From 9c45d9ad13fdf439d44d7443ae75da15ea0223ed Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Mon, 19 Aug 2013 16:39:41 -0400 Subject: Initial checkin Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy. --- gpglib/rfc2045.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 gpglib/rfc2045.c (limited to 'gpglib/rfc2045.c') diff --git a/gpglib/rfc2045.c b/gpglib/rfc2045.c new file mode 100644 index 0000000..df598ec --- /dev/null +++ b/gpglib/rfc2045.c @@ -0,0 +1,115 @@ +/* +** Copyright 2001-2003 Double Precision, Inc. See COPYING for +** distribution information. +*/ + + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} + -- cgit v1.2.3