1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* 3 * Pan - A Newsreader for Gtk+ 4 * Copyright (C) 2002-2006 Charles Kerr <charles@rebelbase.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; version 2 of the License. 9 * 10 * This program 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 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef _UtilMime_h_ 21 #define _UtilMime_h_ 22 23 #include <vector> 24 #include <glib.h> 25 #include <gmime/gmime-filter.h> 26 #include <gmime/gmime-stream.h> 27 #include <gmime/gmime-message.h> 28 #include <pan/general/string-view.h> 29 #include <pan/usenet-utils/gpg.h> 30 31 /*** 32 **** YENC 33 ***/ 34 35 #define YENC_MARKER_BEGIN "=ybegin" 36 #define YENC_MARKER_BEGIN_LEN 7 37 #define YENC_MARKER_PART "=ypart" 38 #define YENC_MARKER_PART_LEN 6 39 #define YENC_MARKER_END "=yend" 40 #define YENC_MARKER_END_LEN 5 41 #define YENC_TAG_PART " part=" 42 #define YENC_TAG_LINE " line=" 43 #define YENC_TAG_SIZE " size=" 44 #define YENC_TAG_NAME " name=" 45 #define YENC_TAG_BEGIN " begin=" 46 #define YENC_TAG_END " end=" 47 #define YENC_TAG_PCRC32 " pcrc32=" 48 #define YENC_TAG_CRC32 " crc32=" 49 #define YENC_FULL_LINE_LEN 256 50 #define YENC_HALF_LINE_LEN 128 51 #define YENC_ESC_NULL "=@" 52 #define YENC_ESC_TAB "=I" 53 #define YENC_ESC_LF "=J" 54 #define YENC_ESC_CR "=M" 55 #define YENC_ESC_ESC "={" 56 #define YENC_SHIFT 42 57 #define YENC_QUOTE_SHIFT 64 58 59 #define NEEDS_DECODING(encoding) ((encoding == GMIME_CONTENT_ENCODING_BASE64) || \ 60 (encoding == GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE)) 61 62 namespace pan 63 { 64 65 #ifdef HAVE_GMIME_CRYPTO 66 GMimeMessage* message_add_signed_part (const std::string& uid, const std::string& body_str, GMimeMessage* body); 67 bool gpg_encrypt (const std::string& uid, const std::string& body_str, GMimeMessage* body, GPtrArray* rcp, bool sign); 68 bool gpg_verify_mps (GMimeObject*, GPGDecErr&); 69 #endif 70 /** 71 * Utilities to build and parse GMimeMessages. 72 * 73 * Most of this nastiness is to handle Usenet's use of chainging together 74 * multiple articles as parts of a whole. This code tries to build 75 * a multipart GMimeMessage from multiple posts when necessary, and to 76 * also handle Usenet's loose standards for uu/yenc by checking each line 77 * to separate the encoded stuff from text. 78 */ 79 struct mime 80 { 81 #ifdef HAVE_GMIME_CRYPTO 82 static GMimeMessage * 83 construct_message (GMimeStream ** istreams, 84 int qty, 85 GPGDecErr &); 86 #else 87 static GMimeMessage * 88 construct_message (GMimeStream ** istreams, 89 int qty); 90 #endif 91 static const char * 92 get_charset (GMimeMessage * message); 93 94 static void 95 guess_part_type_from_filename (const char * filename, 96 const char ** setme_type, 97 const char ** setme_subtype); 98 99 static void 100 remove_multipart_from_subject (const StringView & subject, 101 std::string & setme); 102 103 static void 104 remove_multipart_part_from_subject (const StringView & subject, 105 std::string & setme); 106 107 }; 108 109 char *pan_g_mime_message_get_body (GMimeMessage *message, gboolean *is_html); 110 #ifdef HAVE_GMIME_30 111 void pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeAddressType type, const char *string); 112 #else 113 void pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeRecipientType type, const char *string); 114 #endif 115 std::string pan_g_mime_message_set_message_id (GMimeMessage *msg, const char *mid); 116 117 extern iconv_t conv; 118 extern bool iconv_inited; 119 120 char * __g_mime_iconv_strndup (iconv_t cd, const char *str, size_t n, const char* charset=0); 121 122 static char * __g_mime_iconv_strdup (iconv_t cd, const char *str, const char* charset=0) 123 { 124 return __g_mime_iconv_strndup(cd, str, strlen(str), charset); 125 } 126 127 } 128 129 130 131 #endif 132