mimeheader.h
00001 /*************************************************************************** 00002 mimeheader.h - description 00003 ------------------- 00004 begin : Fri Oct 20 2000 00005 copyright : (C) 2000 by Sven Carstens 00006 email : s.carstens@gmx.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef MIMEHEADER_H 00019 #define MIMEHEADER_H 00020 00021 #include <tqptrlist.h> 00022 #include <tqdict.h> 00023 00024 #include "mimehdrline.h" 00025 #include "mimeio.h" 00026 #include "rfcdecoder.h" 00027 00032 class mimeHeader 00033 { 00034 public: 00035 mimeHeader (); 00036 virtual ~ mimeHeader (); 00037 00038 virtual void addHdrLine (mimeHdrLine *); 00039 virtual void outputHeader (mimeIO &); 00040 virtual void outputPart (mimeIO &); 00041 00042 00043 TQCString outputParameter (TQDict < TQString > *); 00044 00045 int parsePart (mimeIO &, const TQString&); 00046 int parseBody (mimeIO &, TQCString &, const TQString&, bool mbox = false); 00047 00048 // parse a header. returns true if it had a leading 'From ' line 00049 bool parseHeader (mimeIO &); 00050 00051 TQString getDispositionParm (const TQCString&); 00052 void setDispositionParm (const TQCString&, const TQString&); 00053 TQDictIterator < TQString > getDispositionIterator (); 00054 00055 TQString getTypeParm (const TQCString&); 00056 void setTypeParm (const TQCString&, const TQString&); 00057 TQDictIterator < TQString > getTypeIterator (); 00058 00059 // recursively serialize all important contents to the TQDataStream 00060 void serialize(TQDataStream& stream); 00061 00062 const TQCString& getType () 00063 { 00064 return contentType; 00065 } 00066 void setType (const TQCString & _str) 00067 { 00068 contentType = _str; 00069 } 00070 00071 const TQCString& getDescription () 00072 { 00073 return _contentDescription; 00074 } 00075 void setDescription (const TQCString & _str) 00076 { 00077 _contentDescription = _str; 00078 } 00079 00080 TQCString getDisposition () 00081 { 00082 return _contentDisposition; 00083 } 00084 void setDisposition (const TQCString & _str) 00085 { 00086 _contentDisposition = _str; 00087 } 00088 00089 TQCString getEncoding () 00090 { 00091 return contentEncoding; 00092 } 00093 void setEncoding (const TQCString & _str) 00094 { 00095 contentEncoding = _str; 00096 } 00097 00098 TQCString getMD5 () 00099 { 00100 return contentMD5; 00101 } 00102 void setMD5 (const TQCString & _str) 00103 { 00104 contentMD5 = _str; 00105 } 00106 00107 TQCString getID () 00108 { 00109 return contentID; 00110 } 00111 void setID (const TQCString & _str) 00112 { 00113 contentID = _str; 00114 } 00115 00116 unsigned long getLength () 00117 { 00118 return contentLength; 00119 } 00120 void setLength (unsigned long _len) 00121 { 00122 contentLength = _len; 00123 } 00124 00125 const TQString & getPartSpecifier () 00126 { 00127 return partSpecifier; 00128 } 00129 void setPartSpecifier (const TQString & _str) 00130 { 00131 partSpecifier = _str; 00132 } 00133 00134 TQPtrListIterator < mimeHdrLine > getOriginalIterator (); 00135 TQPtrListIterator < mimeHdrLine > getAdditionalIterator (); 00136 void setContent (const TQCString &aContent) 00137 { 00138 mimeContent = aContent; 00139 } 00140 TQCString getContent () 00141 { 00142 return mimeContent; 00143 } 00144 00145 TQCString getBody () 00146 { 00147 return preMultipartBody + postMultipartBody; 00148 } 00149 TQCString getPreBody () 00150 { 00151 return preMultipartBody; 00152 } 00153 void setPreBody (TQCString & inBody) 00154 { 00155 preMultipartBody = inBody; 00156 } 00157 00158 TQCString getPostBody () 00159 { 00160 return postMultipartBody; 00161 } 00162 void setPostBody (TQCString & inBody) 00163 { 00164 postMultipartBody = inBody; 00165 contentLength = inBody.length (); 00166 } 00167 00168 mimeHeader *getNestedMessage () 00169 { 00170 return nestedMessage; 00171 } 00172 void setNestedMessage (mimeHeader * inPart, bool destroy = true) 00173 { 00174 if (nestedMessage && destroy) 00175 delete nestedMessage; 00176 nestedMessage = inPart; 00177 } 00178 00179 // mimeHeader *getNestedPart() { return nestedPart; }; 00180 void addNestedPart (mimeHeader * inPart) 00181 { 00182 nestedParts.append (inPart); 00183 } 00184 TQPtrListIterator < mimeHeader > getNestedIterator () 00185 { 00186 return TQPtrListIterator < mimeHeader > (nestedParts); 00187 } 00188 00189 // clears all parts and deletes them from memory 00190 void clearNestedParts () 00191 { 00192 nestedParts.clear (); 00193 } 00194 00195 // clear all parameters to content-type 00196 void clearTypeParameters () 00197 { 00198 typeList.clear (); 00199 } 00200 00201 // clear all parameters to content-disposition 00202 void clearDispositionParameters () 00203 { 00204 dispositionList.clear (); 00205 } 00206 00207 // return the specified body part or NULL 00208 mimeHeader *bodyPart (const TQString &); 00209 00210 #ifdef KMAIL_COMPATIBLE 00211 ulong msgSize () 00212 { 00213 return contentLength; 00214 } 00215 uint numBodyParts () 00216 { 00217 return nestedParts.count (); 00218 } 00219 mimeHeader *bodyPart (int which, mimeHeader ** ret = NULL) 00220 { 00221 if (ret) 00222 (*ret) = nestedParts.at (which); 00223 return nestedParts.at (which); 00224 } 00225 void write (const TQString &) 00226 { 00227 } 00228 TQString typeStr () 00229 { 00230 return TQString (contentType.left (contentType.find ('/'))); 00231 } 00232 void setTypeStr (const TQString & _str) 00233 { 00234 contentType = TQCString (_str.latin1 ()) + "/" + subtypeStr ().latin1 (); 00235 } 00236 TQString subtypeStr () 00237 { 00238 return TQString (contentType. 00239 right (contentType.length () - contentType.find ('/') - 00240 1)); 00241 } 00242 void setSubtypeStr (const TQString & _str) 00243 { 00244 contentType = TQCString (typeStr ().latin1 ()) + "/" + _str.latin1 (); 00245 } 00246 TQString cteStr () 00247 { 00248 return TQString (getEncoding ()); 00249 } 00250 void setCteStr (const TQString & _str) 00251 { 00252 setEncoding (_str.latin1 ()); 00253 } 00254 TQString contentDisposition () 00255 { 00256 return TQString (_contentDisposition); 00257 } 00258 TQString body () 00259 { 00260 return TQString (postMultipartBody); 00261 } 00262 TQString charset () 00263 { 00264 return getTypeParm ("charset"); 00265 } 00266 TQString bodyDecoded (); 00267 void setBodyEncoded (const TQByteArray &); 00268 void setBodyEncodedBinary (const TQByteArray &); 00269 TQByteArray bodyDecodedBinary (); 00270 TQString name () 00271 { 00272 return TQString (getTypeParm ("name")); 00273 } 00274 void setName (const TQString & _str) 00275 { 00276 setTypeParm ("name", _str); 00277 } 00278 TQString fileName () 00279 { 00280 return TQString (getDispositionParm ("filename")); 00281 } 00282 TQString contentDescription () 00283 { 00284 return TQString (rfcDecoder::decodeRFC2047String (_contentDescription)); 00285 } 00286 void setContentDescription (const TQString & _str) 00287 { 00288 _contentDescription = rfcDecoder::encodeRFC2047String (_str).latin1 (); 00289 } 00290 TQString msgIdMD5 () 00291 { 00292 return TQString (contentMD5); 00293 } 00294 TQString iconName (); 00295 TQString magicSetType (bool aAutoDecode = true); 00296 TQString headerAsString (); 00297 ulong size () 00298 { 00299 return 0; 00300 } 00301 void fromString (const TQByteArray &) 00302 {; 00303 } 00304 void setContentDisposition (const TQString & _str) 00305 { 00306 setDisposition (_str.latin1 ()); 00307 } 00308 #endif 00309 00310 protected: 00311 static void addParameter (const TQCString&, TQDict < TQString > *); 00312 static TQString getParameter (const TQCString&, TQDict < TQString > *); 00313 static void setParameter (const TQCString&, const TQString&, TQDict < TQString > *); 00314 00315 TQPtrList < mimeHdrLine > originalHdrLines; 00316 00317 private: 00318 TQPtrList < mimeHdrLine > additionalHdrLines; 00319 TQDict < TQString > typeList; 00320 TQDict < TQString > dispositionList; 00321 TQCString contentType; 00322 TQCString _contentDisposition; 00323 TQCString contentEncoding; 00324 TQCString _contentDescription; 00325 TQCString contentID; 00326 TQCString contentMD5; 00327 unsigned long contentLength; 00328 TQCString mimeContent; 00329 TQCString preMultipartBody; 00330 TQCString postMultipartBody; 00331 mimeHeader *nestedMessage; 00332 TQPtrList < mimeHeader > nestedParts; 00333 TQString partSpecifier; 00334 00335 }; 00336 00337 #endif