Skip to content
Browse files

Add mapping of X-Attachment-Ids used for inline content

  • Loading branch information...
1 parent 0db033e commit e375931e22f2b3dada3e78a8b50ac1d34e7005c7 @apage43 committed Sep 15, 2010
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/couchmail.clj
View
8 src/couchmail.clj
@@ -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))

0 comments on commit e375931

Please sign in to comment.
Something went wrong with that request. Please try again.