mirror of
https://github.com/djcb/mu.git
synced 2024-07-01 08:11:06 +02:00
Merge pull request #831 from j-hao/master
Handle attached images when write msg body to html
This commit is contained in:
commit
7585506e37
|
@ -322,6 +322,15 @@ mu_msg_part_get_filename (MuMsgPart *mpart, gboolean construct_if_needed)
|
||||||
mpart->index, construct_if_needed);
|
mpart->index, construct_if_needed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gchar*
|
||||||
|
mu_msg_part_get_content_id (MuMsgPart *mpart)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (mpart, NULL);
|
||||||
|
g_return_val_if_fail (GMIME_IS_OBJECT(mpart->data), NULL);
|
||||||
|
return g_mime_object_get_content_id((GMimeObject*)mpart->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static MuMsgPartType
|
static MuMsgPartType
|
||||||
get_disposition (GMimeObject *mobj)
|
get_disposition (GMimeObject *mobj)
|
||||||
|
|
|
@ -114,6 +114,17 @@ char *mu_msg_part_get_filename (MuMsgPart *mpart, gboolean construct_if_needed)
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get appropriate content id for the mime-part
|
||||||
|
*
|
||||||
|
* @param mpart a MuMsgPart
|
||||||
|
*
|
||||||
|
* @return const content id
|
||||||
|
*/
|
||||||
|
const gchar*
|
||||||
|
mu_msg_part_get_content_id (MuMsgPart *mpart)
|
||||||
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the text in the MuMsgPart (ie. in its GMimePart)
|
* get the text in the MuMsgPart (ie. in its GMimePart)
|
||||||
*
|
*
|
||||||
|
|
|
@ -354,16 +354,17 @@ static void
|
||||||
each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||||
{
|
{
|
||||||
char *name, *tmp, *parttype;
|
char *name, *tmp, *parttype;
|
||||||
char *tmpfile;
|
char *tmpfile, *cid;
|
||||||
|
|
||||||
name = mu_msg_part_get_filename (part, TRUE);
|
name = mu_msg_part_get_filename (part, TRUE);
|
||||||
tmpfile = get_temp_file_maybe (msg, part, pinfo->opts);
|
tmpfile = get_temp_file_maybe (msg, part, pinfo->opts);
|
||||||
parttype = get_part_type_string (part->part_type);
|
parttype = get_part_type_string (part->part_type);
|
||||||
|
cid = mu_str_escape_c_literal(mu_msg_part_get_content_id(part), TRUE);
|
||||||
|
|
||||||
tmp = g_strdup_printf
|
tmp = g_strdup_printf
|
||||||
("%s(:index %d :name \"%s\" :mime-type \"%s/%s\"%s%s "
|
("%s(:index %d :name \"%s\" :mime-type \"%s/%s\"%s%s "
|
||||||
":type %s "
|
":type %s "
|
||||||
":attachment %s :size %i %s %s)",
|
":attachment %s %s%s :size %i %s %s)",
|
||||||
pinfo->parts ? pinfo->parts: "",
|
pinfo->parts ? pinfo->parts: "",
|
||||||
part->index,
|
part->index,
|
||||||
name ? mu_str_escape_c_literal(name, FALSE) : "noname",
|
name ? mu_str_escape_c_literal(name, FALSE) : "noname",
|
||||||
|
@ -372,6 +373,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||||
tmpfile ? " :temp" : "", tmpfile ? tmpfile : "",
|
tmpfile ? " :temp" : "", tmpfile ? tmpfile : "",
|
||||||
parttype,
|
parttype,
|
||||||
mu_msg_part_maybe_attachment (part) ? "t" : "nil",
|
mu_msg_part_maybe_attachment (part) ? "t" : "nil",
|
||||||
|
cid ? " :cid" : "", cid ? cid : "",
|
||||||
(int)part->size,
|
(int)part->size,
|
||||||
sig_verdict (part),
|
sig_verdict (part),
|
||||||
dec_verdict (part));
|
dec_verdict (part));
|
||||||
|
@ -379,6 +381,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||||
g_free (name);
|
g_free (name);
|
||||||
g_free (tmpfile);
|
g_free (tmpfile);
|
||||||
g_free (parttype);
|
g_free (parttype);
|
||||||
|
g_free (cid);
|
||||||
|
|
||||||
g_free (pinfo->parts);
|
g_free (pinfo->parts);
|
||||||
pinfo->parts = tmp;
|
pinfo->parts = tmp;
|
||||||
|
|
|
@ -74,14 +74,29 @@ Works for the message view."
|
||||||
"Write the body (either html or text) to a temporary file;
|
"Write the body (either html or text) to a temporary file;
|
||||||
return the filename."
|
return the filename."
|
||||||
(let* ((html (mu4e-message-field msg :body-html))
|
(let* ((html (mu4e-message-field msg :body-html))
|
||||||
(txt (mu4e-message-field msg :body-txt))
|
(txt (mu4e-message-field msg :body-txt))
|
||||||
(tmpfile (mu4e-make-temp-file "html")))
|
(tmpfile (mu4e-make-temp-file "html"))
|
||||||
|
(attachments (remove-if (lambda (part)
|
||||||
|
(or (null (plist-get part :attachment))
|
||||||
|
(null (plist-get part :cid))))
|
||||||
|
(mu4e-message-field msg :parts))))
|
||||||
(unless (or html txt)
|
(unless (or html txt)
|
||||||
(mu4e-error "No body part for this message"))
|
(mu4e-error "No body part for this message"))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert "<head><meta charset=\"UTF-8\"></head>\n")
|
(insert "<head><meta charset=\"UTF-8\"></head>\n")
|
||||||
(insert (or html (concat "<pre>" txt "</pre>")))
|
(insert (or html (concat "<pre>" txt "</pre>")))
|
||||||
(write-file tmpfile)
|
(write-file tmpfile)
|
||||||
|
;; rewrite attachment urls
|
||||||
|
(mapc (lambda (attachment)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward (format "src=\"cid:%s\"" (plist-get attachment :cid)) nil t)
|
||||||
|
(if (plist-get attachment :temp)
|
||||||
|
(replace-match (format "src=\"%s\"" (plist-get attachment :temp)))
|
||||||
|
(replace-match (format "src=\"%s%s\"" temporary-file-directory (plist-get attachment :name)))
|
||||||
|
(mu4e~proc-extract 'save (mu4e-message-field :docid) (plist-get attachment :index) mu4e-decryption-policy temporary-file-directory)
|
||||||
|
(mu4e-remove-file-later (format "%s%s" temporary-file-directory (plist-get attachment :name))))))
|
||||||
|
attachments)
|
||||||
|
(save-buffer)
|
||||||
tmpfile)))
|
tmpfile)))
|
||||||
|
|
||||||
(defun mu4e-action-view-in-browser (msg)
|
(defun mu4e-action-view-in-browser (msg)
|
||||||
|
|
|
@ -139,6 +139,12 @@ return the result."
|
||||||
(mu4e~get-folder 'mu4e-trash-folder msg))
|
(mu4e~get-folder 'mu4e-trash-folder msg))
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
(defun mu4e-remove-file-later (filename)
|
||||||
|
"Remove FILENAME in a few seconds."
|
||||||
|
(run-at-time "10 sec" nil
|
||||||
|
(lambda () (ignore-errors (delete-file filename)))))
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(defun mu4e-make-temp-file (ext)
|
(defun mu4e-make-temp-file (ext)
|
||||||
|
@ -146,8 +152,7 @@ return the result."
|
||||||
self-destruct in a few seconds, enough to open it in another
|
self-destruct in a few seconds, enough to open it in another
|
||||||
program."
|
program."
|
||||||
(let ((tmpfile (make-temp-file "mu4e-" nil (concat "." ext))))
|
(let ((tmpfile (make-temp-file "mu4e-" nil (concat "." ext))))
|
||||||
(run-at-time "10 sec" nil
|
(mu4e-remove-file-later tmpfile)
|
||||||
(lambda (fname) (ignore-errors (delete-file fname))) tmpfile)
|
|
||||||
tmpfile))
|
tmpfile))
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user