Skip to content

Commit

Permalink
Add mapping of X-Attachment-Ids used for inline content
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 committed Sep 15, 2010
1 parent 0db033e commit e375931
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/couchmail.clj
Expand Up @@ -47,13 +47,19 @@
[(:fileName part) {:content_type (:contentType part)
:data (String. (Base64/encodeBase64 (io/to-byte-array (:inputStream part))))}])

(defn attach-id-mapping [part]
(let [headers (headers-map (:allHeaders part))]
(if (headers "X-Attachment-Id")
{(headers "X-Attachment-Id") (:fileName part)})))

(defn simplify-message [msg]
(let [bmsg (bean msg)
content (if (multipart? bmsg) (parts (:content bmsg)) (list bmsg))
mailparts (filter (fn [p] (and (not (attachment? p)) (not (multipart? p)))) content)
subparts (mapcat #(parts (:content %)) (filter multipart? content))
attachments (filter #(attachment? %) content)]
(merge (only '(:subject :messageID) bmsg)
(merge (only '(:subject :messageID) bmsg)
(if (> (count attachments) 0) {:attach_id_map (apply merge (map attach-id-mapping attachments))})
{:headers (headers-map (:allHeaders bmsg))
:_attachments (reduce conj {} (map encode-attachment attachments))
:parts (map simplify-part (concat mailparts subparts))
Expand Down

0 comments on commit e375931

Please sign in to comment.