]> granicus.if.org Git - neomutt/commitdiff
Add compose-to-sender functionality.
authorKevin McCarthy <kevin@8t8.us>
Wed, 22 Aug 2018 22:07:45 +0000 (15:07 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Sep 2018 17:58:48 +0000 (18:58 +0100)
This patch is loosely based on the NeoMutt feature, but adds in
support for the attach menu, reuses functionality in send.c, and has
proper mode checks.

Thanks to Enno for the opening the ticket requesting the port.

curs_main.c
functions.h
opcodes.h
pager.c
recvattach.c
recvcmd.c
recvcmd.h
send.c
send.h

index 39e4af24a405866fb7f00aaf8be6136131d25fd5..f531463b08750e9b73dcf7bc08a9d1c449c51271 100644 (file)
@@ -1764,11 +1764,11 @@ int mutt_index_menu(void)
         break;
 
       case OP_COMPOSE_TO_SENDER:
-        if (Context)
-        {
-          mutt_compose_to_sender(tag ? NULL : CURHDR);
-          menu->redraw = REDRAW_FULL;
-        }
+        CHECK_ATTACH;
+        CHECK_MSGCOUNT;
+        CHECK_VISIBLE;
+        ci_send_message (SEND_TO_SENDER, NULL, NULL, Context, tag ? NULL : CURHDR);
+        menu->redraw = REDRAW_FULL;
         break;
 
         /* --------------------------------------------------------------------
index 78e4eb52e4c187cb8f80ebd5d456b05d9ca8213e..dcdcea96a666d135c572bb98ef8a9fc54c5274b4 100644 (file)
@@ -394,6 +394,7 @@ const struct Binding OpAttach[] = { /* map: attachment */
   { "bounce-message",        OP_BOUNCE_MESSAGE,              "b" },
   { "check-traditional-pgp", OP_CHECK_TRADITIONAL,           "\033P" },
   { "collapse-parts",        OP_ATTACH_COLLAPSE,             "v" },
+  { "compose-to-sender",     OP_COMPOSE_TO_SENDER,           NULL },
   { "delete-entry",          OP_DELETE,                      "d" },
   { "display-toggle-weed",   OP_DISPLAY_HEADERS,             "h" },
   { "edit-type",             OP_EDIT_TYPE,                   "\005" },
index 1b64eb8ee1cf7676630e161f770380ed7b839669..3ad260f308a3252438d9c8cb25910a53a6fb9979 100644 (file)
--- a/opcodes.h
+++ b/opcodes.h
@@ -76,7 +76,7 @@
   _fmt(OP_COMPOSE_TOGGLE_DISPOSITION,     N_("toggle disposition between inline/attachment")) \
   _fmt(OP_COMPOSE_TOGGLE_RECODE,          N_("toggle recoding of this attachment")) \
   _fmt(OP_COMPOSE_TOGGLE_UNLINK,          N_("toggle whether to delete file after sending it")) \
-  _fmt(OP_COMPOSE_TO_SENDER,              N_("compose a new message to the sender")) \
+  _fmt(OP_COMPOSE_TO_SENDER,              N_("compose new message to the current message sender")) \
   _fmt(OP_COMPOSE_UPDATE_ENCODING,        N_("update an attachment's encoding info")) \
   _fmt(OP_COMPOSE_WRITE_MESSAGE,          N_("write the message to a folder")) \
   _fmt(OP_COPY_MESSAGE,                   N_("copy a message to a file/mailbox")) \
diff --git a/pager.c b/pager.c
index bf8e707b1f19943f4da5412ef00ffbc3b8247b0d..5a85e5cbffa2c91d202c76c240181618ab6932a7 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2899,7 +2899,12 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
         break;
 
       case OP_COMPOSE_TO_SENDER:
-        mutt_compose_to_sender(extra->hdr);
+        CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
+        CHECK_ATTACH;
+        if (IsMsgAttach (extra))
+          mutt_attach_mail_sender (extra->fp, extra->hdr, extra->actx, extra->bdy);
+        else
+          ci_send_message (SEND_TO_SENDER, NULL, NULL, extra->ctx, extra->hdr);
         pager_menu->redraw = REDRAW_FULL;
         break;
 
index c4bfc613151802062aa1219245ef7eb1fd5e9375..2d0b094fcd1c001180771ac99d02da2adf6c68f9 100644 (file)
@@ -1568,6 +1568,13 @@ void mutt_view_attachments(struct Header *hdr)
         menu->redraw = REDRAW_FULL;
         break;
 
+      case OP_COMPOSE_TO_SENDER:
+        CHECK_ATTACH;
+        mutt_attach_mail_sender (CURATTACH->fp, hdr, actx,
+                                 menu->tagprefix ? NULL : CURATTACH->content);
+        menu->redraw = REDRAW_FULL;
+        break;
+
       case OP_EDIT_TYPE:
         recvattach_edit_content_type(actx, menu, hdr);
         menu->redraw |= REDRAW_INDEX;
index e087e806f0cdbc6c55b7cd85fe585bc65dc3834d..568d4bfe20af6be6643f24f2d4bd2940f5189831 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -1035,3 +1035,32 @@ void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx,
     mutt_set_flag(Context, hdr, MUTT_REPLIED, 1);
   }
 }
+
+void mutt_attach_mail_sender(FILE *fp, struct Header *hdr,
+                             struct AttachCtx *actx, struct Body *cur)
+{
+  if (!check_all_msg(actx, cur, 0))
+  {
+    mutt_error(_("You may only compose to sender with message/rfc822 parts."));
+    return;
+  }
+
+  struct Header *tmphdr = mutt_header_new();
+  tmphdr->env = mutt_env_new();
+
+  if (cur)
+  {
+    if (mutt_fetch_recips(tmphdr->env, cur->hdr->env, SEND_TO_SENDER) == -1)
+      return;
+  }
+  else
+  {
+    for (int i = 0; i < actx->idxlen; i++)
+    {
+      if (actx->idx[i]->content->tagged &&
+          mutt_fetch_recips(tmphdr->env, actx->idx[i]->content->hdr->env, SEND_TO_SENDER) == -1)
+        return;
+    }
+  }
+  ci_send_message(0, tmphdr, NULL, NULL, NULL);
+}
index f3d714f1c37a9935ae31d88c9949eb27ae921e51..b6a703a06c509bea87072ec71a8b96fdd5b98a54 100644 (file)
--- a/recvcmd.h
+++ b/recvcmd.h
@@ -36,5 +36,6 @@ void mutt_attach_bounce(FILE *fp, struct AttachCtx *actx, struct Body *cur);
 void mutt_attach_resend(FILE *fp, struct AttachCtx *actx, struct Body *cur);
 void mutt_attach_forward(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur, int flags);
 void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur, int flags);
+void mutt_attach_mail_sender(FILE *fp, struct Header *hdr, struct AttachCtx *actx, struct Body *cur);
 
 #endif /* _MUTT_RECVCMD_H */
diff --git a/send.c b/send.c
index 3486e180b18bd784221e9b7e9821150b8d2275c4..e69efb6ad70cfbfa08bba45dc4c0f6f53edba214 100644 (file)
--- a/send.c
+++ b/send.c
@@ -760,6 +760,10 @@ int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, int flags)
       return -1; /* abort */
     }
   }
+  else if (flags & SEND_TO_SENDER)
+  {
+    mutt_addr_append(&out->to, in->from, 0);
+  }
   else
   {
     if (default_to(&out->to, in, flags & SEND_GROUP_REPLY, hmfupto) == MUTT_ABORT)
@@ -965,7 +969,7 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx,
   if (!curenv)
     return -1;
 
-  if (flags & SEND_REPLY)
+  if (flags & (SEND_REPLY|SEND_TO_SENDER))
   {
 #ifdef USE_NNTP
     if ((flags & SEND_NEWS))
@@ -999,8 +1003,11 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx,
       return -1;
     }
 
-    mutt_make_misc_reply_headers(env, curenv);
-    make_reference_headers(tag ? NULL : curenv, env, ctx);
+    if (flags & SEND_REPLY)
+    {
+      mutt_make_misc_reply_headers(env, curenv);
+      make_reference_headers (tag ? NULL : curenv, env, ctx);
+    }
   }
   else if (flags & SEND_FORWARD)
   {
@@ -1401,32 +1408,6 @@ static void fix_end_of_file(const char *data)
   mutt_file_fclose(&fp);
 }
 
-/**
- * mutt_compose_to_sender - Compose an email to the sender
- * @param hdr Header of original email
- * @retval  0 Message was successfully sent
- * @retval -1 Message was aborted or an error occurred
- * @retval  1 Message was postponed
- */
-int mutt_compose_to_sender(struct Header *hdr)
-{
-  struct Header *msg = mutt_header_new();
-
-  msg->env = mutt_env_new();
-  if (!hdr)
-  {
-    for (int i = 0; i < Context->msgcount; i++)
-    {
-      if (message_is_tagged(Context, i))
-        mutt_addr_append(&msg->env->to, Context->hdrs[i]->env->from, false);
-    }
-  }
-  else
-    msg->env->to = mutt_addr_copy_list(hdr->env->from, false);
-
-  return ci_send_message(0, msg, NULL, NULL, NULL);
-}
-
 /**
  * mutt_resend_message - Resend an email
  * @param fp  File containing email
@@ -1729,7 +1710,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile,
 
   if (!(flags & (SEND_POSTPONED | SEND_RESEND)) && !((flags & SEND_DRAFT_FILE) && ResumeDraftFiles))
   {
-    if ((flags & (SEND_REPLY | SEND_FORWARD)) && ctx &&
+    if ((flags & (SEND_REPLY | SEND_FORWARD | SEND_TO_SENDER)) && ctx &&
         envelope_defaults(msg->env, ctx, cur, flags) == -1)
     {
       goto cleanup;
diff --git a/send.h b/send.h
index 480dc1d3ecb6bd1181d01f8db67253de9610a350..a1d1231d3714fc5cb1ac9e51aa4752889b79a7de 100644 (file)
--- a/send.h
+++ b/send.h
@@ -91,11 +91,11 @@ extern bool          UseFrom;
 #define SEND_POSTPONED_FCC  (1 << 9)  /**< used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present */
 #define SEND_NO_FREE_HEADER (1 << 10) /**< Used by the -E flag */
 #define SEND_DRAFT_FILE     (1 << 11) /**< Used by the -H flag */
-#define SEND_NEWS           (1 << 12)
+#define SEND_TO_SENDER      (1 << 12)
+#define SEND_NEWS           (1 << 13)
 
 int             ci_send_message(int flags, struct Header *msg, char *tempfile, struct Context *ctx, struct Header *cur);
 void            mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv);
-int             mutt_compose_to_sender(struct Header *hdr);
 struct Address *mutt_default_from(void);
 void            mutt_encode_descriptions(struct Body *b, bool recurse);
 int             mutt_fetch_recips(struct Envelope *out, struct Envelope *in, int flags);