Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

utils.h

Go to the documentation of this file.
00001 /*
00002  * XetPan: a libEtPan! based Mail User Agent
00003  * Copyright (C) 2002-2003 Melvin Hadasht
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef UTILS_H
00021 #define UTILS_H
00022 
00023 #include <stdlib.h> /* size_t */
00024 #include <time.h>   /* struct tm */
00025 
00026 #include <libetpan.h> /* struct mailimf_date_time */
00027 
00028 #include "uudeview.h" /* uuprogress */
00029 
00030 #define XEP_UTILS_SIZE_BUF_MAX 6
00031 
00032 typedef enum
00033   {
00034     XEP_Q_ENCODING,   
00035     XEP_B_ENCODING,   
00036     XEP_AUTO_ENCODING 
00037   } XePUtilsEncodingType;
00038 
00039 typedef struct XePUtilsFormat_s XePUtilsFormat;
00040 
00044 struct XePUtilsFormat_s
00045 {
00046   const char *string; 
00047   const char token;   
00048 };
00049 
00050 typedef enum
00051   {
00052     XEP_OPENPGP_NONE = 0,
00053     XEP_OPENPGP_SIGNED = 1 << 0,
00054     XEP_OPENPGP_ENCRYPTED = 1 << 1
00055   } XePUtilsOpenPGPType;
00056 
00057 typedef enum
00058   {
00059     XEP_INLINED_DATA_NONE,
00060     XEP_INLINED_DATA_UUENCODED,
00061     XEP_INLINED_DATA_YENCODED,
00062     XEP_INLINED_DATA_YENCODED2,
00063     XEP_INLINED_DATA_BINHEX,
00064     XEP_INLINED_DATA_TEXT,
00065     XEP_INLINED_DATA_CLEARSIGNED_TEXT,
00066     XEP_INLINED_DATA_ASCII_ARMORED_TEXT
00067   } XePUtilsInlinedDataType;
00068 
00069 /* utils.c charset global variable depend on the ordering of this enum */
00070 typedef enum
00071   {
00072     XEP_CHARSET_0,
00073     XEP_CHARSET_BIG5,
00074     XEP_CHARSET_EUC_JP,
00075     XEP_CHARSET_EUC_KR,
00076     XEP_CHARSET_EUC_TW,
00077     XEP_CHARSET_GB2312,
00078     XEP_CHARSET_ISIRI_3342,
00079     XEP_CHARSET_ISO_2022_CN,
00080     XEP_CHARSET_ISO_2022_CN_EXT,
00081     XEP_CHARSET_ISO_2022_JP,
00082     XEP_CHARSET_ISO_2022_JP_2,
00083     XEP_CHARSET_ISO_2022_KR,
00084     XEP_CHARSET_ISO_8859_1,
00085     XEP_CHARSET_ISO_8859_10,
00086     XEP_CHARSET_ISO_8859_11,
00087     XEP_CHARSET_ISO_8859_13,
00088     XEP_CHARSET_ISO_8859_14,
00089     XEP_CHARSET_ISO_8859_15,
00090     XEP_CHARSET_ISO_8859_16,
00091     XEP_CHARSET_ISO_8859_2,
00092     XEP_CHARSET_ISO_8859_3,
00093     XEP_CHARSET_ISO_8859_4,
00094     XEP_CHARSET_ISO_8859_5,
00095     XEP_CHARSET_ISO_8859_6,
00096     XEP_CHARSET_ISO_8859_7,
00097     XEP_CHARSET_ISO_8859_8,
00098     XEP_CHARSET_ISO_8859_8_I,
00099     XEP_CHARSET_ISO_8859_9,
00100     XEP_CHARSET_KOI8_R,
00101     XEP_CHARSET_KOI8_U,
00102     XEP_CHARSET_MAC_CYRILLIC,
00103     XEP_CHARSET_SHIFT_JIS,
00104     XEP_CHARSET_TIS_620,
00105     XEP_CHARSET_UTF8,
00106     XEP_CHARSET_VISCII,
00107     XEP_CHARSET_WINDOWS_1250,
00108     XEP_CHARSET_WINDOWS_1251,
00109     XEP_CHARSET_WINDOWS_1254,
00110     XEP_CHARSET_WINDOWS_1255,
00111     XEP_CHARSET_WINDOWS_1256,
00112     XEP_CHARSET_WINDOWS_1258
00113   } XePUtilsCharset;
00114 
00115 typedef struct XePUtilsInlinedFile_s XePUtilsInlinedFile;
00116 
00120 struct XePUtilsInlinedFile_s
00121 {
00122   /* Common members with XePUtilsInlinedText and XePUtilsInlinedAny */
00123   XePUtilsInlinedDataType type;
00124   char *data;   
00125   size_t size;  
00126   const char *start;  
00127   void *extra;  
00129   /* Specific member */
00130   char *filename; 
00131 };
00132 
00133 typedef struct XePUtilsInlinedText_s XePUtilsInlinedText;
00134 
00137 struct XePUtilsInlinedText_s
00138 {
00139   /* Common members with XePUtilsInlinedFile and XePUtilsInlinedAny */
00140   XePUtilsInlinedDataType type;
00141   char *data;   
00142   size_t size;  
00143   const char *start;  
00144   void *extra;  
00146   /* Specific member */
00147   char *plain_text; 
00148   size_t plain_size;
00149   int privacy_sig_status;
00150   int privacy_enc_status;
00151 };
00152 
00153 typedef struct XePUtilsInlinedDataAny_s XePUtilsInlinedDataAny;
00154 
00155 struct XePUtilsInlinedDataAny_s
00156 {
00157   /* Common members with XePUtilsInlinedText and XePUtilsInlinedFile */
00158   XePUtilsInlinedDataType type;
00159   char *data;   
00160   size_t size;  
00161   const char *start;  
00162   void *extra;  
00163 };
00164 
00165 typedef union XePUtilsInlinedData_u XePUtilsInlinedData;
00166 
00167 union XePUtilsInlinedData_u
00168 {
00169   XePUtilsInlinedDataAny any;
00170   XePUtilsInlinedText text;
00171   XePUtilsInlinedFile file;
00172 };
00173 
00174   
00175 typedef struct XePUtilsPair_s XePUtilsPair;
00176 
00178 struct XePUtilsPair_s
00179 {
00180   void *name;
00181   void *value;
00182 };
00183 
00184 typedef struct XePUtilsTriplet_s XePUtilsTriplet;
00185 
00187 struct XePUtilsTriplet_s
00188 {
00189   void *data1;
00190   void *data2;
00191   void *data3;
00192 };
00193 
00195 typedef struct XePUtilsCharsetMapping_s XePUtilsCharsetMapping;
00196 struct  XePUtilsCharsetMapping_s
00197 {
00198   XePUtilsCharset charset_id;
00199   const char *charset;
00200 };
00201 
00202 extern XePUtilsCharsetMapping xetpan_charsets[];
00203 
00212 char *
00213 a_Utils_printf(char *template, XePUtilsFormat *format);
00214 
00220 char *
00221 a_Utils_append(char *dest, ...);
00222 
00229 void
00230 a_Utils_string_unfold(char *string);
00231 
00239 char *
00240 a_Utils_magic_data_mime_type(const char *data, size_t size);
00241 
00249 char *
00250 a_Utils_magic_file_mime_type(const char *filename);
00251 
00258 char *
00259 a_Utils_magic_get_charset(const char *magic_mime_type);
00260 
00268 void
00269 a_Utils_format_size(char *buffer, size_t size);
00270 
00277 int
00278 a_Utils_write(int fd, const char *data, size_t size);
00279 
00288 int
00289 a_Utils_read(int fd, char **data, size_t *size);
00290 
00291 
00299 char *
00300 a_Utils_save_temp(const char *data, size_t size);
00301 
00308 int
00309 a_Utils_load_file(const char *filename, char **data, size_t *size);
00310 
00317 int
00318 a_Utils_file_backup(const char *filename);
00319 
00320 XePUtilsInlinedData *
00321 a_Utils_inlined_text_new(XePUtilsInlinedDataType type,
00322                          const char *data,
00323                          size_t size,
00324                          const char *plain_text,
00325                          size_t plain_size,
00326                          int privacy_sig_status,
00327                          int privacy_enc_status,
00328                          void *extra);
00329 
00339 XePUtilsInlinedData *
00340 a_Utils_inlined_file_new(XePUtilsInlinedDataType type,
00341                          const char *data, 
00342                          size_t size, 
00343                          const char *filename, 
00344                          void *extra);
00348 void
00349 a_Utils_inlined_list_free(clist *inlined_list);
00350 
00354 void
00355 a_Utils_inlined_data_free(XePUtilsInlinedData *inlined_data);
00356 
00362 int
00363 a_Utils_inlined_file_decode_as(XePUtilsInlinedData *inlined_data,
00364                                const char *save_as);
00365 
00375 char *
00376 a_Utils_uulib_decode_file(const char *filename,
00377                           void (*msg_cb)(void *adata, 
00378                                          const char *msg,
00379                                          int msg_type),
00380                           void (*busy_cb)(void *adata,
00381                                           uuprogress *aprogress),
00382                           void *data);
00383 
00392 XePUtilsInlinedData *
00393 a_Utils_data_has_uuencoded(const char *data, size_t size);
00394 
00402 XePUtilsInlinedData *
00403 a_Utils_data_has_yencoded(const char *data, size_t size);
00404 
00416 XePUtilsInlinedData *
00417 a_Utils_data_has_yencoded2(const char *data, size_t size);
00418 
00429 XePUtilsInlinedData *
00430 a_Utils_data_has_binhex(const char *data, size_t size);
00431 
00438 int
00439 a_Utils_orig_date_to_localtime(struct mailimf_date_time *date_time,
00440                                struct tm *local_tm);
00441 
00446 void *
00447 a_Utils_memmem(const void *haystack, 
00448                size_t haystack_len, 
00449                const void *needle,
00450                size_t needle_len);
00451 
00460 int
00461 a_Utils_quote_text_for_reply(const char *text,
00462                              size_t text_size,
00463                              const char *source_charset,
00464                              char **quoted_text);
00465 
00473 char *
00474 a_Utils_create_quoted_printable(const char *text,
00475                                 const char *text_charset);
00476 
00481 clist *
00482 a_Utils_parse_mailto(const char *mailto);
00483 
00501 int
00502 a_Utils_exec_cmd(char *cmd, int fd_in, int fd_out, int fd_err, int *fd_mon, 
00503                  pid_t *_pid, int sync);
00504 
00505 
00520 char *
00521 a_Utils_basename(const char* path);
00522 
00532 char *
00533 a_Utils_magic_get_bare_mime_type(const char *mime_type);
00534 
00552 void
00553 a_Utils_to_b_encoding(const char *s, size_t *is, char *t, size_t *it);
00554 
00582 void
00583 a_Utils_to_q_encoding(const char *s, size_t *is, char *t, size_t *it, 
00584                       int is_phrase,
00585                       int is_comment);
00586 
00605 char *
00606 a_Utils_encode_8bit_header(const char *text, 
00607                            const char *charset,
00608                            XePUtilsEncodingType encoding, 
00609                            int is_phrase, 
00610                            int is_comment);
00611 
00623 char *
00624 a_Utils_encode_8bit_subject(const char *subject, 
00625                             const char *charset, 
00626                             XePUtilsEncodingType encoding);
00627 
00635 int
00636 a_Utils_has_8bit(const char *text, size_t size);
00637 
00646 clist *
00647 a_Utils_parse_body_text(const char *text, size_t size);
00648 
00653 const char *
00654 a_Utils_inlined_data_type_as_string(XePUtilsInlinedDataType type);
00655 
00665 int
00666 a_Utils_text_new_copy_with_rfc2822_lines(const char *text, 
00667                                          size_t size,
00668                                          char **rfc2822_text,
00669                                          size_t *rfc2822_size);
00670 #endif

Generated on Wed Oct 22 15:50:45 2003 for XetPan by doxygen 1.3.2