/*
* Copyright (C) 1999-2004 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 "attach.h"
#include "mapping.h"
#include "copy.h"
#include "mutt_idna.h"
#include "send.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 (ATTACH_CONTEXT *actx,
BODY * cur, short err)
{
short i;
if (cur && check_msg (cur, err) == -1)
return -1;
else if (!cur)
{
for (i = 0; i < actx->idxlen; i++)
{
if (actx->idx[i]->content->tagged)
{
if (check_msg (actx->idx[i]->content, err) == -1)
return -1;
}
}
}
return 0;
}
/* can we decode all tagged attachments? */
static short check_can_decode (ATTACH_CONTEXT *actx, BODY * cur)
{
short i;
if (cur)
return mutt_can_decode (cur);
for (i = 0; i < actx->idxlen; i++)
if (actx->idx[i]->content->tagged && !mutt_can_decode (actx->idx[i]->content))
return 0;
return 1;
}
static short count_tagged (ATTACH_CONTEXT *actx)
{
short count = 0;
short i;
for (i = 0; i < actx->idxlen; i++)
if (actx->idx[i]->content->tagged)
count++;
return count;
}
/* count the number of tagged children below a multipart or message
* attachment.
*/
static short count_tagged_children (ATTACH_CONTEXT *actx, short i)
{
short level = actx->idx[i]->level;
short count = 0;
while ((++i < actx->idxlen) && (level < actx->idx[i]->level))
if (actx->idx[i]->content->tagged)
count++;
return count;
}
/* Look through the recipients of the message we are replying to, and if
* we find an address that matches $alternates, we use that as the default
* from field.
*
* This is partically duplicated logic from set_reverse_name() but
* with with different data structures. Also, in the attach case, we
* can have both cur and actx non-NULL in some cases.
*/
static ADDRESS *attach_set_reverse_name (HEADER *cur, ATTACH_CONTEXT *actx)
{
ADDRESS *tmp = NULL;
int i;
if (cur)
tmp = mutt_find_user_in_envelope (cur->env);
/* Note that, for replying, we can have a case where both cur and act are
* not null, so don't use an 'else' for the second test */
if (!tmp && actx)
{
for (i = 0; i < actx->idxlen; i++)
if (actx->idx[i]->content->tagged && actx->idx[i]->content->hdr)
if ((tmp = mutt_find_user_in_envelope (actx->idx[i]->content->hdr->env)) != NULL)
break;
}
if (tmp)
{
tmp = rfc822_cpy_adr_real (tmp);
/* when $reverse_realname is not set, clear the personal name so that it
* may be set vi a reply- or send-hook.
*/
if (!option