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