<<< Date Index >>>     <<< Thread Index >>>

[FEATURE][PATCH] forward as resend



Hello,

now, while upgrading mutt to the version 1.5.5.1 I recall I wrote a small
patch to version 1.5.4 some time ago and never had it published. I added a
new option regarding attachments forwarding. When turned on, it overrides
'mime_forward' option and makes mutt to forward emails like with 'resend'
but creates brand new envelope and thus makes it comfortable to forward
attachments not including original text message (like done in mime_forward
case) and does not make user to edit headers (resend case does).

Although the patch was written against 1.5.4, it applies to and seems to
work well also with version 1.5.5.1 

bye,
        tomas
-- 
               The more I see, The less I believe...
diff -HurBw mutt-1.5.4/attach.h mutt-1.5.4-forward_as_resend/attach.h
--- mutt-1.5.4/attach.h 2002-12-11 12:19:39.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/attach.h       2003-07-24 13:23:34.000000000 
+0200
@@ -29,6 +29,6 @@
 void mutt_print_attachment_list (FILE *fp, int tag, BODY *top);
 
 void mutt_attach_bounce (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
-void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
+void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *, short);
 void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
 void mutt_attach_reply (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int);
diff -HurBw mutt-1.5.4/curs_main.c mutt-1.5.4-forward_as_resend/curs_main.c
--- mutt-1.5.4/curs_main.c      2003-01-23 23:04:28.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/curs_main.c    2003-07-24 10:58:38.000000000 
+0200
@@ -1774,7 +1774,23 @@
        CHECK_MSGCOUNT;
         CHECK_VISIBLE;
        CHECK_ATTACH;
+
+       if( option(OPTFORWASRSND) )
+       {
+               if (tag)
+               {
+                       for (j = 0; j < Context->vcount; j++)
+                       {
+                               if (Context->hdrs[Context->v2r[j]]->tagged)
+                                       mutt_resend_message (NULL, Context, 
Context->hdrs[Context->v2r[j]], 1);
+                       }
+               }
+               else
+                       mutt_resend_message (NULL, Context, CURHDR, 1);
+       }
+       else
        ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
+
        menu->redraw = REDRAW_FULL;
        break;
 
@@ -1898,11 +1914,11 @@
          for (j = 0; j < Context->vcount; j++)
          {
            if (Context->hdrs[Context->v2r[j]]->tagged)
-             mutt_resend_message (NULL, Context, 
Context->hdrs[Context->v2r[j]]);
+             mutt_resend_message (NULL, Context, 
Context->hdrs[Context->v2r[j]],0);
          }
        }
         else
-         mutt_resend_message (NULL, Context, CURHDR);
+         mutt_resend_message (NULL, Context, CURHDR,0);
       
         menu->redraw = REDRAW_FULL;
         break;
diff -HurBw mutt-1.5.4/init.h mutt-1.5.4-forward_as_resend/init.h
--- mutt-1.5.4/init.h   2003-03-04 10:28:12.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/init.h 2003-07-24 13:40:11.000000000 +0200
@@ -619,6 +619,16 @@
   { "forw_quote",      DT_SYN,  R_NONE, UL "forward_quote", 0 },
   /*
   */
+  { "forward_as_resend",       DT_BOOL,  R_NONE, OPTFORWASRSND, 0 },
+  /*
+  ** .pp
+  ** When \fIset\fP, message is forwarded in the same way like done by 
+  ** ``$$resend-message'' function with differences, that in this case 
+  ** brand new envelope will be constructed as on forwarding and also
+  ** the editable part will be formated as on forwarding. This option
+  ** overrides ``$$mime_forward''.
+  ** 
+  */
   { "from",            DT_ADDR, R_NONE, UL &From, UL 0 },
   /*
   ** .pp
diff -HurBw mutt-1.5.4/mutt.h mutt-1.5.4-forward_as_resend/mutt.h
--- mutt-1.5.4/mutt.h   2003-03-04 08:49:48.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/mutt.h 2003-07-24 09:45:06.000000000 +0200
@@ -341,6 +341,7 @@
   OPTFORCENAME,
   OPTFORWDECODE,
   OPTFORWQUOTE,
+  OPTFORWASRSND,
   OPTHDRS,
   OPTHEADER,
   OPTHELP,
diff -HurBw mutt-1.5.4/pager.c mutt-1.5.4-forward_as_resend/pager.c
--- mutt-1.5.4/pager.c  2003-01-23 23:04:28.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/pager.c        2003-07-24 13:24:57.000000000 
+0200
@@ -2168,9 +2168,9 @@
         if (IsMsgAttach (extra))
          mutt_attach_resend (extra->fp, extra->hdr,
                              extra->idx, extra->idxlen,
-                             extra->bdy);
+                             extra->bdy,0);
         else
-         mutt_resend_message (NULL, extra->ctx, extra->hdr);
+         mutt_resend_message (NULL, extra->ctx, extra->hdr,0);
         redraw = REDRAW_FULL;
         break;
       
@@ -2420,11 +2420,28 @@
       case OP_FORWARD_MESSAGE:
        CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
         CHECK_ATTACH;
+
+       if( option(OPTFORWASRSND) )
+       {
+               if (IsMsgAttach (extra))
+                       mutt_attach_resend (extra->fp, extra->hdr,
+                                       extra->idx, extra->idxlen,
+                                       extra->bdy,1);
+               else
+                       mutt_resend_message (NULL, extra->ctx, extra->hdr,1);
+       }
+       else
+       {
+
+
         if (IsMsgAttach (extra))
          mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
                               extra->idxlen, extra->bdy);
         else
          ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
+       }
+
+
        redraw = REDRAW_FULL;
        break;
 
diff -HurBw mutt-1.5.4/protos.h mutt-1.5.4-forward_as_resend/protos.h
--- mutt-1.5.4/protos.h 2003-03-06 22:24:46.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/protos.h       2003-07-24 13:28:10.000000000 
+0200
@@ -265,7 +265,7 @@
 #define mutt_is_us_ascii(a) mutt_chscmp (a, "us-ascii")
 int mutt_parent_message (CONTEXT *, HEADER *);
 int mutt_prepare_template(FILE*, CONTEXT *, HEADER *, HEADER *, short);
-int mutt_resend_message (FILE *, CONTEXT *, HEADER *);
+int mutt_resend_message (FILE *, CONTEXT *, HEADER *, short);
 #define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
 int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char 
***, int *);
 int  mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags);
diff -HurBw mutt-1.5.4/recvattach.c mutt-1.5.4-forward_as_resend/recvattach.c
--- mutt-1.5.4/recvattach.c     2003-01-21 13:25:21.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/recvattach.c   2003-07-24 13:26:58.000000000 
+0200
@@ -1073,7 +1073,7 @@
       case OP_RESEND:
         CHECK_ATTACH;
         mutt_attach_resend (fp, hdr, idx, idxlen,
-                            menu->tagprefix ? NULL : 
idx[menu->current]->content);
+                            menu->tagprefix ? NULL : 
idx[menu->current]->content,0);
         menu->redraw = REDRAW_FULL;
        break;
       
@@ -1086,6 +1086,10 @@
 
       case OP_FORWARD_MESSAGE:
         CHECK_ATTACH;
+       if( option(OPTFORWASRSND) )
+               mutt_attach_resend (fp, hdr, idx, idxlen,
+                    menu->tagprefix ? NULL : idx[menu->current]->content,1);
+       else
         mutt_attach_forward (fp, hdr, idx, idxlen,
                             menu->tagprefix ? NULL : 
idx[menu->current]->content);
         menu->redraw = REDRAW_FULL;
diff -HurBw mutt-1.5.4/recvcmd.c mutt-1.5.4-forward_as_resend/recvcmd.c
--- mutt-1.5.4/recvcmd.c        2003-03-04 08:49:48.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/recvcmd.c      2003-07-24 13:23:12.000000000 
+0200
@@ -223,7 +223,7 @@
  **/
 
 void mutt_attach_resend (FILE * fp, HEADER * hdr, ATTACHPTR ** idx, 
-                        short idxlen, BODY * cur)
+                        short idxlen, BODY * cur, short asfwd)
 {
   short i;
 
@@ -231,12 +231,12 @@
     return;
 
   if (cur)
-    mutt_resend_message (fp, Context, cur->hdr);
+    mutt_resend_message (fp, Context, cur->hdr,asfwd);
   else
   {
     for (i = 0; i < idxlen; i++)
       if (idx[i]->content->tagged)
-       mutt_resend_message (fp, Context, idx[i]->content->hdr);
+       mutt_resend_message (fp, Context, idx[i]->content->hdr,asfwd);
   }
 }
 
diff -HurBw mutt-1.5.4/send.c mutt-1.5.4-forward_as_resend/send.c
--- mutt-1.5.4/send.c   2003-03-06 22:21:32.000000000 +0100
+++ mutt-1.5.4-forward_as_resend/send.c 2003-07-24 13:36:41.000000000 +0200
@@ -1015,13 +1015,20 @@
   }
 }
 
-int mutt_resend_message (FILE *fp, CONTEXT *ctx, HEADER *cur)
+int mutt_resend_message (FILE *fp, CONTEXT *ctx, HEADER *cur, short asfwd)
 {
   HEADER *msg = mutt_new_header ();
   
   if (mutt_prepare_template (fp, ctx, msg, cur, 1) < 0)
     return -1;
   
+  if( asfwd )
+  {
+         mutt_free_envelope(&msg->env);
+         msg->env=mutt_new_envelope();
+         return ci_send_message (SENDFORWARD|SENDRESEND, msg, NULL, ctx, cur);
+  }
+  else
   return ci_send_message (SENDRESEND, msg, NULL, ctx, cur);
 }
 
@@ -1128,7 +1135,8 @@
   }
 
   /* this is handled here so that the user can match ~f in send-hook */
-  if (cur && option (OPTREVNAME) && !(flags & (SENDPOSTPONED|SENDRESEND)))
+  if (cur && option (OPTREVNAME) &&
+               (flags&SENDFORWARD || !(flags & (SENDPOSTPONED|SENDRESEND))))
   {
     /* we shouldn't have to worry about freeing `msg->env->from' before
      * setting it here since this code will only execute when doing some
@@ -1145,7 +1153,8 @@
     msg->env->from = set_reverse_name (cur->env);
   }
 
-  if (!msg->env->from && option (OPTUSEFROM) && !(flags & 
(SENDPOSTPONED|SENDRESEND)))
+  if (!msg->env->from && option (OPTUSEFROM) && 
+                 (flags&SENDFORWARD || !(flags & (SENDPOSTPONED|SENDRESEND))))
     msg->env->from = mutt_default_from ();
 
   if (flags & SENDBATCH) 
@@ -1281,10 +1290,53 @@
     }
 
   }
+  else if ( (flags&SENDRESEND) && (flags&SENDFORWARD))
+  {
+      if ( ctx && envelope_defaults (msg->env, ctx, cur, flags) == -1)
+         goto cleanup;
+
+      if (option (OPTHDRS))
+         process_user_recips (msg->env);
+
+      /* Expand aliases and remove duplicates/crossrefs */
+      mutt_fix_reply_recipients (msg->env);
+
+      if (edit_envelope (msg->env) == -1)
+         goto cleanup;
+
+      if (!msg->env->from)
+      {
+         msg->env->from = mutt_default_from ();
+         killfrom = 1;
+      }
+
+      mutt_message_hook (NULL, msg, M_SENDHOOK);
+
+      if (killfrom)
+      {
+         rfc822_free_address (&msg->env->from);
+         killfrom = 0;
+      }
+
+      if (option (OPTHDRS))
+         process_user_header (msg->env);
+
+
+      if (truncate(msg->content->filename,0) ||
+             (tempfp = safe_fopen (msg->content->filename, "a+")) == NULL)
+      {
+         mutt_perror (msg->content->filename);
+         goto cleanup;
+      }
+
+      include_forward (ctx, msg, tempfp);
+      safe_fclose (&tempfp);
+  }
   /* wait until now to set the real name portion of our return address so
      that $realname can be set in a send-hook */
   if (msg->env->from && !msg->env->from->personal
-      && !(flags & (SENDRESEND|SENDPOSTPONED)))
+      && (!(flags & (SENDRESEND|SENDPOSTPONED))||
+                      ((flags&SENDRESEND)&&(flags&SENDFORWARD))))
     msg->env->from->personal = safe_strdup (Realname);
 
   if ((WithCrypto & APPLICATION_PGP) && !(flags & SENDKEY))