Back to index

courier  0.68.2
rfc2045.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2001-2003 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 
00007 #include      "config.h"
00008 #include      <stdio.h>
00009 #include      <stdlib.h>
00010 #include      <string.h>
00011 #include      <unistd.h>
00012 #include      <signal.h>
00013 #include      <errno.h>
00014 #include      <sys/types.h>
00015 #include      <sys/stat.h>
00016 #include      <sys/time.h>
00017 
00018 #include      "gpg.h"
00019 #include      "gpglib.h"
00020 
00021 #include      "rfc2045/rfc2045.h"
00022 
00023 struct rfc2045 *libmail_gpgmime_is_multipart_signed(const struct rfc2045 *q)
00024 {
00025        struct rfc2045 *p;
00026 
00027        if (!q->content_type || strcmp(q->content_type, "multipart/signed"))
00028               return (0);
00029 
00030        for (p=q->firstpart; p && p->isdummy; p=p->next)
00031               ;
00032 
00033        if (p && p->next && p->next->content_type &&
00034            strcmp(p->next->content_type, "application/pgp-signature") == 0)
00035               return (p);
00036 
00037        return (NULL);
00038 }
00039 
00040 struct rfc2045 *libmail_gpgmime_is_multipart_encrypted(const struct rfc2045 *q)
00041 {
00042        struct rfc2045 *p;
00043 
00044        if (!q->content_type || strcmp(q->content_type, "multipart/encrypted"))
00045               return (0);
00046 
00047        for (p=q->firstpart; p && p->isdummy; p=p->next)
00048               ;
00049 
00050        if (p && p->content_type && p->next && p->next->content_type &&
00051            strcmp(p->content_type, "application/pgp-encrypted") == 0 &&
00052            strcmp(p->next->content_type, "application/octet-stream") == 0)
00053               return (p->next);
00054 
00055        return (NULL);
00056 }
00057 
00058 int libmail_gpgmime_has_mimegpg(const struct rfc2045 *q)
00059 {
00060        if (libmail_gpgmime_is_multipart_signed(q) ||
00061            libmail_gpgmime_is_multipart_encrypted(q))
00062               return (1);
00063 
00064        for (q=q->firstpart; q; q=q->next)
00065        {
00066               if (q->isdummy)
00067                      continue;
00068               if (libmail_gpgmime_has_mimegpg(q))
00069                      return (1);
00070        }
00071        return (0);
00072 }
00073 
00074 int libmail_gpgmime_is_decoded(const struct rfc2045 *q, int *retcode)
00075 {
00076        const char *p;
00077 
00078        if (!q->content_type || strcasecmp(q->content_type,
00079                                       "multipart/x-mimegpg"))
00080               return (0);
00081 
00082        p=rfc2045_getattr(q->content_type_attr, "xpgpstatus");
00083        if (!p)
00084               return (0);
00085 
00086        *retcode=atoi(p);
00087        return (1);
00088 }
00089 
00090 struct rfc2045 *libmail_gpgmime_decoded_content(const struct rfc2045 *q)
00091 {
00092        for (q=q->firstpart; q; q=q->next)
00093        {
00094               if (q->isdummy)
00095                      continue;
00096 
00097               return (q->next);
00098        }
00099        return (NULL);
00100 }
00101 
00102 struct rfc2045 *libmail_gpgmime_signed_content(const struct rfc2045 *p)
00103 {
00104        struct rfc2045 *q;
00105 
00106        for (q=p->firstpart; q; q=q->next)
00107        {
00108               if (q->isdummy)
00109                      continue;
00110 
00111               return (q);
00112        }
00113        return (NULL);
00114 }
00115