/*
* Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "rfc1524.h"
#include "mime.h"
#include "mailbox.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)
{
if (!mutt_is_message_type (b->type, b->subtype))
{
if (err)
mutt_error _("You may only bounce message/rfc822 parts.");
return -1;
}
return 0;
}
static short check_all_msg (ATTACHPTR ** idx, short idxlen,
BODY * cur, short err)
{
short i;
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)
{
short i;
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;
return 1;
}
static short count_tagged (ATTACHPTR **idx, short idxlen)
{
short count = 0;
short i;
for (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)
{
short level = idx[i]->level;
short count = 0;
while ((++i < idxlen) && (level < idx[i]->level))
if (idx[i]->content->tagged)
count++;
return count;
}
/**
**
** The bounce function, from the attachment menu
**
**/
void mutt_attach_bounce (FILE * fp, HEADER * hdr,
ATTACHPTR ** idx, short idxlen, BODY * cur)
{
short i;
char prompt[STRING];
char buf[HUGE_STRING];
char *err = NULL;
ADDRESS *adr = NULL;
int ret = 0;
int p = 0;
if (check_all_msg (idx, idxlen, cur, 1) == -1)
return;
/* one or more messages? */
p = (cur || count_tagged (idx, idxlen) == 1);
if (p)
strfcpy (prompt, _("Bounce message to: "), sizeof (prompt));
else
strfcpy (prompt, _("Bounce tagged messages to: "), sizeof (prompt));
buf[0] = '\0';
if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS)
|| buf[0] == '\0')
return;
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)
{
mutt_error (_("Bad IDN: '%s'"), err);
FREE (&err);
rfc822_free_address (&adr);
return;
}
buf[0] = 0;
rfc822_write_address (buf, sizeof (buf), adr, 1);
#define extra_