Jma — 17-Sep-2013/7:40:22-7:00
Hi!
How can I download multipart email messages?
thanks!
Nick — 19-Sep-2013/9:58:31-7:00
Have you looked at the import-email function? You can get the source in the R2 console:
source import-email
There's an example of how to use it (not for multi-part email, but you'll get the idea), at:
http://business-programming.com/business_programming.html#section-17.3
To save an email attachment to a file, you can use the debase function (here the data has be copied to the system clipboard):
write/binary %floorplan8.pdf debase read clipboard://
As an aside, you may be interested in looking at the decode-multipart-form-data function at http://business-programming.com/business_programming.html#section-19.10 to see how Andreas Bolka created a form-multipart function, or any of Graham's protocols that deal with RFC specifications, to see how anything that's not built in, can be created from scratch.
Jma — 21-Sep-2013/7:06:27-7:00
Before I can use the following:
write/binary %floorplan8.pdf debase read clipboard://
Is the data to be saved to file, returned from the following (from section 17.3) ?
...
; copy/part for URI length, at 3 is a serialization trick:
at (mold compress (copy/part single-message/content 5000)) 3
...
Can you explain what it does ?
Nick — 21-Sep-2013/9:17:38-7:00
The debase example was a quicky that I've used to save binary attachment files copied from on-screen selections made with a mouse, but it works the same way if you parse out that data with code (no need to copy to the clipboard if you do that). This should help to clarify:
R E B O L []
; read mail in a mailbox:
x: read pop://user:pass@site.com
; import 3rd email from the box:
y: import-email x/3
; inspect properties of the email object (parts of the email):
? y
; read /content part of the email object:
editor y/content
; find attachment in content and save to file:
z: find y/content {Content-Disposition: attachment; filename="}
xx: next find z newline
write/binary %temp.pdf debase xx
Nick — 21-Sep-2013/9:20:45-7:00
You can find and parse the different parts of the email according to your own needs. Taking a look at import-email to see how parse was used to break apart the original email, should be helpful.
Jma — 21-Sep-2013/10:57:53-7:00
Thanks for the clarification; that was helpful.//
Nick — 22-Sep-2013/8:56:23-7:00
Be sure to read the section on ports, to see how to access individual emails from an account (without having to download the entire mailbox):
http://business-programming.com/business_programming.html#section-17.2