| Paste number 71961: | CL-MIME basic usage |
| Pasted by: | fusss |
| When: | 6 months, 3 weeks ago |
| Share: | Tweet this! | http://paste.lisp.org/+1JIX |
| Channel: | None |
| Paste contents: |
small example to parse Thunderbird messages in mbox format:
(defun thunderbird-mbox-msg-to-text (email)
(with-open-file (msg email :direction :input)
(with-open-file (out (concatenate 'string (pathname-name x) ".txt") :direction :output :if-exists :supersede)
(let ((mime (parse-mime msg)))
(case (type-of mime)
(text-mime (print (content mime) out))
(multipart-mime
(dolist (part (content mime))
(if (and (string-equal (content-type part) "text")
(string-equal (content-subtype part) "plain"))
(print-mime out part nil nil))))
(mime (print "mime")) ;?
(t (print "other"))))))) ;?
The MIME class is the mixin which TEXT-MIME and MULTIPART-MIME inherit from. Most plain text messages will be of type TEXT-MIME and you can read the body with the CONTENT function. MULTIPART-MIME messages have multiple parts, you will have to iterate over them inspecting the type and subtype of each and choose what to do with them. In the example above, I was extracting the plain text version of html emails. See the wikipedia page on MIME and help yourself.
This paste has no annotations.