Submit emails via public REST /deliver API
Background
Mime messages are text, encoded and wrapped up for transmission. JEMH uses this format for audit history and test cases, it should also expose a REST API for external tools to drive JEMH via REST:
MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sun, 19 Jun 2011 17:42:26 +1200
Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: This is a starting email template, update as required
From: "Andy Brook" <andy@localhost>
To: changeme@thiswontwork.com
Content-Type: text/plain; charset=UTF-8
some text
Required Info
In order for JEMH to process a mail, it needs to use a Profile. Until now Profiles are tied to mailboxes, allowing arbitrary external use of those profiles may trigger unexpected scenarios, therefore:
Profiles will need to explicitly opt-in to API use
Lists of profiles via REST will only show those that have opted-in.
All REST API's require an authenticated user
Changes in JEMH 5.0 (Jira 10+)
In JEMH 5.0, JEMH will not process mail directly through the API, but will store this mail in a nominated folder (JIRA_SHARED_HOME/import/mail/nnn) that is configured as a source for a Jira mail handler. This addresses scalability problems, and removes a source of denial of service.
API
URLS must follow this pattern
create POST /urlOfRestResource
read GET /urlOfRestResource[/id]
update PUT /urlOfRestResource/id
delete DELETE /urlOfRestResource/id
URL | Method | Response |
.../rest/jemh/latest/public/profile/list | GET | List of JSON profile objects that identify Profile NAME and ID. Requires authenticated user (base 64 headers?) Request: curl -D- -u admin:admin -X GET http://dev-jira:8080/rest/jemh/latest/public/profile/list Response: HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-AREQUESTID: 717x157x1
X-ASEN: SEN-2050663
Set-Cookie: JSESSIONID=54EBDC61B68527A9C48C9106A76054E0; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3QZ-T2ZD-68A2-PNV6|c01f148e72fd5ea6a08f5a62276e077754c7005a|lin; Path=/
X-ASESSIONID: 1c9uhsa
X-AUSERNAME: admin
Cache-Control: no-cache, no-store, no-transform
X-Content-Type-Options: nosniff
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 24 Sep 2014 10:57:58 GMT
[{"id":1,"name":"Testing","desc":"TEST"}]
|
/rest/jemh/latest/public/mailbox/deliver | POST | Request Using an email like: A CURL command would be of format (NOTE: initially application/x-www-form-urlencoded was supported, since 1.6.15, multipart/form-data is also supported): URLEncoding the content (shown above) eg through services like http://www.url-encode-decode.com/ and replacing .... with the result: RESPONSE format: Example Response:
|
Example script to deliver a mail
The script below will use the first param as the profileID, update the url as applicable, the response will be launched in a browser