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