Merge pull request #491 from zakkak/master
Fix replying and forwarding of messages
This commit is contained in:
@ -415,8 +415,14 @@ cmd_add (ServerContext *ctx, GHashTable *args, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct _PartInfo {
|
||||||
|
GSList *attlist;
|
||||||
|
MuMsgOptions opts;
|
||||||
|
};
|
||||||
|
typedef struct _PartInfo PartInfo;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_part (MuMsg *msg, MuMsgPart *part, GSList **attlist)
|
each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo)
|
||||||
{
|
{
|
||||||
char *att, *cachefile;
|
char *att, *cachefile;
|
||||||
GError *err;
|
GError *err;
|
||||||
@ -427,7 +433,8 @@ each_part (MuMsg *msg, MuMsgPart *part, GSList **attlist)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
err = NULL;
|
err = NULL;
|
||||||
cachefile = mu_msg_part_save_temp (msg, MU_MSG_OPTION_OVERWRITE,
|
cachefile = mu_msg_part_save_temp (msg,
|
||||||
|
pinfo->opts|MU_MSG_OPTION_OVERWRITE,
|
||||||
part->index, &err);
|
part->index, &err);
|
||||||
if (!cachefile) {
|
if (!cachefile) {
|
||||||
print_and_clear_g_error (&err);
|
print_and_clear_g_error (&err);
|
||||||
@ -437,7 +444,7 @@ each_part (MuMsg *msg, MuMsgPart *part, GSList **attlist)
|
|||||||
att = g_strdup_printf (
|
att = g_strdup_printf (
|
||||||
"(:file-name \"%s\" :mime-type \"%s/%s\")",
|
"(:file-name \"%s\" :mime-type \"%s/%s\")",
|
||||||
cachefile, part->type, part->subtype);
|
cachefile, part->type, part->subtype);
|
||||||
*attlist = g_slist_append (*attlist, att);
|
pinfo->attlist = g_slist_append (pinfo->attlist, att);
|
||||||
g_free (cachefile);
|
g_free (cachefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,27 +457,44 @@ each_part (MuMsg *msg, MuMsgPart *part, GSList **attlist)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static gchar*
|
static gchar*
|
||||||
include_attachments (MuMsg *msg)
|
include_attachments (MuMsg *msg, MuMsgOptions opts)
|
||||||
{
|
{
|
||||||
GSList *attlist, *cur;
|
GSList *cur;
|
||||||
GString *gstr;
|
GString *gstr;
|
||||||
|
PartInfo pinfo;
|
||||||
|
|
||||||
attlist = NULL;
|
pinfo.attlist = NULL;
|
||||||
mu_msg_part_foreach (msg, MU_MSG_OPTION_NONE,
|
pinfo.opts = opts;
|
||||||
|
mu_msg_part_foreach (msg, opts,
|
||||||
(MuMsgPartForeachFunc)each_part,
|
(MuMsgPartForeachFunc)each_part,
|
||||||
&attlist);
|
&pinfo);
|
||||||
|
|
||||||
gstr = g_string_sized_new (512);
|
gstr = g_string_sized_new (512);
|
||||||
gstr = g_string_append_c (gstr, '(');
|
gstr = g_string_append_c (gstr, '(');
|
||||||
for (cur = attlist; cur; cur = g_slist_next (cur))
|
for (cur = pinfo.attlist; cur; cur = g_slist_next (cur))
|
||||||
g_string_append (gstr, (gchar*)cur->data);
|
g_string_append (gstr, (gchar*)cur->data);
|
||||||
gstr = g_string_append_c (gstr, ')');
|
gstr = g_string_append_c (gstr, ')');
|
||||||
|
|
||||||
mu_str_free_list (attlist);
|
mu_str_free_list (pinfo.attlist);
|
||||||
|
|
||||||
return g_string_free (gstr, FALSE);
|
return g_string_free (gstr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MuMsgOptions
|
||||||
|
get_encrypted_msg_opts (GHashTable *args)
|
||||||
|
{
|
||||||
|
MuMsgOptions opts;
|
||||||
|
|
||||||
|
opts = MU_MSG_OPTION_NONE;
|
||||||
|
|
||||||
|
if (get_bool_from_args (args, "use-agent", FALSE, NULL))
|
||||||
|
opts |= MU_MSG_OPTION_USE_AGENT;
|
||||||
|
if (get_bool_from_args (args, "extract-encrypted", FALSE, NULL))
|
||||||
|
opts |= MU_MSG_OPTION_DECRYPT;
|
||||||
|
|
||||||
|
return opts;
|
||||||
|
}
|
||||||
|
|
||||||
enum { NEW, REPLY, FORWARD, EDIT, INVALID_TYPE };
|
enum { NEW, REPLY, FORWARD, EDIT, INVALID_TYPE };
|
||||||
static unsigned
|
static unsigned
|
||||||
compose_type (const char *typestr)
|
compose_type (const char *typestr)
|
||||||
@ -505,6 +529,9 @@ cmd_compose (ServerContext *ctx, GHashTable *args, GError **err)
|
|||||||
const gchar *typestr;
|
const gchar *typestr;
|
||||||
char *sexp, *atts;
|
char *sexp, *atts;
|
||||||
unsigned ctype;
|
unsigned ctype;
|
||||||
|
MuMsgOptions opts;
|
||||||
|
|
||||||
|
opts = get_encrypted_msg_opts (args);
|
||||||
|
|
||||||
GET_STRING_OR_ERROR_RETURN (args, "type", &typestr, err);
|
GET_STRING_OR_ERROR_RETURN (args, "type", &typestr, err);
|
||||||
|
|
||||||
@ -523,9 +550,8 @@ cmd_compose (ServerContext *ctx, GHashTable *args, GError **err)
|
|||||||
print_and_clear_g_error (err);
|
print_and_clear_g_error (err);
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
}
|
}
|
||||||
sexp = mu_msg_to_sexp (msg, atoi(docidstr), NULL,
|
sexp = mu_msg_to_sexp (msg, atoi(docidstr), NULL, opts);
|
||||||
MU_MSG_OPTION_NONE);
|
atts = (ctype == FORWARD) ? include_attachments (msg, opts) : NULL;
|
||||||
atts = (ctype == FORWARD) ? include_attachments (msg) : NULL;
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
} else
|
} else
|
||||||
atts = sexp = NULL;
|
atts = sexp = NULL;
|
||||||
@ -776,22 +802,6 @@ temp_part (MuMsg *msg, unsigned docid, unsigned index,
|
|||||||
return MU_OK;
|
return MU_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static MuMsgOptions
|
|
||||||
get_extract_msg_opts (GHashTable *args)
|
|
||||||
{
|
|
||||||
MuMsgOptions opts;
|
|
||||||
|
|
||||||
opts = MU_MSG_OPTION_NONE;
|
|
||||||
|
|
||||||
if (get_bool_from_args (args, "use-agent", FALSE, NULL))
|
|
||||||
opts |= MU_MSG_OPTION_USE_AGENT;
|
|
||||||
if (get_bool_from_args (args, "extract-encrypted", FALSE, NULL))
|
|
||||||
opts |= MU_MSG_OPTION_DECRYPT;
|
|
||||||
|
|
||||||
return opts;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { SAVE, OPEN, TEMP, INVALID_ACTION };
|
enum { SAVE, OPEN, TEMP, INVALID_ACTION };
|
||||||
static int
|
static int
|
||||||
action_type (const char *actionstr)
|
action_type (const char *actionstr)
|
||||||
@ -816,7 +826,7 @@ cmd_extract (ServerContext *ctx, GHashTable *args, GError **err)
|
|||||||
MuMsgOptions opts;
|
MuMsgOptions opts;
|
||||||
const char* actionstr, *indexstr;
|
const char* actionstr, *indexstr;
|
||||||
|
|
||||||
opts = get_extract_msg_opts (args);
|
opts = get_encrypted_msg_opts (args);
|
||||||
rv = MU_ERROR;
|
rv = MU_ERROR;
|
||||||
|
|
||||||
/* read parameters */
|
/* read parameters */
|
||||||
|
|||||||
@ -381,7 +381,7 @@ tempfile)."
|
|||||||
(mu4e~compose-hide-headers)
|
(mu4e~compose-hide-headers)
|
||||||
;; switch on the mode
|
;; switch on the mode
|
||||||
(mu4e-compose-mode))
|
(mu4e-compose-mode))
|
||||||
|
|
||||||
(defun mu4e-sent-handler (docid path)
|
(defun mu4e-sent-handler (docid path)
|
||||||
"Handler function, called with DOCID and PATH for the just-sent
|
"Handler function, called with DOCID and PATH for the just-sent
|
||||||
message. For Forwarded ('Passed') and Replied messages, try to set
|
message. For Forwarded ('Passed') and Replied messages, try to set
|
||||||
@ -466,7 +466,13 @@ for draft messages."
|
|||||||
(if (eq compose-type 'new)
|
(if (eq compose-type 'new)
|
||||||
(mu4e~compose-handler 'new)
|
(mu4e~compose-handler 'new)
|
||||||
;; otherwise, we need the doc-id
|
;; otherwise, we need the doc-id
|
||||||
(let ((docid (mu4e-message-field msg :docid)))
|
(let* ((docid (mu4e-message-field msg :docid))
|
||||||
|
;; decrypt (or not), based on `mu4e-decryption-policy'.
|
||||||
|
(decrypt
|
||||||
|
(and (member 'encrypted (mu4e-message-field msg :flags))
|
||||||
|
(if (eq mu4e-decryption-policy 'ask)
|
||||||
|
(yes-or-no-p (mu4e-format "Decrypt message?"))
|
||||||
|
mu4e-decryption-policy))))
|
||||||
;; if there's a visible view window, select that before starting composing
|
;; if there's a visible view window, select that before starting composing
|
||||||
;; a new message, so that one will be replaced by the compose window. The
|
;; a new message, so that one will be replaced by the compose window. The
|
||||||
;; 10-or-so line headers buffer is not a good place to write it...
|
;; 10-or-so line headers buffer is not a good place to write it...
|
||||||
@ -474,7 +480,7 @@ for draft messages."
|
|||||||
(when (window-live-p viewwin)
|
(when (window-live-p viewwin)
|
||||||
(select-window viewwin)))
|
(select-window viewwin)))
|
||||||
;; talk to the backend
|
;; talk to the backend
|
||||||
(mu4e~proc-compose compose-type docid)))))
|
(mu4e~proc-compose compose-type decrypt docid)))))
|
||||||
|
|
||||||
(defun mu4e-compose-reply ()
|
(defun mu4e-compose-reply ()
|
||||||
"Compose a reply for the message at point in the headers buffer."
|
"Compose a reply for the message at point in the headers buffer."
|
||||||
|
|||||||
@ -433,7 +433,7 @@ e.g. '/drafts'.
|
|||||||
(mu4e~proc-escape path) (mu4e~proc-escape maildir)))
|
(mu4e~proc-escape path) (mu4e~proc-escape maildir)))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e~proc-compose (type &optional docid)
|
(defun mu4e~proc-compose (type decrypt &optional docid)
|
||||||
"Start composing a message of certain TYPE (a symbol, either
|
"Start composing a message of certain TYPE (a symbol, either
|
||||||
`forward', `reply', `edit' or `new', based on an original
|
`forward', `reply', `edit' or `new', based on an original
|
||||||
message (ie, replying to, forwarding, editing) with DOCID or nil
|
message (ie, replying to, forwarding, editing) with DOCID or nil
|
||||||
@ -445,8 +445,9 @@ The result will be delivered to the function registered as
|
|||||||
(mu4e-error "Unsupported compose-type %S" type))
|
(mu4e-error "Unsupported compose-type %S" type))
|
||||||
(unless (eq (null docid) (eq type 'new))
|
(unless (eq (null docid) (eq type 'new))
|
||||||
(mu4e-error "`new' implies docid not-nil, and vice-versa"))
|
(mu4e-error "`new' implies docid not-nil, and vice-versa"))
|
||||||
(mu4e~proc-send-command "cmd:compose type:%s docid:%d"
|
(mu4e~proc-send-command
|
||||||
(symbol-name type) docid))
|
"cmd:compose type:%s docid:%d extract-encrypted:%s use-agent:true"
|
||||||
|
(symbol-name type) docid (if decrypt "true" "false")))
|
||||||
|
|
||||||
(defun mu4e~proc-mkdir (path)
|
(defun mu4e~proc-mkdir (path)
|
||||||
"Create a new maildir-directory at filesystem PATH."
|
"Create a new maildir-directory at filesystem PATH."
|
||||||
|
|||||||
Reference in New Issue
Block a user