summaryrefslogtreecommitdiffstats
path: root/gpglib/rfc2045.c
blob: df598ec570e61de906e21be966328f73e6230f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
** Copyright 2001-2003 Double Precision, Inc.  See COPYING for
** distribution information.
*/


#include	"config.h"
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<unistd.h>
#include	<signal.h>
#include	<errno.h>
#include	<sys/types.h>
#include	<sys/stat.h>
#include	<sys/time.h>

#include	"gpg.h"
#include	"gpglib.h"

#include	"rfc2045/rfc2045.h"

struct rfc2045 *libmail_gpgmime_is_multipart_signed(const struct rfc2045 *q)
{
	struct rfc2045 *p;

	if (!q->content_type || strcmp(q->content_type, "multipart/signed"))
		return (0);

	for (p=q->firstpart; p && p->isdummy; p=p->next)
		;

	if (p && p->next && p->next->content_type &&
	    strcmp(p->next->content_type, "application/pgp-signature") == 0)
		return (p);

	return (NULL);
}

struct rfc2045 *libmail_gpgmime_is_multipart_encrypted(const struct rfc2045 *q)
{
	struct rfc2045 *p;

	if (!q->content_type || strcmp(q->content_type, "multipart/encrypted"))
		return (0);

	for (p=q->firstpart; p && p->isdummy; p=p->next)
		;

	if (p && p->content_type && p->next && p->next->content_type &&
	    strcmp(p->content_type, "application/pgp-encrypted") == 0 &&
	    strcmp(p->next->content_type, "application/octet-stream") == 0)
		return (p->next);

	return (NULL);
}

int libmail_gpgmime_has_mimegpg(const struct rfc2045 *q)
{
	if (libmail_gpgmime_is_multipart_signed(q) ||
	    libmail_gpgmime_is_multipart_encrypted(q))
		return (1);

	for (q=q->firstpart; q; q=q->next)
	{
		if (q->isdummy)
			continue;
		if (libmail_gpgmime_has_mimegpg(q))
			return (1);
	}
	return (0);
}

int libmail_gpgmime_is_decoded(const struct rfc2045 *q, int *retcode)
{
	const char *p;

	if (!q->content_type || strcasecmp(q->content_type,
					   "multipart/x-mimegpg"))
		return (0);

	p=rfc2045_getattr(q->content_type_attr, "xpgpstatus");
	if (!p)
		return (0);

	*retcode=atoi(p);
	return (1);
}

struct rfc2045 *libmail_gpgmime_decoded_content(const struct rfc2045 *q)
{
	for (q=q->firstpart; q; q=q->next)
	{
		if (q->isdummy)
			continue;

		return (q->next);
	}
	return (NULL);
}

struct rfc2045 *libmail_gpgmime_signed_content(const struct rfc2045 *p)
{
	struct rfc2045 *q;

	for (q=p->firstpart; q; q=q->next)
	{
		if (q->isdummy)
			continue;

		return (q);
	}
	return (NULL);
}