X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=recvcmd.c;h=0d8813b75979181ccd1ee38d8655cf054ec1a452;hp=d91db9a6e8bce86849fee8083694fd2fc9966772;hb=6605e3e4bf358e8d5835232623dc359af219cc6a;hpb=3d937534e7b1ee723f86594b5e4c64c95158a933 diff --git a/recvcmd.c b/recvcmd.c index d91db9a..0d8813b 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -1,108 +1,84 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1999-2000 Thomas Roessler - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111, USA. + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ +#include + +#include + +#include +#include +#include + #include "mutt.h" -#include "mutt_curses.h" -#include "mutt_menu.h" -#include "rfc1524.h" -#include "mime.h" -#include "mailbox.h" +#include "alias.h" +#include "state.h" +#include "handler.h" +#include "recvattach.h" #include "attach.h" -#include "mapping.h" -#include "mx.h" #include "copy.h" #include "mutt_idna.h" + /* some helper functions to verify that we are exclusively operating * on message/rfc822 attachments */ - -static short check_msg (BODY * b, short err) +static int check_all_msg(ATTACHPTR **idx, int idxlen, BODY *cur, bool err) { - if (!mutt_is_message_type (b->type, b->subtype)) - { - if (err) - mutt_error _("You may only bounce message/rfc822 parts."); - return -1; - } - return 0; -} + if (cur) { + if (!mutt_is_message_type(cur)) + goto error; + } else { + for (int i = 0; i < idxlen; i++) { + BODY *b = idx[i]->content; + if (b->tagged && !mutt_is_message_type(b)) + goto error; + } + } + return 0; -static short check_all_msg (ATTACHPTR ** idx, short idxlen, - BODY * cur, short err) -{ - short i; + error: + if (err) + mutt_error(_("You may only bounce message/rfc822 parts.")); - if (cur && check_msg (cur, err) == -1) return -1; - else if (!cur) - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged) - { - if (check_msg (idx[i]->content, err) == -1) - return -1; - } - } - } - return 0; } - /* can we decode all tagged attachments? */ - -static short check_can_decode (ATTACHPTR ** idx, short idxlen, - BODY * cur) +static int check_can_decode(ATTACHPTR ** idx, int idxlen, BODY * cur) { - short i; - - if (cur) - return mutt_can_decode (cur); + if (cur) + return mutt_can_decode(cur); - for (i = 0; i < idxlen; i++) - if (idx[i]->content->tagged && !mutt_can_decode (idx[i]->content)) - return 0; + for (int i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged && !mutt_can_decode(idx[i]->content)) + return 0; + } - return 1; + return -1; } -static short count_tagged (ATTACHPTR **idx, short idxlen) +static int count_tagged(ATTACHPTR **idx, int idxlen) { - short count = 0; - short i; - - for (i = 0; i < idxlen; i++) - if (idx[i]->content->tagged) - count++; - - return count; + int count = 0; + + for (int i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged) + count++; + } + + return count; } /* count the number of tagged children below a multipart or message * attachment. */ - -static short count_tagged_children (ATTACHPTR ** idx, - short idxlen, short i) +static short count_tagged_children (ATTACHPTR ** idx, short idxlen, short i) { short level = idx[i]->level; short count = 0; @@ -115,23 +91,20 @@ static short count_tagged_children (ATTACHPTR ** idx, } - /** - ** ** The bounce function, from the attachment menu - ** **/ -void mutt_attach_bounce (FILE * fp, HEADER * hdr, - ATTACHPTR ** idx, short idxlen, BODY * cur) +void mutt_attach_bounce (FILE * fp, HEADER * hdr __attribute__ ((unused)), + ATTACHPTR ** idx, short idxlen, BODY * cur) { short i; char prompt[STRING]; char buf[HUGE_STRING]; char *err = NULL; - ADDRESS *adr = NULL; + address_t *adr = NULL; int ret = 0; - int p = 0; + int p = 0; if (check_all_msg (idx, idxlen, cur, 1) == -1) return; @@ -140,90 +113,81 @@ void mutt_attach_bounce (FILE * fp, HEADER * hdr, p = (cur || count_tagged (idx, idxlen) == 1); if (p) - strfcpy (prompt, _("Bounce message to: "), sizeof (prompt)); + m_strcpy(prompt, sizeof(prompt), _("Bounce message to: ")); else - strfcpy (prompt, _("Bounce tagged messages to: "), sizeof (prompt)); + m_strcpy(prompt, sizeof(prompt), _("Bounce tagged messages to: ")); buf[0] = '\0'; - if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS) + if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS) || buf[0] == '\0') return; - if (!(adr = rfc822_parse_adrlist (adr, buf))) - { + if (!(adr = rfc822_parse_adrlist (adr, buf))) { mutt_error _("Error parsing address!"); + return; } adr = mutt_expand_aliases (adr); - - if (mutt_addrlist_to_idna (adr, &err) < 0) - { + + if (mutt_addrlist_to_idna (adr, &err) < 0) { mutt_error (_("Bad IDN: '%s'"), err); - FREE (&err); - rfc822_free_address (&adr); + p_delete(&err); + address_list_wipe(&adr); return; } - + buf[0] = 0; - rfc822_write_address (buf, sizeof (buf), adr, 1); + rfc822_addrcat(buf, sizeof(buf), adr, 1); -#define extra_space (15+7+2) /* * See commands.c. */ - snprintf (prompt, sizeof (prompt) - 4, - (p ? _("Bounce message to %s") : _("Bounce messages to %s")), buf); - - if (mutt_strwidth (prompt) > COLS - extra_space) - { - mutt_format_string (prompt, sizeof (prompt) - 4, - 0, COLS-extra_space, 0, 0, - prompt, sizeof (prompt), 0); - safe_strcat (prompt, sizeof (prompt), "...?"); - } - else - safe_strcat (prompt, sizeof (prompt), "?"); + snprintf (prompt, sizeof (prompt) - 4, + (p ? _("Bounce message to %s") : _("Bounce messages to %s")), + buf); - if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) - { - rfc822_free_address (&adr); - CLEARLINE (LINES - 1); +#define extra_space (15+7+2) + if (m_strwidth(prompt) > getmaxx(main_w) - extra_space) { + mutt_format_string (prompt, sizeof (prompt) - 4, 0, + getmaxx(main_w) - extra_space, 0, 0, + prompt, sizeof (prompt), 0); + m_strcat(prompt, sizeof(prompt), "...?"); + } else { + m_strcat(prompt, sizeof(prompt), "?"); + } +#undef extra_space + + if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) { + address_list_wipe(&adr); mutt_message (p ? _("Message not bounced.") : _("Messages not bounced.")); return; } - - CLEARLINE (LINES - 1); - + if (cur) ret = mutt_bounce_message (fp, cur->hdr, adr); - else - { - for (i = 0; i < idxlen; i++) - { + else { + for (i = 0; i < idxlen; i++) { if (idx[i]->content->tagged) - if (mutt_bounce_message (fp, idx[i]->content->hdr, adr)) - ret = 1; + if (mutt_bounce_message (fp, idx[i]->content->hdr, adr)) + ret = 1; } } if (!ret) mutt_message (p ? _("Message bounced.") : _("Messages bounced.")); else - mutt_error (p ? _("Error bouncing message!") : _("Error bouncing messages!")); + mutt_error (p ? _("Error bouncing message!") : + _("Error bouncing messages!")); } - /** - ** ** resend-message, from the attachment menu - ** - ** **/ -void mutt_attach_resend (FILE * fp, HEADER * hdr, ATTACHPTR ** idx, - short idxlen, BODY * cur) +void mutt_attach_resend (FILE * fp, HEADER * hdr __attribute__ ((unused)), ATTACHPTR ** idx, + short idxlen, BODY * cur) { short i; @@ -232,25 +196,21 @@ void mutt_attach_resend (FILE * fp, HEADER * hdr, ATTACHPTR ** idx, if (cur) mutt_resend_message (fp, Context, cur->hdr); - else - { + 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); } } - /** - ** ** forward-message, from the attachment menu - ** **/ - + /* try to find a common parent message for the tagged attachments. */ static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen, - short nattach) + short nattach) { short i; short nchildren; @@ -258,14 +218,12 @@ static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen, for (i = 0; i < idxlen; i++) if (idx[i]->content->tagged) break; - - while (--i >= 0) - { - if (mutt_is_message_type (idx[i]->content->type, idx[i]->content->subtype)) - { + + while (--i >= 0) { + if (mutt_is_message_type(idx[i]->content)) { nchildren = count_tagged_children (idx, idxlen, i); if (nchildren == nattach) - return idx[i]->content->hdr; + return idx[i]->content->hdr; } } @@ -280,12 +238,11 @@ static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen, * bit. For now, it's not worth the effort. */ -static int is_parent (short i, ATTACHPTR **idx, short idxlen, BODY *cur) +static int is_parent (short i, ATTACHPTR ** idx, short idxlen, BODY * cur) { short level = idx[i]->level; - while ((++i < idxlen) && idx[i]->level > level) - { + while ((++i < idxlen) && idx[i]->level > level) { if (idx[i]->content == cur) return 1; } @@ -293,72 +250,130 @@ static int is_parent (short i, ATTACHPTR **idx, short idxlen, BODY *cur) return 0; } -static HEADER *find_parent (ATTACHPTR **idx, short idxlen, BODY *cur, short nattach) +static HEADER *find_parent (ATTACHPTR ** idx, short idxlen, BODY * cur, + short nattach) { short i; HEADER *parent = NULL; - - if (cur) - { - for (i = 0; i < idxlen; i++) - { - if (mutt_is_message_type (idx[i]->content->type, idx[i]->content->subtype) - && is_parent (i, idx, idxlen, cur)) - parent = idx[i]->content->hdr; + + if (cur) { + for (i = 0; i < idxlen; i++) { + if (mutt_is_message_type(idx[i]->content) + && is_parent (i, idx, idxlen, cur)) + parent = idx[i]->content->hdr; if (idx[i]->content == cur) - break; + break; } } else if (nattach) parent = find_common_parent (idx, idxlen, nattach); - + return parent; } static void include_header (int quote, FILE * ifp, - HEADER * hdr, FILE * ofp, - char *_prefix) + HEADER * hdr, FILE * ofp, char *_prefix) { int chflags = CH_DECODE; - char prefix[SHORT_STRING]; - + char prefix[STRING]; + if (option (OPTWEED)) chflags |= CH_WEED | CH_REORDER; - if (quote) - { + if (quote) { if (_prefix) - strfcpy (prefix, _prefix, sizeof (prefix)); + m_strcpy(prefix, sizeof(prefix), _prefix); else if (!option (OPTTEXTFLOWED)) - _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), - Context, hdr, 0); + _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), + Context, hdr, 0); else - strfcpy (prefix, ">", sizeof (prefix)); + m_strcpy(prefix, sizeof(prefix), ">"); chflags |= CH_PREFIX; } - + mutt_copy_header (ifp, hdr, ofp, chflags, quote ? prefix : NULL); } +/* create a send-mode duplicate from a receive-mode body */ +static int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src) +{ + char tmp[_POSIX_PATH_MAX]; + BODY *b; + + parameter_t *par, **ppar; + + short use_disp; + + if (src->filename) { + use_disp = 1; + m_strcpy(tmp, sizeof(tmp), src->filename); + } else { + use_disp = 0; + tmp[0] = '\0'; + } + + mutt_adv_mktemp (NULL, tmp, sizeof (tmp)); + if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1) + return -1; + + *tgt = body_new(); + b = *tgt; + + memcpy (b, src, sizeof (BODY)); + b->parts = NULL; + b->next = NULL; + + b->filename = m_strdup(tmp); + b->use_disp = use_disp; + b->unlink = 1; + + if (mutt_is_text_part (b)) + b->noconv = 1; + + b->xtype = m_strdup(b->xtype); + b->subtype = m_strdup(b->subtype); + b->form_name = m_strdup(b->form_name); + b->filename = m_strdup(b->filename); + b->d_filename = m_strdup(b->d_filename); + b->description = m_strdup(b->description); + + /* + * we don't seem to need the HEADER structure currently. + * XXX - this may change in the future + */ + + if (b->hdr) + b->hdr = NULL; + + /* copy parameters */ + for (par = b->parameter, ppar = &b->parameter; par; + ppar = &(*ppar)->next, par = par->next) { + *ppar = parameter_new(); + (*ppar)->attribute = m_strdup(par->attribute); + (*ppar)->value = m_strdup(par->value); + } + + mutt_stamp_attachment (b); + + return 0; +} + /* Attach all the body parts which can't be decoded. * This code is shared by forwarding and replying. */ -static BODY ** copy_problematic_attachments (FILE *fp, - BODY **last, - ATTACHPTR **idx, - short idxlen, - short force) +static BODY **copy_problematic_attachments (FILE * fp, + BODY ** last, + ATTACHPTR ** idx, + short idxlen, short force) { short i; - - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged && - (force || !mutt_can_decode (idx[i]->content))) - { + + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged && + (force || !mutt_can_decode (idx[i]->content))) { if (mutt_copy_body (fp, last, idx[i]->content) == -1) - return NULL; /* XXXXX - may lead to crashes */ + return NULL; /* XXXXX - may lead to crashes */ last = &((*last)->next); } } @@ -371,9 +386,8 @@ static BODY ** copy_problematic_attachments (FILE *fp, */ static void attach_forward_bodies (FILE * fp, HEADER * hdr, - ATTACHPTR ** idx, short idxlen, - BODY * cur, - short nattach, int flags) + ATTACHPTR ** idx, short idxlen, + BODY * cur, short nattach, int flags) { short i; short mime_fwd_all = 0; @@ -398,19 +412,18 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr, parent = find_parent (idx, idxlen, cur, nattach); - + if (parent == NULL) parent = hdr; - tmphdr = mutt_new_header (); - tmphdr->env = mutt_new_envelope (); + tmphdr = header_new(); + tmphdr->env = envelope_new(); mutt_make_forward_subject (tmphdr->env, Context, parent); - mutt_mktemp (tmpbody); - if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) - { - mutt_error (_("Can't open temporary file %s."), tmpbody); + tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(mod_core.tmpdir), NULL); + if (!tmpfp) { + mutt_error(_("Could not create temporary file")); return; } @@ -418,17 +431,15 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr, /* prepare the prefix here since we'll need it later. */ - if (option (OPTFORWQUOTE)) - { + if (option (OPTFORWQUOTE)) { if (!option (OPTTEXTFLOWED)) _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, - parent, 0); + parent, 0); else - strfcpy (prefix, ">", sizeof (prefix)); + m_strcpy(prefix, sizeof(prefix), ">"); } - - include_header (option (OPTFORWQUOTE), fp, parent, - tmpfp, prefix); + + include_header (option (OPTFORWQUOTE), fp, parent, tmpfp, prefix); /* @@ -440,8 +451,8 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr, */ if ((!cur || mutt_can_decode (cur)) && - (rc = query_quadoption (OPT_MIMEFWD, - _("Forward as attachments?"))) == M_YES) + (rc = query_quadoption (OPT_MIMEFWD, + _("Forward as attachments?"))) == M_YES) mime_fwd_all = 1; else if (rc == -1) goto bail; @@ -451,20 +462,21 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr, * this intuitive? */ - if (!mime_fwd_all && !cur && (nattach > 1) - && !check_can_decode (idx, idxlen, cur)) - { + if (!mime_fwd_all && !cur && (nattach > 1) + && !check_can_decode (idx, idxlen, cur)) { if ((rc = query_quadoption (OPT_MIMEFWDREST, -_("Can't decode all tagged attachments. MIME-forward the others?"))) == -1) + _ + ("Can't decode all tagged attachments. MIME-forward the others?"))) + == -1) goto bail; else if (rc == M_NO) mime_fwd_any = 0; } /* initialize a state structure */ - - memset (&st, 0, sizeof (st)); - + + p_clear(&st, 1); + if (option (OPTFORWQUOTE)) st.prefix = prefix; st.flags = M_CHARCONV; @@ -476,61 +488,49 @@ _("Can't decode all tagged attachments. MIME-forward the others?"))) == -1) /* where do we append new MIME parts? */ last = &tmphdr->content; - if (cur) - { + if (cur) { /* single body case */ - if (!mime_fwd_all && mutt_can_decode (cur)) - { + if (!mime_fwd_all && mutt_can_decode (cur)) { mutt_body_handler (cur, &st); state_putc ('\n', &st); } - else - { + else { if (mutt_copy_body (fp, last, cur) == -1) - goto bail; + goto bail; last = &((*last)->next); } } - else - { + else { /* multiple body case */ - if (!mime_fwd_all) - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) - { - mutt_body_handler (idx[i]->content, &st); - state_putc ('\n', &st); - } + if (!mime_fwd_all) { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) { + mutt_body_handler (idx[i]->content, &st); + state_putc ('\n', &st); + } } } - if (mime_fwd_any && - (last = copy_problematic_attachments (fp, last, idx, idxlen, mime_fwd_all)) == NULL) + if (mime_fwd_any && + (last = + copy_problematic_attachments (fp, last, idx, idxlen, + mime_fwd_all)) == NULL) goto bail; } - + mutt_forward_trailer (tmpfp); - - fclose (tmpfp); - tmpfp = NULL; + m_fclose(&tmpfp); /* now that we have the template, send it. */ ci_send_message (flags, tmphdr, tmpbody, NULL, parent); return; - - bail: - - if (tmpfp) - { - fclose (tmpfp); - mutt_unlink (tmpbody); - } - mutt_free_header (&tmphdr); +bail: + m_fclose(&tmpfp); + mutt_unlink(tmpbody); + header_delete(&tmphdr); } @@ -545,8 +545,9 @@ _("Can't decode all tagged attachments. MIME-forward the others?"))) == -1) * the attachment index. */ -static void attach_forward_msgs (FILE * fp, HEADER * hdr, - ATTACHPTR ** idx, short idxlen, BODY * cur, int flags) +static void attach_forward_msgs (FILE * fp, HEADER * hdr __attribute__ ((unused)), + ATTACHPTR ** idx, short idxlen, BODY * cur, + int flags) { HEADER *curhdr = NULL; HEADER *tmphdr; @@ -559,125 +560,108 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr, int cmflags = 0; int chflags = CH_XMIT; - + if (cur) curhdr = cur->hdr; - else - { + else { for (i = 0; i < idxlen; i++) - if (idx[i]->content->tagged) - { - curhdr = idx[i]->content->hdr; - break; + if (idx[i]->content->tagged) { + curhdr = idx[i]->content->hdr; + break; } } - tmphdr = mutt_new_header (); - tmphdr->env = mutt_new_envelope (); + tmphdr = header_new(); + tmphdr->env = envelope_new(); mutt_make_forward_subject (tmphdr->env, Context, curhdr); tmpbody[0] = '\0'; - if ((rc = query_quadoption (OPT_MIMEFWD, - _("Forward MIME encapsulated?"))) == M_NO) - { - + if ((rc = query_quadoption (OPT_MIMEFWD, + _("Forward MIME encapsulated?"))) == M_NO) { + /* no MIME encapsulation */ - - mutt_mktemp (tmpbody); - if (!(tmpfp = safe_fopen (tmpbody, "w"))) - { - mutt_error (_("Can't create %s."), tmpbody); - mutt_free_header (&tmphdr); + + tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(mod_core.tmpdir), NULL); + if (!tmpfp) { + mutt_error(_("Could not create temporary file")); + header_delete(&tmphdr); return; } - if (option (OPTFORWQUOTE)) - { + if (option (OPTFORWQUOTE)) { chflags |= CH_PREFIX; cmflags |= M_CM_PREFIX; } - if (option (OPTFORWDECODE)) - { + if (option (OPTFORWDECODE)) { cmflags |= M_CM_DECODE | M_CM_CHARCONV; - if (option (OPTWEED)) - { - chflags |= CH_WEED | CH_REORDER; - cmflags |= M_CM_WEED; + if (option (OPTWEED)) { + chflags |= CH_WEED | CH_REORDER; + cmflags |= M_CM_WEED; } } - - - if (cur) - { - /* mutt_message_hook (cur->hdr, M_MESSAGEHOOK); */ + + + if (cur) { + /* mutt_message_hook (cur->hdr, M_MESSAGEHOOK); */ mutt_forward_intro (tmpfp, cur->hdr); - _mutt_copy_message (tmpfp, fp, cur->hdr, cur->hdr->content, cmflags, chflags); + _mutt_copy_message (tmpfp, fp, cur->hdr, cur->hdr->content, cmflags, + chflags); mutt_forward_trailer (tmpfp); } - else - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged) - { - /* mutt_message_hook (idx[i]->content->hdr, M_MESSAGEHOOK); */ - mutt_forward_intro (tmpfp, idx[i]->content->hdr); - _mutt_copy_message (tmpfp, fp, idx[i]->content->hdr, - idx[i]->content->hdr->content, cmflags, chflags); - mutt_forward_trailer (tmpfp); - } + else { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged) { + /* mutt_message_hook (idx[i]->content->hdr, M_MESSAGEHOOK); */ + mutt_forward_intro (tmpfp, idx[i]->content->hdr); + _mutt_copy_message (tmpfp, fp, idx[i]->content->hdr, + idx[i]->content->hdr->content, cmflags, + chflags); + mutt_forward_trailer (tmpfp); + } } } - fclose (tmpfp); + m_fclose(&tmpfp); } - else if (rc == M_YES) /* do MIME encapsulation - we don't need to do much here */ - { + else if (rc == M_YES) { /* do MIME encapsulation - we don't need to do much here */ last = &tmphdr->content; if (cur) mutt_copy_body (fp, last, cur); - else - { + else { for (i = 0; i < idxlen; i++) - if (idx[i]->content->tagged) - { - mutt_copy_body (fp, last, idx[i]->content); - last = &((*last)->next); - } + if (idx[i]->content->tagged) { + mutt_copy_body (fp, last, idx[i]->content); + last = &((*last)->next); + } } } else - mutt_free_header (&tmphdr); + header_delete(&tmphdr); - ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL, - NULL, curhdr); + ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL, NULL, curhdr); } -void mutt_attach_forward (FILE * fp, HEADER * hdr, - ATTACHPTR ** idx, short idxlen, BODY * cur, int flags) +void mutt_attach_forward (FILE * fp, HEADER * hdr, + ATTACHPTR ** idx, short idxlen, BODY * cur, + int flags) { short nattach; - - if (check_all_msg (idx, idxlen, cur, 0) == 0) + + if (check_all_msg (idx, idxlen, cur, 0) == 0) { attach_forward_msgs (fp, hdr, idx, idxlen, cur, flags); - else - { + } else { nattach = count_tagged (idx, idxlen); attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach, flags); } } - /** - ** ** the various reply functions, from the attachment menu - ** - ** **/ /* Create the envelope defaults for a reply. @@ -692,121 +676,99 @@ void mutt_attach_forward (FILE * fp, HEADER * hdr, * * Note that this code is horribly similar to envelope_defaults () from send.c. */ - + static int -attach_reply_envelope_defaults (ENVELOPE *env, ATTACHPTR **idx, short idxlen, - HEADER *parent, int flags) +attach_reply_envelope_defaults (ENVELOPE * env, ATTACHPTR ** idx, + short idxlen, HEADER * parent, int flags) { ENVELOPE *curenv = NULL; HEADER *curhdr = NULL; short i; - - if (!parent) - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged) - { - curhdr = idx[i]->content->hdr; - curenv = curhdr->env; - break; + + if (!parent) { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged) { + curhdr = idx[i]->content->hdr; + curenv = curhdr->env; + break; } } } - else - { + else { curenv = parent->env; curhdr = parent; } - if (curenv == NULL || curhdr == NULL) - { + if (curenv == NULL || curhdr == NULL) { mutt_error _("Can't find any tagged messages."); + return -1; } -#ifdef USE_NNTP - if ((flags & SENDNEWS)) - { - /* in case followup set Newsgroups: with Followup-To: if it present */ - if (!env->newsgroups && curenv && - mutt_strcasecmp (curenv->followup_to, "poster")) - env->newsgroups = safe_strdup (curenv->followup_to); - } - else -#endif - { - if (parent) - { - if (mutt_fetch_recips (env, curenv, flags) == -1) - return -1; - } - else - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged - && mutt_fetch_recips (env, idx[i]->content->hdr->env, flags) == -1) - return -1; - } + if (parent) { + if (mutt_fetch_recips (env, curenv, flags) == -1) + return -1; + } else { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged + && mutt_fetch_recips (env, idx[i]->content->hdr->env, + flags) == -1) + return -1; } + } - if ((flags & SENDLISTREPLY) && !env->to) - { - mutt_error _("No mailing lists found!"); - return (-1); - } + if ((flags & SENDLISTREPLY) && !env->to) { + mutt_error _("No mailing lists found!"); - mutt_fix_reply_recipients (env); + return -1; } + + mutt_fix_reply_recipients (env); mutt_make_misc_reply_headers (env, Context, curhdr, curenv); if (parent) mutt_add_to_reference_headers (env, curenv, NULL, NULL); - else - { - LIST **p = NULL, **q = NULL; - - for (i = 0; i < idxlen; i++) - { + else { + string_list_t **p = NULL, **q = NULL; + + for (i = 0; i < idxlen; i++) { if (idx[i]->content->tagged) - mutt_add_to_reference_headers (env, idx[i]->content->hdr->env, &p, &q); + mutt_add_to_reference_headers (env, idx[i]->content->hdr->env, &p, + &q); } } - + return 0; } /* This is _very_ similar to send.c's include_reply(). */ -static void attach_include_reply (FILE *fp, FILE *tmpfp, HEADER *cur, int flags) +static void attach_include_reply (FILE * fp, FILE * tmpfp, HEADER * cur, + int flags __attribute__ ((unused))) { int cmflags = M_CM_PREFIX | M_CM_DECODE | M_CM_CHARCONV; int chflags = CH_DECODE; - /* mutt_message_hook (cur, M_MESSAGEHOOK); */ - + /* mutt_message_hook (cur, M_MESSAGEHOOK); */ + mutt_make_attribution (Context, cur, tmpfp); - + if (!option (OPTHEADER)) cmflags |= M_CM_NOHEADER; - if (option (OPTWEED)) - { + if (option (OPTWEED)) { chflags |= CH_WEED; cmflags |= M_CM_WEED; } _mutt_copy_message (tmpfp, fp, cur, cur->content, cmflags, chflags); - mutt_make_post_indent (Context, cur, tmpfp); } - -void mutt_attach_reply (FILE * fp, HEADER * hdr, - ATTACHPTR ** idx, short idxlen, BODY * cur, - int flags) + +void mutt_attach_reply (FILE * fp, HEADER * hdr, + ATTACHPTR ** idx, short idxlen, BODY * cur, int flags) { short mime_reply_any = 0; - + short nattach = 0; HEADER *parent = NULL; HEADER *tmphdr = NULL; @@ -815,28 +777,21 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr, STATE st; char tmpbody[_POSIX_PATH_MAX]; FILE *tmpfp; - - char prefix[SHORT_STRING]; + + char prefix[STRING]; int rc; - -#ifdef USE_NNTP - if (flags & SENDNEWS) - set_option (OPTNEWSSEND); - else - unset_option (OPTNEWSSEND); -#endif - if (check_all_msg (idx, idxlen, cur, 0) == -1) - { + if (check_all_msg (idx, idxlen, cur, 0) == -1) { nattach = count_tagged (idx, idxlen); if ((parent = find_parent (idx, idxlen, cur, nattach)) == NULL) parent = hdr; } - if (nattach > 1 && !check_can_decode (idx, idxlen, cur)) - { + if (nattach > 1 && !check_can_decode (idx, idxlen, cur)) { if ((rc = query_quadoption (OPT_MIMEFWDREST, - _("Can't decode all tagged attachments. MIME-encapsulate the others?"))) == -1) + _ + ("Can't decode all tagged attachments. MIME-encapsulate the others?"))) + == -1) return; else if (rc == M_YES) mime_reply_any = 1; @@ -844,96 +799,84 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr, else if (nattach == 1) mime_reply_any = 1; - tmphdr = mutt_new_header (); - tmphdr->env = mutt_new_envelope (); + tmphdr = header_new(); + tmphdr->env = envelope_new(); - if (attach_reply_envelope_defaults (tmphdr->env, idx, idxlen, - parent ? parent : (cur ? cur->hdr : NULL), flags) == -1) - { - mutt_free_header (&tmphdr); + if (attach_reply_envelope_defaults (tmphdr->env, idx, idxlen, + parent ? parent : (cur ? cur-> + hdr : NULL), + flags) == -1) { + header_delete(&tmphdr); return; } - - mutt_mktemp (tmpbody); - if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) - { - mutt_error (_("Can't create %s."), tmpbody); - mutt_free_header (&tmphdr); + + tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(mod_core.tmpdir), NULL); + if (!tmpfp) { + mutt_error(_("Could not create temporary file")); + header_delete(&tmphdr); return; } - if (!parent) - { + if (!parent) { if (cur) attach_include_reply (fp, tmpfp, cur->hdr, flags); - else - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged) - attach_include_reply (fp, tmpfp, idx[i]->content->hdr, flags); + else { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged) + attach_include_reply (fp, tmpfp, idx[i]->content->hdr, flags); } } } - else - { + else { mutt_make_attribution (Context, parent, tmpfp); - - memset (&st, 0, sizeof (STATE)); + + p_clear(&st, 1); st.fpin = fp; st.fpout = tmpfp; if (!option (OPTTEXTFLOWED)) - _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), - Context, parent, 0); + _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), + Context, parent, 0); else - strfcpy (prefix, ">", sizeof (prefix)); + m_strcpy(prefix, sizeof(prefix), ">"); st.prefix = prefix; - st.flags = M_CHARCONV; - - if (option (OPTWEED)) + st.flags = M_CHARCONV; + + if (option (OPTWEED)) st.flags |= M_WEED; if (option (OPTHEADER)) include_header (1, fp, parent, tmpfp, prefix); - if (cur) - { - if (mutt_can_decode (cur)) - { - mutt_body_handler (cur, &st); - state_putc ('\n', &st); + if (cur) { + if (mutt_can_decode (cur)) { + mutt_body_handler (cur, &st); + state_putc ('\n', &st); } else - mutt_copy_body (fp, &tmphdr->content, cur); + mutt_copy_body (fp, &tmphdr->content, cur); } - else - { - for (i = 0; i < idxlen; i++) - { - if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) - { - mutt_body_handler (idx[i]->content, &st); - state_putc ('\n', &st); - } + else { + for (i = 0; i < idxlen; i++) { + if (idx[i]->content->tagged && mutt_can_decode (idx[i]->content)) { + mutt_body_handler (idx[i]->content, &st); + state_putc ('\n', &st); + } } } - mutt_make_post_indent (Context, parent, tmpfp); - - if (mime_reply_any && !cur && - copy_problematic_attachments (fp, &tmphdr->content, idx, idxlen, 0) == NULL) - { - mutt_free_header (&tmphdr); - fclose (tmpfp); + if (mime_reply_any && !cur && + copy_problematic_attachments (fp, &tmphdr->content, idx, idxlen, + 0) == NULL) { + header_delete(&tmphdr); + m_fclose(&tmpfp); return; } } - fclose (tmpfp); - + m_fclose(&tmpfp); + if (ci_send_message (flags, tmphdr, tmpbody, NULL, parent) == 0) mutt_set_flag (Context, hdr, M_REPLIED, 1); } -