root / libsylph / procmime.h @ 1693
History | View | Annotate | Download (5 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 578 | hiro | * LibSylph -- E-Mail client library |
| 3 | 1693 | hiro | * Copyright (C) 1999-2007 Hiroyuki Yamamoto |
| 4 | 1 | hiro | * |
| 5 | 578 | hiro | * This library is free software; you can redistribute it and/or |
| 6 | 578 | hiro | * modify it under the terms of the GNU Lesser General Public |
| 7 | 578 | hiro | * License as published by the Free Software Foundation; either |
| 8 | 578 | hiro | * version 2.1 of the License, or (at your option) any later version. |
| 9 | 1 | hiro | * |
| 10 | 578 | hiro | * This library is distributed in the hope that it will be useful, |
| 11 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 578 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | 578 | hiro | * Lesser General Public License for more details. |
| 14 | 1 | hiro | * |
| 15 | 578 | hiro | * You should have received a copy of the GNU Lesser General Public |
| 16 | 578 | hiro | * License along with this library; if not, write to the Free Software |
| 17 | 578 | hiro | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | 1 | hiro | */ |
| 19 | 1 | hiro | |
| 20 | 1 | hiro | #ifndef __PROCMIME_H__
|
| 21 | 1 | hiro | #define __PROCMIME_H__
|
| 22 | 1 | hiro | |
| 23 | 1 | hiro | #ifdef HAVE_CONFIG_H
|
| 24 | 1 | hiro | # include "config.h" |
| 25 | 1 | hiro | #endif
|
| 26 | 1 | hiro | |
| 27 | 1 | hiro | #include <glib.h> |
| 28 | 1 | hiro | #include <stdio.h> |
| 29 | 1 | hiro | |
| 30 | 1 | hiro | typedef struct _MimeType MimeType; |
| 31 | 1032 | hiro | typedef struct _MailCap MailCap; |
| 32 | 1 | hiro | typedef struct _MimeInfo MimeInfo; |
| 33 | 1 | hiro | |
| 34 | 1 | hiro | #include "procmsg.h" |
| 35 | 1 | hiro | #include "utils.h" |
| 36 | 1 | hiro | |
| 37 | 1 | hiro | typedef enum |
| 38 | 1 | hiro | {
|
| 39 | 1 | hiro | ENC_7BIT, |
| 40 | 1 | hiro | ENC_8BIT, |
| 41 | 1 | hiro | ENC_QUOTED_PRINTABLE, |
| 42 | 1 | hiro | ENC_BASE64, |
| 43 | 1 | hiro | ENC_X_UUENCODE, |
| 44 | 1 | hiro | ENC_UNKNOWN |
| 45 | 1 | hiro | } EncodingType; |
| 46 | 1 | hiro | |
| 47 | 1 | hiro | typedef enum |
| 48 | 1 | hiro | {
|
| 49 | 1 | hiro | MIME_TEXT, |
| 50 | 1 | hiro | MIME_TEXT_HTML, |
| 51 | 1 | hiro | MIME_MESSAGE_RFC822, |
| 52 | 1 | hiro | MIME_APPLICATION, |
| 53 | 1 | hiro | MIME_APPLICATION_OCTET_STREAM, |
| 54 | 1 | hiro | MIME_MULTIPART, |
| 55 | 1 | hiro | MIME_IMAGE, |
| 56 | 1 | hiro | MIME_AUDIO, |
| 57 | 924 | hiro | MIME_VIDEO, |
| 58 | 1 | hiro | MIME_UNKNOWN |
| 59 | 1 | hiro | } ContentType; |
| 60 | 1 | hiro | |
| 61 | 1 | hiro | struct _MimeType
|
| 62 | 1 | hiro | {
|
| 63 | 1 | hiro | gchar *type; |
| 64 | 1 | hiro | gchar *sub_type; |
| 65 | 1 | hiro | |
| 66 | 1 | hiro | gchar *extension; |
| 67 | 1 | hiro | }; |
| 68 | 1 | hiro | |
| 69 | 1032 | hiro | struct _MailCap
|
| 70 | 1032 | hiro | {
|
| 71 | 1032 | hiro | gchar *mime_type; |
| 72 | 1032 | hiro | gchar *cmdline_fmt; |
| 73 | 1032 | hiro | gboolean needs_terminal; |
| 74 | 1032 | hiro | }; |
| 75 | 1032 | hiro | |
| 76 | 1 | hiro | /*
|
| 77 | 1 | hiro | * An example of MimeInfo structure: |
| 78 | 1 | hiro | * |
| 79 | 1 | hiro | * multipart/mixed root <-+ parent |
| 80 | 1 | hiro | * | |
| 81 | 1 | hiro | * multipart/alternative children <-+ parent |
| 82 | 1 | hiro | * | |
| 83 | 1 | hiro | * text/plain children --+ |
| 84 | 1 | hiro | * | |
| 85 | 1 | hiro | * text/html next <-+ |
| 86 | 1 | hiro | * |
| 87 | 1 | hiro | * message/rfc822 next <-+ main |
| 88 | 1 | hiro | * | |
| 89 | 1 | hiro | * sub (capsulated message) |
| 90 | 1 | hiro | * |
| 91 | 1 | hiro | * image/jpeg next |
| 92 | 1 | hiro | */ |
| 93 | 1 | hiro | |
| 94 | 1 | hiro | struct _MimeInfo
|
| 95 | 1 | hiro | {
|
| 96 | 1 | hiro | gchar *encoding; |
| 97 | 1 | hiro | |
| 98 | 1 | hiro | EncodingType encoding_type; |
| 99 | 1 | hiro | ContentType mime_type; |
| 100 | 1 | hiro | |
| 101 | 1 | hiro | gchar *content_type; |
| 102 | 1 | hiro | gchar *charset; |
| 103 | 1 | hiro | gchar *name; |
| 104 | 1 | hiro | gchar *boundary; |
| 105 | 1 | hiro | |
| 106 | 1 | hiro | gchar *content_disposition; |
| 107 | 1 | hiro | gchar *filename; |
| 108 | 1 | hiro | |
| 109 | 1 | hiro | glong fpos; |
| 110 | 1 | hiro | guint size; |
| 111 | 427 | hiro | guint content_size; |
| 112 | 1 | hiro | |
| 113 | 1 | hiro | MimeInfo *main; |
| 114 | 1 | hiro | MimeInfo *sub; |
| 115 | 1 | hiro | |
| 116 | 1 | hiro | MimeInfo *next; |
| 117 | 1 | hiro | MimeInfo *parent; |
| 118 | 1 | hiro | MimeInfo *children; |
| 119 | 1 | hiro | |
| 120 | 1 | hiro | MimeInfo *plaintext; |
| 121 | 1 | hiro | gchar *sigstatus; |
| 122 | 1 | hiro | gchar *sigstatus_full; |
| 123 | 1 | hiro | |
| 124 | 1 | hiro | gint level; |
| 125 | 1 | hiro | }; |
| 126 | 1 | hiro | |
| 127 | 1 | hiro | #define IS_BOUNDARY(s, bnd, len) \
|
| 128 | 1 | hiro | (bnd && s[0] == '-' && s[1] == '-' && !strncmp(s + 2, bnd, len)) |
| 129 | 1 | hiro | |
| 130 | 1 | hiro | /* MimeInfo handling */
|
| 131 | 1 | hiro | |
| 132 | 1 | hiro | MimeInfo *procmime_mimeinfo_new (void);
|
| 133 | 1 | hiro | void procmime_mimeinfo_free_all (MimeInfo *mimeinfo);
|
| 134 | 1 | hiro | |
| 135 | 1 | hiro | MimeInfo *procmime_mimeinfo_insert (MimeInfo *parent, |
| 136 | 1 | hiro | MimeInfo *mimeinfo); |
| 137 | 1325 | hiro | #if 0
|
| 138 | 1 | hiro | void procmime_mimeinfo_replace (MimeInfo *old, |
| 139 | 1 | hiro | MimeInfo *new); |
| 140 | 1325 | hiro | #endif |
| 141 | 1 | hiro | |
| 142 | 1 | hiro | MimeInfo *procmime_mimeinfo_next (MimeInfo *mimeinfo); |
| 143 | 1 | hiro | |
| 144 | 1 | hiro | MimeInfo *procmime_scan_message (MsgInfo *msginfo); |
| 145 | 1 | hiro | void procmime_scan_multipart_message (MimeInfo *mimeinfo,
|
| 146 | 1 | hiro | FILE *fp); |
| 147 | 1 | hiro | |
| 148 | 1 | hiro | /* scan headers */
|
| 149 | 1 | hiro | |
| 150 | 1 | hiro | void procmime_scan_encoding (MimeInfo *mimeinfo,
|
| 151 | 1 | hiro | const gchar *encoding);
|
| 152 | 1 | hiro | void procmime_scan_content_type (MimeInfo *mimeinfo,
|
| 153 | 1 | hiro | const gchar *content_type);
|
| 154 | 144 | hiro | void procmime_scan_content_type_str (const gchar *content_type, |
| 155 | 144 | hiro | gchar **mime_type, |
| 156 | 144 | hiro | gchar **charset, |
| 157 | 144 | hiro | gchar **name, |
| 158 | 144 | hiro | gchar **boundary); |
| 159 | 1 | hiro | void procmime_scan_content_disposition (MimeInfo *mimeinfo,
|
| 160 | 1 | hiro | const gchar *content_disposition);
|
| 161 | 1 | hiro | MimeInfo *procmime_scan_mime_header (FILE *fp); |
| 162 | 1 | hiro | |
| 163 | 1 | hiro | FILE *procmime_decode_content (FILE *outfp, |
| 164 | 1 | hiro | FILE *infp, |
| 165 | 1 | hiro | MimeInfo *mimeinfo); |
| 166 | 1 | hiro | gint procmime_get_part (const gchar *outfile,
|
| 167 | 1 | hiro | const gchar *infile,
|
| 168 | 1 | hiro | MimeInfo *mimeinfo); |
| 169 | 97 | hiro | gint procmime_get_part_fp (const gchar *outfile,
|
| 170 | 97 | hiro | FILE *infp, |
| 171 | 97 | hiro | MimeInfo *mimeinfo); |
| 172 | 601 | hiro | gint procmime_get_all_parts (const gchar *dir,
|
| 173 | 601 | hiro | const gchar *infile,
|
| 174 | 601 | hiro | MimeInfo *mimeinfo); |
| 175 | 1 | hiro | FILE *procmime_get_text_content (MimeInfo *mimeinfo, |
| 176 | 129 | hiro | FILE *infp, |
| 177 | 129 | hiro | const gchar *encoding);
|
| 178 | 129 | hiro | FILE *procmime_get_first_text_content (MsgInfo *msginfo, |
| 179 | 129 | hiro | const gchar *encoding);
|
| 180 | 1 | hiro | |
| 181 | 1 | hiro | gboolean procmime_find_string_part (MimeInfo *mimeinfo, |
| 182 | 1 | hiro | const gchar *filename,
|
| 183 | 1 | hiro | const gchar *str,
|
| 184 | 1 | hiro | StrFindFunc find_func); |
| 185 | 1 | hiro | gboolean procmime_find_string (MsgInfo *msginfo, |
| 186 | 1 | hiro | const gchar *str,
|
| 187 | 1 | hiro | StrFindFunc find_func); |
| 188 | 1 | hiro | |
| 189 | 162 | hiro | gchar *procmime_get_part_file_name (MimeInfo *mimeinfo); |
| 190 | 1 | hiro | gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo); |
| 191 | 1 | hiro | |
| 192 | 1 | hiro | ContentType procmime_scan_mime_type (const gchar *mime_type);
|
| 193 | 1 | hiro | gchar *procmime_get_mime_type (const gchar *filename);
|
| 194 | 1 | hiro | |
| 195 | 1032 | hiro | gint procmime_execute_open_file (const gchar *file,
|
| 196 | 1032 | hiro | const gchar *mime_type);
|
| 197 | 1032 | hiro | |
| 198 | 1 | hiro | EncodingType procmime_get_encoding_for_charset (const gchar *charset);
|
| 199 | 1 | hiro | EncodingType procmime_get_encoding_for_text_file(const gchar *file);
|
| 200 | 1693 | hiro | EncodingType procmime_get_encoding_for_str (const gchar *str);
|
| 201 | 1 | hiro | const gchar *procmime_get_encoding_str (EncodingType encoding);
|
| 202 | 1 | hiro | |
| 203 | 1 | hiro | #endif /* __PROCMIME_H__ */ |