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