Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
int mutt_print_attachment (FILE *fp, BODY *a)
{
  char newfile[_POSIX_PATH_MAX] = "";
  char type[STRING];
  pid_t thepid;
  FILE *ifp, *fpout;
  short unlink_newfile = 0;
  
  snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);

  if (rfc1524_mailcap_lookup (a, type, NULL, M_PRINT)) 
  {
    char command[_POSIX_PATH_MAX+STRING];
    rfc1524_entry *entry;
    int piped = FALSE;

    dprint (2, (debugfile, "Using mailcap...\n"));
    
    entry = rfc1524_new_entry ();
    rfc1524_mailcap_lookup (a, type, entry, M_PRINT);
    if (rfc1524_expand_filename (entry->nametemplate, a->filename,
						  newfile, sizeof (newfile)))
    {
      if (!fp)
      {
	if (safe_symlink(a->filename, newfile) == -1)
	{
	  if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES)
	  {
	    rfc1524_free_entry (&entry);
	    return 0;
	  }
	  strfcpy (newfile, a->filename, sizeof (newfile));
	}
	else
	  unlink_newfile = 1;
      }
    }

    /* in recv mode, save file to newfile first */
    if (fp)
      mutt_save_attachment (fp, a, newfile, 0, NULL);

    strfcpy (command, entry->printcommand, sizeof (command));
    piped = rfc1524_expand_command (a, newfile, type, command, sizeof (command));

    mutt_endwin (NULL);

    /* interactive program */
    if (piped)
    {
      if ((ifp = fopen (newfile, "r")) == NULL)
      {
	mutt_perror ("fopen");
	rfc1524_free_entry (&entry);
	return (0);
      }

      if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0)
      {
	mutt_perror _("Can't create filter");
	rfc1524_free_entry (&entry);
	safe_fclose (&ifp);
	return 0;
      }
      mutt_copy_stream (ifp, fpout);
      safe_fclose (&fpout);
      safe_fclose (&ifp);
      if (mutt_wait_filter (thepid) || option (OPTWAITKEY))
	mutt_any_key_to_continue (NULL);
    }
    else
    {
      if (mutt_system (command) || option (OPTWAITKEY))
	mutt_any_key_to_continue (NULL);
    }

    if (fp)
      mutt_unlink (newfile);
    else if (unlink_newfile)
      unlink(newfile);

    rfc1524_free_entry (&entry);
    return (1);
  }

  if (!ascii_strcasecmp ("text/plain", type) ||
      !ascii_strcasecmp ("application/postscript", type))
  {
    return (mutt_pipe_attachment (fp, a, NONULL(PrintCmd), NULL));
  }
  else if (mutt_can_decode (a))
  {
    /* decode and print */

    int rc = 0;
    
    ifp = NULL;
    fpout = NULL;
    
    mutt_mktemp (newfile, sizeof (newfile));
    if (mutt_decode_save_attachment (fp, a, newfile, M_PRINTING, 0) == 0)
    {
      
      dprint (2, (debugfile, "successfully decoded %s type attachment to %s\n",
		  type, newfile));
      
      if ((ifp = fopen (newfile, "r")) == NULL)
      {
	mutt_perror ("fopen");
	goto bail0;
      }

      dprint (2, (debugfile, "successfully opened %s read-only\n", newfile));
      
      mutt_endwin (NULL);
      if ((thepid = mutt_create_filter (NONULL(PrintCmd), &fpout, NULL, NULL)) < 0)
      {
	mutt_perror _("Can't create filter");
	goto bail0;
      }

      dprint (2, (debugfile, "Filter created.\n"));
      
      mutt_copy_stream (ifp, fpout);

      safe_fclose (&fpout);
      safe_fclose (&ifp);

      if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
	mutt_any_key_to_continue (NULL);
      rc = 1;
    }
  bail0:
    safe_fclose (&ifp);
    safe_fclose (&fpout);
    mutt_unlink (newfile);
    return rc;
  }
  else
  {
    mutt_error _("I don't know how to print that!");
    return 0;
  }
}
Ejemplo n.º 3
0
Archivo: recvcmd.c Proyecto: 0xAX/muttx
void mutt_attach_reply (FILE * fp, struct header *hdr,
			ATTACHPTR ** idx, short idxlen, struct body * cur,
			int flags)
{
	short mime_reply_any = 0;

	short nattach = 0;
	struct header *parent = NULL;
	struct header *tmphdr = NULL;
	short i;

	STATE st;
	char tmpbody[_POSIX_PATH_MAX];
	FILE *tmpfp;

	char prefix[SHORT_STRING];
	int rc;

	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 ((rc = query_quadoption (OPT_MIMEFWDREST,
					    ("Can't decode all tagged attachments.  MIME-encapsulate the others?"))) == -1)
			return;
		else if (rc == M_YES)
			mime_reply_any = 1;
	}
	else if (nattach == 1)
		mime_reply_any = 1;

	tmphdr = mutt_new_header ();
	tmphdr->env = mutt_new_envelope ();

	if (attach_reply_envelope_defaults (tmphdr->env, idx, idxlen,
					    parent ? parent : (cur ? cur->hdr : NULL), flags) == -1)
	{
		mutt_free_header (&tmphdr);
		return;
	}

	mutt_mktemp (tmpbody, sizeof (tmpbody));
	if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL)
	{
		mutt_error (("Can't create %s."), tmpbody);
		mutt_free_header (&tmphdr);
		return;
	}

	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
	{
		mutt_make_attribution (Context, parent, tmpfp);

		memset (&st, 0, sizeof (STATE));
		st.fpin = fp;
		st.fpout = tmpfp;

		if (!bit_val(options, OPTTEXTFLOWED))
			_mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix),
					   Context, parent, 0);
		else
			strfcpy (prefix, ">", sizeof (prefix));

		st.prefix = prefix;
		st.flags  = M_CHARCONV;

		if (bit_val(options, OPTWEED))
			st.flags |= M_WEED;

		if (bit_val(options, OPTHEADER))
			include_header (1, fp, parent, tmpfp, prefix);

		if (cur)
		{
			if (mutt_can_decode (cur))
			{
				mutt_body_handler (cur, &st);
				state_putc ('\n', &st);
			}
			else
				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);
				}
			}
		}

		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);
			safe_fclose (&tmpfp);
			return;
		}
	}

	safe_fclose (&tmpfp);

	if (ci_send_message (flags, tmphdr, tmpbody, NULL,
			     parent ? parent : (cur ? cur->hdr : NULL)) == 0)
		mutt_set_flag (Context, hdr, M_REPLIED, 1);
}
Ejemplo n.º 4
0
Archivo: recvcmd.c Proyecto: 0xAX/muttx
static void attach_forward_bodies (FILE * fp, struct header * hdr,
				   ATTACHPTR ** idx, short idxlen,
				   struct body * cur,
				   short nattach)
{
	short i;
	short mime_fwd_all = 0;
	short mime_fwd_any = 1;
	struct header *parent = NULL;
	struct header *tmphdr = NULL;
	struct body **last;
	char tmpbody[_POSIX_PATH_MAX];
	FILE *tmpfp = NULL;

	char prefix[STRING];

	int rc = 0;

	STATE st;

	/*
	 * First, find the parent message.
	 * Note: This could be made an option by just
	 * putting the following lines into an if block.
	 */


	parent = find_parent (idx, idxlen, cur, nattach);

	if (parent == NULL)
		parent = hdr;


	tmphdr = mutt_new_header ();
	tmphdr->env = mutt_new_envelope ();
	mutt_make_forward_subject (tmphdr->env, Context, parent);

	mutt_mktemp (tmpbody, sizeof (tmpbody));
	if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL)
	{
		mutt_error (("Can't open temporary file %s."), tmpbody);
		return;
	}

	mutt_forward_intro (tmpfp, parent);

	/* prepare the prefix here since we'll need it later. */

	if (bit_val(options, OPTFORWQUOTE))
	{
		if (!bit_val(options, OPTTEXTFLOWED))
			_mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context,
					   parent, 0);
		else
			strfcpy (prefix, ">", sizeof (prefix));
	}

	include_header (bit_val(options, OPTFORWQUOTE), fp, parent,
			tmpfp, prefix);


	/*
	 * Now, we have prepared the first part of the message body: The
	 * original message's header.
	 *
	 * The next part is more interesting: either include the message bodies,
	 * or attach them.
	 */

	if ((!cur || mutt_can_decode (cur)) &&
	    (rc = query_quadoption (OPT_MIMEFWD,
				    ("Forward as attachments?"))) == M_YES)
		mime_fwd_all = 1;
	else if (rc == -1)
		goto bail;

	/*
	 * shortcut MIMEFWDREST when there is only one attachment.  Is
	 * this intuitive?
	 */

	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)
			goto bail;
		else if (rc == M_NO)
			mime_fwd_any = 0;
	}

	/* initialize a state structure */

	memset (&st, 0, sizeof (st));

	if (bit_val(options, OPTFORWQUOTE))
		st.prefix = prefix;
	st.flags = M_CHARCONV;
	if (bit_val(options, OPTWEED))
		st.flags |= M_WEED;
	st.fpin = fp;
	st.fpout = tmpfp;

	/* where do we append new MIME parts? */
	last = &tmphdr->content;

	if (cur)
	{
		/* single body case */

		if (!mime_fwd_all && mutt_can_decode (cur))
		{
			mutt_body_handler (cur, &st);
			state_putc ('\n', &st);
		}
		else
		{
			if (mutt_copy_body (fp, last, cur) == -1)
				goto bail;
			last = &((*last)->next);
		}
	}
	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_any &&
		    copy_problematic_attachments (fp, last, idx, idxlen, mime_fwd_all) == NULL)
			goto bail;
	}

	mutt_forward_trailer (tmpfp);

	safe_fclose (&tmpfp);
	tmpfp = NULL;

	/* now that we have the template, send it. */
	ci_send_message (0, tmphdr, tmpbody, NULL, parent);
	return;

bail:

	if (tmpfp)
	{
		safe_fclose (&tmpfp);
		mutt_unlink (tmpbody);
	}

	mutt_free_header (&tmphdr);
}