/*
* Copyright (C) 1999-2000 Thomas Roessler <roessler@guug.de>
*
* 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.
*/
#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"
/* 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;
short ntagged;
char prompt[STRING];
char buf[HUGE_STRING];
ADDRESS *adr = NULL;
if (check_all_msg (idx, idxlen, cur, 1) == -1)
return;
ntagged = count_tagged (idx, idxlen);
if (cur || ntagged == 1)
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;
adr = rfc822_parse_adrlist (adr, buf);
adr = mutt_expand_aliases (adr);
buf[0] = 0;
rfc822_write_address (buf, sizeof (buf), adr);
snprintf (prompt, sizeof (prompt),
cur ? _("Bounce message to %s...?") : _("Bounce messages to %s...?"), buf);
if (mutt_yesorno (prompt, 1) != 1)
goto bail;
if (cur)
mutt_bounce_message (fp, cur->hdr, adr);
else
{
for (i = 0; i < idxlen; i++)
{
if (idx[i]->content->tagged)
mutt_bounce_message (fp, idx[i]->content->hdr, adr);
}
}
bail:
rfc822_free_address (&adr);
CLEARLINE (LINES - 1);
}
/**
**
** resend-message, from the attachment menu
**
**
**/
void mutt_attach_resend (FILE * fp, HEADER * hdr, ATTACHPTR ** idx,
short