KMIME Library
kmime_header_parsing.h
00001 /* -*- c++ -*- 00002 kmime_header_parsing.h 00003 00004 KMime, the KDE Internet mail/usenet news message library. 00005 Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef __KMIME_HEADER_PARSING_H__ 00024 #define __KMIME_HEADER_PARSING_H__ 00025 00026 #include <QtCore/QString> 00027 #include <QtCore/QPair> 00028 00029 #include <kdatetime.h> 00030 00031 #include "kmime_export.h" 00032 00033 template <typename K, typename V> class QMap; 00034 class QStringList; 00035 00036 namespace KMime { 00037 00038 namespace Headers { 00039 class Base; 00040 } 00041 00042 namespace Types { 00043 00044 // for when we can't make up our mind what to use... 00045 // FIXME: Remove this thing, we should _always_ know wether we are handling a byte array or a string. 00046 // In most places where this is used, it should simply be replaced by QByteArray 00047 struct KMIME_EXPORT QStringOrQPair { 00048 QStringOrQPair() : qstring(), qpair( 0, 0 ) {} 00049 QString qstring; 00050 QPair<const char*,int> qpair; 00051 }; 00052 00053 struct KMIME_EXPORT AddrSpec { 00054 QString asString() const; 00056 QString asPrettyString() const; 00057 bool isEmpty() const; 00058 QString localPart; 00059 QString domain; 00060 }; 00061 typedef QList<AddrSpec> AddrSpecList; 00062 00067 class KMIME_EXPORT Mailbox 00068 { 00069 public: 00070 typedef QList<Mailbox> List; 00071 00076 QByteArray address() const; 00077 00078 AddrSpec addrSpec() const; 00079 00083 QString name() const; 00084 00088 void setAddress( const AddrSpec &addr ); 00089 00093 void setAddress( const QByteArray &addr ); 00094 00098 void setName( const QString &name ); 00099 00103 void setNameFrom7Bit( const QByteArray &name, 00104 const QByteArray &defaultCharset = QByteArray() ); 00105 00109 bool hasAddress() const; 00110 00114 bool hasName() const; 00115 00121 QString prettyAddress() const; 00122 00127 //AK_REVIEW: remove this enum 00128 enum Quoting { 00129 QuoteNever, 00130 00131 00132 QuoteWhenNecessary, 00133 00134 QuoteAlways 00135 }; 00136 00142 // TODO: KDE5: BIC: remove other prettyAddress() overload, and make it None the default 00143 // parameter here 00144 //AK_REVIEW: replace by 'QString quotedAddress() const' 00145 QString prettyAddress( Quoting quoting ) const; 00146 00150 void fromUnicodeString( const QString &s ); 00151 00155 void from7BitString( const QByteArray &s ); 00156 00162 QByteArray as7BitString( const QByteArray &encCharset ) const; 00163 00164 private: 00165 QString mDisplayName; 00166 AddrSpec mAddrSpec; 00167 }; 00168 00169 typedef QList<Mailbox> MailboxList; 00170 00171 struct KMIME_EXPORT Address { 00172 QString displayName; 00173 MailboxList mailboxList; 00174 }; 00175 typedef QList<Address> AddressList; 00176 00177 } // namespace KMime::Types 00178 00179 namespace HeaderParsing { 00180 00196 KMIME_EXPORT bool parseEncodedWord( const char* &scursor, 00197 const char * const send, 00198 QString &result, QByteArray &language, 00199 QByteArray &usedCS, const QByteArray &defaultCS = QByteArray(), 00200 bool forceCS = false ); 00201 00202 // 00203 // The parsing squad: 00204 // 00205 00208 KMIME_EXPORT bool parseAtom( const char* &scursor, const char * const send, 00209 QString &result, bool allow8Bit=false ); 00210 00211 KMIME_EXPORT bool parseAtom( const char* &scursor, const char * const send, 00212 QPair<const char*,int> &result, 00213 bool allow8Bit=false ); 00214 00217 KMIME_EXPORT bool parseToken( const char* &scursor, const char * const send, 00218 QString &result, bool allow8Bit=false ); 00219 00220 KMIME_EXPORT bool parseToken( const char* &scursor, const char * const send, 00221 QPair<const char*,int> &result, 00222 bool allow8Bit=false ); 00223 00225 KMIME_EXPORT bool parseGenericQuotedString( const char* &scursor, 00226 const char* const send, 00227 QString &result, bool isCRLF, 00228 const char openChar='"', 00229 const char closeChar='"' ); 00230 00232 KMIME_EXPORT bool parseComment( const char* &scursor, const char * const send, 00233 QString &result, bool isCRLF=false, 00234 bool reallySave=true ); 00235 00251 KMIME_EXPORT bool parsePhrase( const char* &scursor, const char * const send, 00252 QString &result, bool isCRLF=false ); 00253 00266 KMIME_EXPORT bool parseDotAtom( const char* &scursor, const char * const send, 00267 QString &result, bool isCRLF=false ); 00268 00283 KMIME_EXPORT void eatCFWS( const char* &scursor, const char * const send, 00284 bool isCRLF ); 00285 00286 KMIME_EXPORT bool parseDomain( const char* &scursor, const char * const send, 00287 QString &result, bool isCRLF=false ); 00288 00289 KMIME_EXPORT bool parseObsRoute( const char* &scursor, const char * const send, 00290 QStringList &result, bool isCRLF=false, 00291 bool save=false ); 00292 00293 KMIME_EXPORT bool parseAddrSpec( const char* &scursor, const char * const send, 00294 Types::AddrSpec &result, bool isCRLF=false ); 00295 00296 KMIME_EXPORT bool parseAngleAddr( const char* &scursor, const char * const send, 00297 Types::AddrSpec &result, bool isCRLF=false ); 00298 00315 KMIME_EXPORT bool parseMailbox( const char* &scursor, const char * const send, 00316 Types::Mailbox &result, bool isCRLF=false ); 00317 00318 KMIME_EXPORT bool parseGroup( const char* &scursor, const char * const send, 00319 Types::Address &result, bool isCRLF=false ); 00320 00321 KMIME_EXPORT bool parseAddress( const char* &scursor, const char * const send, 00322 Types::Address &result, bool isCRLF=false ); 00323 00324 KMIME_EXPORT bool parseAddressList( const char* &scursor, 00325 const char * const send, 00326 Types::AddressList &result, 00327 bool isCRLF=false ); 00328 00329 KMIME_EXPORT bool parseParameter( const char* &scursor, const char * const send, 00330 QPair<QString,Types::QStringOrQPair> &result, 00331 bool isCRLF=false ); 00332 00333 KMIME_EXPORT bool parseParameterList( const char* &scursor, 00334 const char * const send, 00335 QMap<QString,QString> &result, 00336 bool isCRLF=false ); 00337 00338 KMIME_EXPORT bool parseRawParameterList( const char* &scursor, 00339 const char * const send, 00340 QMap<QString,Types::QStringOrQPair> &result, 00341 bool isCRLF=false ); 00342 00348 KMIME_EXPORT bool parseParameterListWithCharset( const char* &scursor, 00349 const char * const send, 00350 QMap<QString,QString> &result, 00351 QByteArray& charset, bool isCRLF=false ); 00352 00360 KMIME_EXPORT int parseDigits( const char* &scursor, const char* const send, int &result ); 00361 00362 KMIME_EXPORT bool parseTime( const char* &scursor, const char * const send, 00363 int &hour, int &min, int &sec, 00364 long int &secsEastOfGMT, 00365 bool &timeZoneKnown, bool isCRLF=false ); 00366 00367 KMIME_EXPORT bool parseDateTime( const char* &scursor, const char * const send, 00368 KDateTime &result, bool isCRLF=false ); 00369 00376 KMIME_EXPORT KMime::Headers::Base *extractFirstHeader( QByteArray &head ); 00377 00388 KMIME_EXPORT void extractHeaderAndBody( const QByteArray &content, 00389 QByteArray &header, QByteArray &body ); 00390 00391 00392 } // namespace HeaderParsing 00393 00394 } // namespace KMime 00395 00396 #endif // __KMIME_HEADER_PARSING_H__ 00397