Beispiel #1
0
static void show_preview(const char *filename)
{
char	*header, *value;
struct	rfc2045	*rfcp;
FILE	*fp;
int	fd;

	fp=0;
	fd=maildir_safeopen(filename, O_RDONLY, 0);
	if (fd >= 0)
		if ((fp=fdopen(fd, "r")) == 0)
			close(fd);

	if (!fp)	return;

	while ((header=maildir_readheader(fp, &value, 1)) != 0)
	{
		/* Don't show X-, From, and Content- headers in preview */

		if (strncmp(header, "x-", 2) == 0)	continue;
		if (strcmp(header, "mime-version") == 0)	continue;
		if (strncmp(header, "content-", 8) == 0)	continue;

		printf("%c", toupper(*header));
		output_attrencoded_oknl(header+1);
		printf(": ");

		value=rfc2047_decode_enhanced(value, sqwebmail_content_charset);
		if (value)
		{
			output_attrencoded_oknl(value);
			free(value);
		}
		printf("\n");
	}
	printf("\n");

	rfcp=rfc2045_fromfp(fp);
	if (!rfcp)	return;

	filter_start(FILTER_FOR_PREVIEW, &preview_show_func_s);
	{
		struct rfc2045 *q=
			rfc2045_searchcontenttype(rfcp, "text/plain");

		if (q)
			rfc2045_decodemimesection(fileno(fp), q,
						  &filter_stub, NULL);
	}
	rfc2045_free(rfcp);
	filter_end();
}
Beispiel #2
0
void newmsg_showfp(FILE *fp, int *attachcnt)
{
	struct	rfc2045 *p=rfc2045_fromfp(fp), *q;

	if (!p)	enomem();

	/* Here's a nice opportunity to count all attachments */

	*attachcnt=0;

	for (q=p->firstpart; q; q=q->next)
		if (!q->isdummy)	++*attachcnt;
	if (*attachcnt)	--*attachcnt;
	/* Not counting the 1st MIME part */

	{
		const char *content_type;
		const char *content_transfer_encoding;
		const char *charset;

		rfc2045_mimeinfo(p, &content_type,
				 &content_transfer_encoding, &charset);

		if (content_type &&
		    strcmp(content_type, "multipart/alternative") == 0)
			*attachcnt=0;
	}

	q=rfc2045_searchcontenttype(p, "text/plain");

	if (q)
	{
		struct rfc2045src *src=rfc2045src_init_fd(fileno(fp));

		if (src)
		{
			struct show_textarea_info info;

			show_textarea_init(&info, 1);

			rfc2045_decodetextmimesection(src, q,
						      sqwebmail_content_charset,
						      NULL,
						      &show_textarea_trampoline,
						      &info);
			rfc2045src_deinit(src);
			show_textarea(&info, "\n", 1);
		}
	}
	rfc2045_free(p);
}
struct rfc2045 *rfc2045_searchcontenttype(struct rfc2045 *rfc, const char *ct)
{
	const	char *content_type, *dummy;
	struct rfc2045 *p;

        rfc2045_mimeinfo(rfc, &content_type, &dummy, &dummy);
	if (strcmp(content_type, ct) == 0)
		return (rfc);

	for (p=rfc->firstpart; p; p=p->next)
	{
		if (p->isdummy)	continue;
		rfc2045_mimeinfo(p, &content_type, &dummy, &dummy);
		if (strcmp(content_type, ct) == 0)
			break;
		if (strncmp(content_type, "multipart/", 10) == 0)
			return(rfc2045_searchcontenttype(p, ct));
	}

	return (p);
}
Beispiel #4
0
void newmsg_showfp(FILE *fp, int *attachcnt)
{
	struct	rfc2045 *p=rfc2045_fromfp(fp), *q;

	if (!p)	enomem();

	/* Here's a nice opportunity to count all attachments */

	*attachcnt=0;

	for (q=p->firstpart; q; q=q->next)
		if (!q->isdummy)	++*attachcnt;
	if (*attachcnt)	--*attachcnt;
	/* Not counting the 1st MIME part */

	q=rfc2045_searchcontenttype(p, "text/plain");

	if (q)
		rfc2045_decodemimesection(fileno(fp), q,
					  &show_textarea, NULL);
	rfc2045_free(p);
}