sort out some prototypes, put them where they belong.
[apps/madmutt.git] / recvcmd.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #if HAVE_CONFIG_H
11 # include "config.h"
12 #endif
13
14 #include <lib-lib/lib-lib.h>
15
16 #include <lib-mime/mime.h>
17
18 #include <lib-ui/curses.h>
19 #include <lib-ui/enter.h>
20 #include <lib-ui/menu.h>
21
22 #include "mutt.h"
23 #include "alias.h"
24 #include "state.h"
25 #include "handler.h"
26 #include "recvattach.h"
27 #include "attach.h"
28 #include "mx.h"
29 #include "copy.h"
30 #include "mutt_idna.h"
31
32
33 /* some helper functions to verify that we are exclusively operating
34  * on message/rfc822 attachments
35  */
36
37 static short check_msg (BODY * b, short err)
38 {
39   if (!mutt_is_message_type (b->type, b->subtype)) {
40     if (err)
41       mutt_error _("You may only bounce message/rfc822 parts.");
42
43     return -1;
44   }
45   return 0;
46 }
47
48 static short check_all_msg (ATTACHPTR ** idx, short idxlen,
49                             BODY * cur, short err)
50 {
51   short i;
52
53   if (cur && check_msg (cur, err) == -1)
54     return -1;
55   else if (!cur) {
56     for (i = 0; i < idxlen; i++) {
57       if (idx[i]->content->tagged) {
58         if (check_msg (idx[i]->content, err) == -1)
59           return -1;
60       }
61     }
62   }
63   return 0;
64 }
65
66
67 /* can we decode all tagged attachments? */
68
69 static short check_can_decode (ATTACHPTR ** idx, short idxlen, BODY * cur)
70 {
71   short i;
72
73   if (cur)
74     return mutt_can_decode (cur);
75
76   for (i = 0; i < idxlen; i++)
77     if (idx[i]->content->tagged && !mutt_can_decode (idx[i]->content))
78       return 0;
79
80   return 1;
81 }
82
83 static short count_tagged (ATTACHPTR ** idx, short idxlen)
84 {
85   short count = 0;
86   short i;
87
88   for (i = 0; i < idxlen; i++)
89     if (idx[i]->content->tagged)
90       count++;
91
92   return count;
93 }
94
95 /* count the number of tagged children below a multipart or message
96  * attachment.
97  */
98
99 static short count_tagged_children (ATTACHPTR ** idx, short idxlen, short i)
100 {
101   short level = idx[i]->level;
102   short count = 0;
103
104   while ((++i < idxlen) && (level < idx[i]->level))
105     if (idx[i]->content->tagged)
106       count++;
107
108   return count;
109 }
110 \f
111
112
113 /**
114  ** The bounce function, from the attachment menu
115  **/
116
117 void mutt_attach_bounce (FILE * fp, HEADER * hdr __attribute__ ((unused)),
118                          ATTACHPTR ** idx, short idxlen, BODY * cur)
119 {
120   short i;
121   char prompt[STRING];
122   char buf[HUGE_STRING];
123   char *err = NULL;
124   address_t *adr = NULL;
125   int ret = 0;
126   int p = 0;
127
128   if (check_all_msg (idx, idxlen, cur, 1) == -1)
129     return;
130
131   /* one or more messages? */
132   p = (cur || count_tagged (idx, idxlen) == 1);
133
134   if (p)
135     m_strcpy(prompt, sizeof(prompt), _("Bounce message to: "));
136   else
137     m_strcpy(prompt, sizeof(prompt), _("Bounce tagged messages to: "));
138
139   buf[0] = '\0';
140   if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS)
141       || buf[0] == '\0')
142     return;
143
144   if (!(adr = rfc822_parse_adrlist (adr, buf))) {
145     mutt_error _("Error parsing address!");
146
147     return;
148   }
149
150   adr = mutt_expand_aliases (adr);
151
152   if (mutt_addrlist_to_idna (adr, &err) < 0) {
153     mutt_error (_("Bad IDN: '%s'"), err);
154     p_delete(&err);
155     address_list_wipe(&adr);
156     return;
157   }
158
159   buf[0] = 0;
160   rfc822_write_address (buf, sizeof (buf), adr, 1);
161
162 #define extra_space (15+7+2)
163   /*
164    * See commands.c.
165    */
166   snprintf (prompt, sizeof (prompt) - 4,
167             (p ? _("Bounce message to %s") : _("Bounce messages to %s")),
168             buf);
169
170   if (mutt_strwidth (prompt) > COLS - extra_space) {
171     mutt_format_string (prompt, sizeof (prompt) - 4,
172                         0, COLS - extra_space, 0, 0,
173                         prompt, sizeof (prompt), 0);
174     m_strcat(prompt, sizeof(prompt), "...?");
175   } else {
176     m_strcat(prompt, sizeof(prompt), "?");
177   }
178
179   if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) {
180     address_list_wipe(&adr);
181     CLEARLINE (LINES - 1);
182     mutt_message (p ? _("Message not bounced.") : _("Messages not bounced."));
183     return;
184   }
185
186   CLEARLINE (LINES - 1);
187
188   if (cur)
189     ret = mutt_bounce_message (fp, cur->hdr, adr);
190   else {
191     for (i = 0; i < idxlen; i++) {
192       if (idx[i]->content->tagged)
193         if (mutt_bounce_message (fp, idx[i]->content->hdr, adr))
194           ret = 1;
195     }
196   }
197
198   if (!ret)
199     mutt_message (p ? _("Message bounced.") : _("Messages bounced."));
200   else
201     mutt_error (p ? _("Error bouncing message!") :
202                 _("Error bouncing messages!"));
203 }
204 \f
205
206
207 /**
208  ** resend-message, from the attachment menu 
209  **/
210
211 void mutt_attach_resend (FILE * fp, HEADER * hdr __attribute__ ((unused)), ATTACHPTR ** idx,
212                          short idxlen, BODY * cur)
213 {
214   short i;
215
216   if (check_all_msg (idx, idxlen, cur, 1) == -1)
217     return;
218
219   if (cur)
220     mutt_resend_message (fp, Context, cur->hdr);
221   else {
222     for (i = 0; i < idxlen; i++)
223       if (idx[i]->content->tagged)
224         mutt_resend_message (fp, Context, idx[i]->content->hdr);
225   }
226 }
227 \f
228
229 /**
230  ** forward-message, from the attachment menu 
231  **/
232
233 /* try to find a common parent message for the tagged attachments. */
234
235 static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen,
236                                    short nattach)
237 {
238   short i;
239   short nchildren;
240
241   for (i = 0; i < idxlen; i++)
242     if (idx[i]->content->tagged)
243       break;
244
245   while (--i >= 0) {
246     if (mutt_is_message_type
247         (idx[i]->content->type, idx[i]->content->subtype)) {
248       nchildren = count_tagged_children (idx, idxlen, i);
249       if (nchildren == nattach)
250         return idx[i]->content->hdr;
251     }
252   }
253
254   return NULL;
255 }
256
257 /* 
258  * check whether attachment #i is a parent of the attachment
259  * pointed to by cur
260  * 
261  * Note: This and the calling procedure could be optimized quite a 
262  * bit.  For now, it's not worth the effort.
263  */
264
265 static int is_parent (short i, ATTACHPTR ** idx, short idxlen, BODY * cur)
266 {
267   short level = idx[i]->level;
268
269   while ((++i < idxlen) && idx[i]->level > level) {
270     if (idx[i]->content == cur)
271       return 1;
272   }
273
274   return 0;
275 }
276
277 static HEADER *find_parent (ATTACHPTR ** idx, short idxlen, BODY * cur,
278                             short nattach)
279 {
280   short i;
281   HEADER *parent = NULL;
282
283   if (cur) {
284     for (i = 0; i < idxlen; i++) {
285       if (mutt_is_message_type
286           (idx[i]->content->type, idx[i]->content->subtype)
287           && is_parent (i, idx, idxlen, cur))
288         parent = idx[i]->content->hdr;
289       if (idx[i]->content == cur)
290         break;
291     }
292   }
293   else if (nattach)
294     parent = find_common_parent (idx, idxlen, nattach);
295
296   return parent;
297 }
298
299 static void include_header (int quote, FILE * ifp,
300                             HEADER * hdr, FILE * ofp, char *_prefix)
301 {
302   int chflags = CH_DECODE;
303   char prefix[SHORT_STRING];
304
305   if (option (OPTWEED))
306     chflags |= CH_WEED | CH_REORDER;
307
308   if (quote) {
309     if (_prefix)
310       m_strcpy(prefix, sizeof(prefix), _prefix);
311     else if (!option (OPTTEXTFLOWED))
312       _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix),
313                          Context, hdr, 0);
314     else
315       m_strcpy(prefix, sizeof(prefix), ">");
316
317     chflags |= CH_PREFIX;
318   }
319
320   mutt_copy_header (ifp, hdr, ofp, chflags, quote ? prefix : NULL);
321 }
322
323 /* Attach all the body parts which can't be decoded. 
324  * This code is shared by forwarding and replying. */
325
326 static BODY **copy_problematic_attachments (FILE * fp,
327                                             BODY ** last,
328                                             ATTACHPTR ** idx,
329                                             short idxlen, short force)
330 {
331   short i;
332
333   for (i = 0; i < idxlen; i++) {
334     if (idx[i]->content->tagged &&
335         (force || !mutt_can_decode (idx[i]->content))) {
336       if (mutt_copy_body (fp, last, idx[i]->content) == -1)
337         return NULL;            /* XXXXX - may lead to crashes */
338       last = &((*last)->next);
339     }
340   }
341   return last;
342 }
343
344 /* 
345  * forward one or several MIME bodies 
346  * (non-message types)
347  */
348
349 static void attach_forward_bodies (FILE * fp, HEADER * hdr,
350                                    ATTACHPTR ** idx, short idxlen,
351                                    BODY * cur, short nattach, int flags)
352 {
353   short i;
354   short mime_fwd_all = 0;
355   short mime_fwd_any = 1;
356   HEADER *parent = NULL;
357   HEADER *tmphdr = NULL;
358   BODY **last;
359   char tmpbody[_POSIX_PATH_MAX];
360   FILE *tmpfp = NULL;
361
362   char prefix[STRING];
363
364   int rc = 0;
365
366   STATE st;
367
368   /* 
369    * First, find the parent message.
370    * Note: This could be made an option by just
371    * putting the following lines into an if block.
372    */
373
374
375   parent = find_parent (idx, idxlen, cur, nattach);
376
377   if (parent == NULL)
378     parent = hdr;
379
380
381   tmphdr = header_new();
382   tmphdr->env = envelope_new();
383   mutt_make_forward_subject (tmphdr->env, Context, parent);
384
385   mutt_mktemp (tmpbody);
386   if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) {
387     mutt_error (_("Can't open temporary file %s."), tmpbody);
388     return;
389   }
390
391   mutt_forward_intro (tmpfp, parent);
392
393   /* prepare the prefix here since we'll need it later. */
394
395   if (option (OPTFORWQUOTE)) {
396     if (!option (OPTTEXTFLOWED))
397       _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context,
398                          parent, 0);
399     else
400       m_strcpy(prefix, sizeof(prefix), ">");
401   }
402
403   include_header (option (OPTFORWQUOTE), fp, parent, tmpfp, prefix);
404
405
406   /* 
407    * Now, we have prepared the first part of the message body: The
408    * original message's header. 
409    *
410    * The next part is more interesting: either include the message bodies,
411    * or attach them.
412    */
413
414   if ((!cur || mutt_can_decode (cur)) &&
415       (rc = query_quadoption (OPT_MIMEFWD,
416                               _("Forward as attachments?"))) == M_YES)
417     mime_fwd_all = 1;
418   else if (rc == -1)
419     goto bail;
420
421   /* 
422    * shortcut MIMEFWDREST when there is only one attachment.  Is 
423    * this intuitive?
424    */
425
426   if (!mime_fwd_all && !cur && (nattach > 1)
427       && !check_can_decode (idx, idxlen, cur)) {
428     if ((rc = query_quadoption (OPT_MIMEFWDREST,
429                                 _
430                                 ("Can't decode all tagged attachments.  MIME-forward the others?")))
431         == -1)
432       goto bail;
433     else if (rc == M_NO)
434       mime_fwd_any = 0;
435   }
436
437   /* initialize a state structure */
438
439   p_clear(&st, 1);
440
441   if (option (OPTFORWQUOTE))
442     st.prefix = prefix;
443   st.flags = M_CHARCONV;
444   if (option (OPTWEED))
445     st.flags |= M_WEED;
446   st.fpin = fp;
447   st.fpout = tmpfp;
448
449   /* where do we append new MIME parts? */
450   last = &tmphdr->content;
451
452   if (cur) {
453     /* single body case */
454
455     if (!mime_fwd_all && mutt_can_decode (cur)) {
456       mutt_body_handler (cur, &st);
457       state_putc ('\n', &st);
458     }
459     else {
460       if (mutt_copy_body (fp, last, cur) == -1)
461         goto bail;
462       last = &((*last)->next);
463     }
464   }
465   else {
466     /* multiple body case */
467
468     if (!mime_fwd_all) {
469       for (i = 0; i < idxlen; i++) {
470         if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) {
471           mutt_body_handler (idx[i]->content, &st);
472           state_putc ('\n', &st);
473         }
474       }
475     }
476
477     if (mime_fwd_any &&
478         (last =
479          copy_problematic_attachments (fp, last, idx, idxlen,
480                                        mime_fwd_all)) == NULL)
481       goto bail;
482   }
483
484   mutt_forward_trailer (tmpfp);
485
486   fclose (tmpfp);
487   tmpfp = NULL;
488
489   /* now that we have the template, send it. */
490   ci_send_message (flags, tmphdr, tmpbody, NULL, parent);
491   return;
492
493 bail:
494
495   if (tmpfp) {
496     fclose (tmpfp);
497     mutt_unlink (tmpbody);
498   }
499
500   header_delete(&tmphdr);
501 }
502
503
504 /* 
505  * Forward one or several message-type attachments. This 
506  * is different from the previous function
507  * since we want to mimic the index menu's behaviour.
508  *
509  * Code reuse from ci_send_message is not possible here -
510  * ci_send_message relies on a context structure to find messages,
511  * while, on the attachment menu, messages are referenced through
512  * the attachment index. 
513  */
514
515 static void attach_forward_msgs (FILE * fp, HEADER * hdr __attribute__ ((unused)),
516                                  ATTACHPTR ** idx, short idxlen, BODY * cur,
517                                  int flags)
518 {
519   HEADER *curhdr = NULL;
520   HEADER *tmphdr;
521   short i;
522   int rc;
523
524   BODY **last;
525   char tmpbody[_POSIX_PATH_MAX];
526   FILE *tmpfp = NULL;
527
528   int cmflags = 0;
529   int chflags = CH_XMIT;
530
531   if (cur)
532     curhdr = cur->hdr;
533   else {
534     for (i = 0; i < idxlen; i++)
535       if (idx[i]->content->tagged) {
536         curhdr = idx[i]->content->hdr;
537         break;
538       }
539   }
540
541   tmphdr = header_new();
542   tmphdr->env = envelope_new();
543   mutt_make_forward_subject (tmphdr->env, Context, curhdr);
544
545
546   tmpbody[0] = '\0';
547
548   if ((rc = query_quadoption (OPT_MIMEFWD,
549                               _("Forward MIME encapsulated?"))) == M_NO) {
550
551     /* no MIME encapsulation */
552
553     mutt_mktemp (tmpbody);
554     if (!(tmpfp = safe_fopen (tmpbody, "w"))) {
555       mutt_error (_("Can't create %s."), tmpbody);
556       header_delete(&tmphdr);
557       return;
558     }
559
560     if (option (OPTFORWQUOTE)) {
561       chflags |= CH_PREFIX;
562       cmflags |= M_CM_PREFIX;
563     }
564
565     if (option (OPTFORWDECODE)) {
566       cmflags |= M_CM_DECODE | M_CM_CHARCONV;
567       if (option (OPTWEED)) {
568         chflags |= CH_WEED | CH_REORDER;
569         cmflags |= M_CM_WEED;
570       }
571     }
572
573
574     if (cur) {
575       /* mutt_message_hook (cur->hdr, M_MESSAGEHOOK); */
576       mutt_forward_intro (tmpfp, cur->hdr);
577       _mutt_copy_message (tmpfp, fp, cur->hdr, cur->hdr->content, cmflags,
578                           chflags);
579       mutt_forward_trailer (tmpfp);
580     }
581     else {
582       for (i = 0; i < idxlen; i++) {
583         if (idx[i]->content->tagged) {
584           /* mutt_message_hook (idx[i]->content->hdr, M_MESSAGEHOOK); */
585           mutt_forward_intro (tmpfp, idx[i]->content->hdr);
586           _mutt_copy_message (tmpfp, fp, idx[i]->content->hdr,
587                               idx[i]->content->hdr->content, cmflags,
588                               chflags);
589           mutt_forward_trailer (tmpfp);
590         }
591       }
592     }
593     fclose (tmpfp);
594   }
595   else if (rc == M_YES) {       /* do MIME encapsulation - we don't need to do much here */
596     last = &tmphdr->content;
597     if (cur)
598       mutt_copy_body (fp, last, cur);
599     else {
600       for (i = 0; i < idxlen; i++)
601         if (idx[i]->content->tagged) {
602           mutt_copy_body (fp, last, idx[i]->content);
603           last = &((*last)->next);
604         }
605     }
606   }
607   else
608     header_delete(&tmphdr);
609
610   ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL, NULL, curhdr);
611
612 }
613
614 void mutt_attach_forward (FILE * fp, HEADER * hdr,
615                           ATTACHPTR ** idx, short idxlen, BODY * cur,
616                           int flags)
617 {
618   short nattach;
619
620
621   if (check_all_msg (idx, idxlen, cur, 0) == 0)
622     attach_forward_msgs (fp, hdr, idx, idxlen, cur, flags);
623   else {
624     nattach = count_tagged (idx, idxlen);
625     attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach, flags);
626   }
627 }
628 \f
629
630
631 /**
632  ** the various reply functions, from the attachment menu
633  **/
634
635 /* Create the envelope defaults for a reply.
636  *
637  * This function can be invoked in two ways.
638  * 
639  * Either, parent is NULL.  In this case, all tagged bodies are of a message type,
640  * and the header information is fetched from them.
641  * 
642  * Or, parent is non-NULL.  In this case, cur is the common parent of all the
643  * tagged attachments.
644  * 
645  * Note that this code is horribly similar to envelope_defaults () from send.c.
646  */
647
648 static int
649 attach_reply_envelope_defaults (ENVELOPE * env, ATTACHPTR ** idx,
650                                 short idxlen, HEADER * parent, int flags)
651 {
652   ENVELOPE *curenv = NULL;
653   HEADER *curhdr = NULL;
654   short i;
655
656   if (!parent) {
657     for (i = 0; i < idxlen; i++) {
658       if (idx[i]->content->tagged) {
659         curhdr = idx[i]->content->hdr;
660         curenv = curhdr->env;
661         break;
662       }
663     }
664   }
665   else {
666     curenv = parent->env;
667     curhdr = parent;
668   }
669
670   if (curenv == NULL || curhdr == NULL) {
671     mutt_error _("Can't find any tagged messages.");
672
673     return -1;
674   }
675
676 #ifdef USE_NNTP
677   if ((flags & SENDNEWS)) {
678     /* in case followup set Newsgroups: with Followup-To: if it present */
679     if (!env->newsgroups && curenv &&
680         m_strcasecmp(curenv->followup_to, "poster"))
681       env->newsgroups = m_strdup(curenv->followup_to);
682   }
683   else
684 #endif
685   {
686     if (parent) {
687       if (mutt_fetch_recips (env, curenv, flags) == -1)
688         return -1;
689     }
690     else {
691       for (i = 0; i < idxlen; i++) {
692         if (idx[i]->content->tagged
693             && mutt_fetch_recips (env, idx[i]->content->hdr->env,
694                                   flags) == -1)
695           return -1;
696       }
697     }
698
699     if ((flags & SENDLISTREPLY) && !env->to) {
700       mutt_error _("No mailing lists found!");
701
702       return (-1);
703     }
704
705     mutt_fix_reply_recipients (env);
706   }
707   mutt_make_misc_reply_headers (env, Context, curhdr, curenv);
708
709   if (parent)
710     mutt_add_to_reference_headers (env, curenv, NULL, NULL);
711   else {
712     string_list_t **p = NULL, **q = NULL;
713
714     for (i = 0; i < idxlen; i++) {
715       if (idx[i]->content->tagged)
716         mutt_add_to_reference_headers (env, idx[i]->content->hdr->env, &p,
717                                        &q);
718     }
719   }
720
721   return 0;
722 }
723
724
725 /*  This is _very_ similar to send.c's include_reply(). */
726
727 static void attach_include_reply (FILE * fp, FILE * tmpfp, HEADER * cur,
728                                   int flags __attribute__ ((unused)))
729 {
730   int cmflags = M_CM_PREFIX | M_CM_DECODE | M_CM_CHARCONV;
731   int chflags = CH_DECODE;
732
733   /* mutt_message_hook (cur, M_MESSAGEHOOK); */
734
735   mutt_make_attribution (Context, cur, tmpfp);
736
737   if (!option (OPTHEADER))
738     cmflags |= M_CM_NOHEADER;
739   if (option (OPTWEED)) {
740     chflags |= CH_WEED;
741     cmflags |= M_CM_WEED;
742   }
743
744   _mutt_copy_message (tmpfp, fp, cur, cur->content, cmflags, chflags);
745   mutt_make_post_indent (Context, cur, tmpfp);
746 }
747
748 void mutt_attach_reply (FILE * fp, HEADER * hdr,
749                         ATTACHPTR ** idx, short idxlen, BODY * cur, int flags)
750 {
751   short mime_reply_any = 0;
752
753   short nattach = 0;
754   HEADER *parent = NULL;
755   HEADER *tmphdr = NULL;
756   short i;
757
758   STATE st;
759   char tmpbody[_POSIX_PATH_MAX];
760   FILE *tmpfp;
761
762   char prefix[SHORT_STRING];
763   int rc;
764
765 #ifdef USE_NNTP
766   if (flags & SENDNEWS)
767     set_option (OPTNEWSSEND);
768   else
769     unset_option (OPTNEWSSEND);
770 #endif
771
772   if (check_all_msg (idx, idxlen, cur, 0) == -1) {
773     nattach = count_tagged (idx, idxlen);
774     if ((parent = find_parent (idx, idxlen, cur, nattach)) == NULL)
775       parent = hdr;
776   }
777
778   if (nattach > 1 && !check_can_decode (idx, idxlen, cur)) {
779     if ((rc = query_quadoption (OPT_MIMEFWDREST,
780                                 _
781                                 ("Can't decode all tagged attachments.  MIME-encapsulate the others?")))
782         == -1)
783       return;
784     else if (rc == M_YES)
785       mime_reply_any = 1;
786   }
787   else if (nattach == 1)
788     mime_reply_any = 1;
789
790   tmphdr = header_new();
791   tmphdr->env = envelope_new();
792
793   if (attach_reply_envelope_defaults (tmphdr->env, idx, idxlen,
794                                       parent ? parent : (cur ? cur->
795                                                          hdr : NULL),
796                                       flags) == -1) {
797     header_delete(&tmphdr);
798     return;
799   }
800
801   mutt_mktemp (tmpbody);
802   if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) {
803     mutt_error (_("Can't create %s."), tmpbody);
804     header_delete(&tmphdr);
805     return;
806   }
807
808   if (!parent) {
809     if (cur)
810       attach_include_reply (fp, tmpfp, cur->hdr, flags);
811     else {
812       for (i = 0; i < idxlen; i++) {
813         if (idx[i]->content->tagged)
814           attach_include_reply (fp, tmpfp, idx[i]->content->hdr, flags);
815       }
816     }
817   }
818   else {
819     mutt_make_attribution (Context, parent, tmpfp);
820
821     p_clear(&st, 1);
822     st.fpin = fp;
823     st.fpout = tmpfp;
824
825     if (!option (OPTTEXTFLOWED))
826       _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix),
827                          Context, parent, 0);
828     else
829       m_strcpy(prefix, sizeof(prefix), ">");
830
831     st.prefix = prefix;
832     st.flags = M_CHARCONV;
833
834     if (option (OPTWEED))
835       st.flags |= M_WEED;
836
837     if (option (OPTHEADER))
838       include_header (1, fp, parent, tmpfp, prefix);
839
840     if (cur) {
841       if (mutt_can_decode (cur)) {
842         mutt_body_handler (cur, &st);
843         state_putc ('\n', &st);
844       }
845       else
846         mutt_copy_body (fp, &tmphdr->content, cur);
847     }
848     else {
849       for (i = 0; i < idxlen; i++) {
850         if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) {
851           mutt_body_handler (idx[i]->content, &st);
852           state_putc ('\n', &st);
853         }
854       }
855     }
856
857     mutt_make_post_indent (Context, parent, tmpfp);
858
859     if (mime_reply_any && !cur &&
860         copy_problematic_attachments (fp, &tmphdr->content, idx, idxlen,
861                                       0) == NULL) {
862       header_delete(&tmphdr);
863       fclose (tmpfp);
864       return;
865     }
866   }
867
868   fclose (tmpfp);
869
870   if (ci_send_message (flags, tmphdr, tmpbody, NULL, parent) == 0)
871     mutt_set_flag (Context, hdr, M_REPLIED, 1);
872 }