Example for doveadm-save using Doveadm HTTP API
I could use an example of how to use curl to save a new message to a user’s INBOX using the Doveadm HTTP API.
https://wiki2.dovecot.org/Design/DoveadmProtocol/HTTP https://wiki2.dovecot.org/Design/DoveadmProtocol/HTTP
Do I really use the -d option and inline the entire new message in the command-line? Or, should I create a temporary .json file with the message wrapped in JSON and pass this filename to the -d option?
Does anyone have a PHP class that abstracts the HTTP API commands?
I’ve been using the Roundcube Framework to deliver new messages by IMAP, but I’m experimenting whether the Doveadm HTTP API might be a better solution. I eventually want my PHP code to do full administration of my users mailboxes. I was planning on using Sieve pipe PHP scripts in conjunction with IMAP to do full admin on mailboxes (as they receive new messages or change a flag, I would trigger maintenance on the mailbox such as deleting or moving to the trash old messages or filing a copy of a new message in a folder).
Finally, is the Doveadm HTTP API stable enough to use in production? It seems like the documentation is rather minimal. Can this interface really be used for new message delivery instead of LMTP in production? Or, is this a bad idea to combine mailbox administration with new message delivery?
Does anyone here use the Doveadm HTTP API in production?
Kevin
On 10 May 2017, at 14.57, KT Walrus kevin@my.walr.us wrote:
I could use an example of how to use curl to save a new message to a user’s INBOX using the Doveadm HTTP API.
Here you go:
doveadm mailbox save
parameters:
{ "command": "save", "parameters": [ { "name": "allUsers", "type": "boolean" }, { "name": "socketPath", "type": "string" }, { "name": "user", "type": "string" }, { "name": "userFile", "type": "string" }, { "name": "mailbox", "type": "string" }, { "name": "file", "type": "string" } ] }
example:
[ [ "save", { "file": "From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n", "mailbox": "INBOX/myfoldertoo", "user": "samik" }, "bb" ] ]
# curl -v -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["save",{"user":"samik","mailbox":"INBOX/myfoldertoo","file":"From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n"},"bb"]]' http://localhost:8080/doveadm/v1
Does anyone here use the Doveadm HTTP API in production?
I know many.
Sami
On May 10, 2017, at 11:06 AM, Sami Ketola sami.ketola@dovecot.fi wrote:
On 10 May 2017, at 14.57, KT Walrus kevin@my.walr.us wrote:
I could use an example of how to use curl to save a new message to a user’s INBOX using the Doveadm HTTP API.
Here you go:
doveadm mailbox save
parameters:
{ "command": "save", "parameters": [ { "name": "allUsers", "type": "boolean" }, { "name": "socketPath", "type": "string" }, { "name": "user", "type": "string" }, { "name": "userFile", "type": "string" }, { "name": "mailbox", "type": "string" }, { "name": "file", "type": "string" } ] }
example:
[ [ "save", { "file": "From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n", "mailbox": "INBOX/myfoldertoo", "user": "samik" }, "bb" ] ]
# curl -v -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["save",{"user":"samik","mailbox":"INBOX/myfoldertoo","file":"From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n"},"bb"]]' http://localhost:8080/doveadm/v1
Thanks. I worry that by inlining the entire message in the curl command, the message might exceed some limits on how long a command can be. Some of my messages are up to 20MBs with the attachments and 1MB messages are very common. I also worry about the raw message having unescaped quotes in the message messing up to actual storage of the message in the INBOX. Are HTML mail messages encoded to be safe to enclose in quotations? Or, should I encode the entire mail message and trust that Dovecot can handle decoding the message in the back end?
I figure that it would be better to put the message in a file and include it some way as part of the HTTP request data. But, does the doveadm HTTP server handle 20MB requests in a single HTTP request? Probably, it does, but I know I had to configure MySQL to take large SQL queries and they really recommend that large files be broken up into chunks and stored with multiple queries (especially for replication).
I’ll probably implement message delivery in PHP using a class that can safely post a large file in an HTTP request, so I won’t really be using curl directly at a bash command line.
Do you know of any PHP class for the Doveadm HTTP API that I might use?
Kevin
On 10 May 2017, at 16.26, KT Walrus kevin@my.walr.us wrote:
# curl -v -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["save",{"user":"samik","mailbox":"INBOX/myfoldertoo","file":"From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n"},"bb"]]' http://localhost:8080/doveadm/v1
Thanks. I worry that by inlining the entire message in the curl command, the message might exceed some limits on how long a command can be. Some of my messages are up to 20MBs with the attachments and 1MB messages are very common. I also worry about the raw message having unescaped quotes in the message messing up to actual storage of the message in the INBOX. Are HTML mail messages encoded to be safe to enclose in quotations? Or, should I encode the entire mail message and trust that Dovecot can handle decoding the message in the back end?
The question is: why do you want to deliver 20MB messages with doveadm http api? I would not replace LMTP with that.
Sami
On May 10, 2017, at 5:16 PM, Sami Ketola sami.ketola@dovecot.fi wrote:
On 10 May 2017, at 16.26, KT Walrus kevin@my.walr.us wrote:
# curl -v -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["save",{"user":"samik","mailbox":"INBOX/myfoldertoo","file":"From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n"},"bb"]]' http://localhost:8080/doveadm/v1
Thanks. I worry that by inlining the entire message in the curl command, the message might exceed some limits on how long a command can be. Some of my messages are up to 20MBs with the attachments and 1MB messages are very common. I also worry about the raw message having unescaped quotes in the message messing up to actual storage of the message in the INBOX. Are HTML mail messages encoded to be safe to enclose in quotations? Or, should I encode the entire mail message and trust that Dovecot can handle decoding the message in the back end?
The question is: why do you want to deliver 20MB messages with doveadm http api? I would not replace LMTP with that.
I could certainly end up using SMTP/LMTP, but in my case I need complete control over when, where, and how messages are delivered. The IMAP interface gives me that control, but the Doveadm HTTP API seems easier and I can do operations that span all users with this API. So, I don’t need to worry as much about scaling (since I think IMAP is limited to one user at a time per connection).
If the Doveadm HTTP API isn’t mature enough or have a PHP interface (like Roundcube gives me for IMAP), I may have to just go with IMAP or SMTP. SMTP is a whole lot easier from PHP of my 3 options, but only handles new message delivery and not the other admin actions I need to do. Eventually, I want to hire some programmers to code my admin app in Go and move to a micro-services architecture, but to start out, when scaling isn’t that important, I’m coding the mail admin app in PHP (since Roundcube Framework gives me a lot of mail handling classes that are mature and well tested).
Kevin
On 11.05.2017 00:36, KT Walrus wrote:
On May 10, 2017, at 5:16 PM, Sami Ketola sami.ketola@dovecot.fi wrote:
On 10 May 2017, at 16.26, KT Walrus kevin@my.walr.us wrote:
# curl -v -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["save",{"user":"samik","mailbox":"INBOX/myfoldertoo","file":"From: Joulu Pukki joulu.pukki@korvatunturi.fi\nSubject: plaa\n\nmail body\n"},"bb"]]' http://localhost:8080/doveadm/v1 Thanks. I worry that by inlining the entire message in the curl command, the message might exceed some limits on how long a command can be. Some of my messages are up to 20MBs with the attachments and 1MB messages are very common. I also worry about the raw message having unescaped quotes in the message messing up to actual storage of the message in the INBOX. Are HTML mail messages encoded to be safe to enclose in quotations? Or, should I encode the entire mail message and trust that Dovecot can handle decoding the message in the back end?
The question is: why do you want to deliver 20MB messages with doveadm http api? I would not replace LMTP with that. I could certainly end up using SMTP/LMTP, but in my case I need complete control over when, where, and how messages are delivered. The IMAP interface gives me that control, but the Doveadm HTTP API seems easier and I can do operations that span all users with this API. So, I don’t need to worry as much about scaling (since I think IMAP is limited to one user at a time per connection).
If the Doveadm HTTP API isn’t mature enough or have a PHP interface (like Roundcube gives me for IMAP), I may have to just go with IMAP or SMTP. SMTP is a whole lot easier from PHP of my 3 options, but only handles new message delivery and not the other admin actions I need to do. Eventually, I want to hire some programmers to code my admin app in Go and move to a micro-services architecture, but to start out, when scaling isn’t that important, I’m coding the mail admin app in PHP (since Roundcube Framework gives me a lot of mail handling classes that are mature and well tested).
Kevin
There is no PHP interface. Roundcube is made with php, so it's not really wonder there is.
The API is mature enough for it's use. doveadm save is not intended for mail delivery function, it's more about dropping administrative or such emails to user's box. It will not behave as delivery, that is, you won't get sieve acting on those. quota is still imposed, though.
There are no size limits in the API, other than imposed by your system. You can dump 20M email if you want, it will happily consume it.
Aki
participants (3)
-
Aki Tuomi
-
KT Walrus
-
Sami Ketola