Main Page | Class Hierarchy | Class List | File List | Class Members

EmailMessage.h

00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef __EmailMessage_h__
00030 #define __EmailMessage_h__
00031 
00032 #include <QStringList>
00033 #include <QByteArray>
00034 #include <QBuffer>
00035 #include <QVector>
00036 #include "GInputStream.h"
00037 #include "GBufferString.h"
00038 #include "GBufferedInputStream.h"
00039 
00040 const int MaxLineSize = 65536;
00041 
00045 
00046 class MailHeader
00047 {
00048 public:
00049 
00050          MailHeader();
00051          virtual ~MailHeader();
00052 
00056          virtual const QString& getMessageId() const;
00057 
00058          virtual const QStringList& getTo() const;
00059 
00060          virtual const QStringList& getCc() const;
00061 
00062          virtual const QStringList& getBcc() const;
00063 
00064          virtual const QString& getFrom() const;
00065 
00066          virtual const QString& getSubject() const;      
00067 
00068          virtual long getDate() const;   
00069 
00070          virtual uint getPriority() const;
00071 
00072          virtual void clear();
00073 
00074 protected:
00075 
00076         QString messageId_;
00077         QStringList recipients_;
00078         QStringList cc_;
00079         QStringList bcc_;
00080         QString sender_;
00081         QString subject_;
00082         long date_;
00083         uint priority_;
00084 };
00085 
00091 class EmailMessage 
00092         : public MailHeader
00093 {
00094 public:
00095 
00096         EmailMessage();
00097         virtual ~EmailMessage();
00098 
00102         bool open(GInputStream *stream);
00103 
00107         const QByteArray& contentType();
00108 
00112         const QString& text();
00113 
00117 
00118         size_t size() const;
00119 
00121 
00125         bool hasAttachments() const ;
00126 
00130         QStringList attachments();
00131 
00138         bool readAttachment(const QString& name, QByteArray& contents, QByteArray& contentType);
00139 
00142         void setDeleteStream( bool isDelete = true );
00143 
00146         void parseHeaderOnly( bool bOnly = true );
00147 
00148         static bool isHexString( const QByteArray &hex );
00149 
00150         // Decodes encoded text and returns unicode string
00151         static QString decodeNonAsciiText( GBufferString &text );
00152         static int encode( QByteArray &text, const GBufferString &encoding, bool bShortForm = false );
00153 
00154 protected:
00155 
00156         // Type of content body
00157         enum contenttype
00158         {
00159                 e_text          = 0xA,
00160                 e_multipart     = 0xF,
00161                 e_other         = 0xD
00162         } 
00163         enumConType_;
00164 
00165         void initParams();
00166         void init();
00167 
00168         void processParameter( GBufferString &paramText );
00169         bool parseMimeBody();
00170 
00171         bool compareNoCase( const char *ca1, const char *ca2 );
00172 
00173         void parseContentType( GBufferString &paramString );
00174         void parseFrom( GBufferString &paramString );
00175         void parseDate( GBufferString &paramString );
00176         void parseContentDisp( GBufferString &paramString, bool &bMulti, 
00177                 bool bTextEmpty, int boundaryPos, int &nameCounter );
00178         void parseAddrList( QStringList &addrList, GBufferString &line );
00179         void getExt( const QByteArray &contentType, QByteArray &extension );
00180 
00181         void addAttachment();
00182 
00183         bool isUUencoded( GBufferString &line, QByteArray &filename );
00184         void uudecode( bool extract, QByteArray &outData );
00185 
00186         GBufferedInputStream< GInputStream > readline_;
00187         GInputStream *emailStream_;
00188 
00189         // Represents one attachment
00190         struct AttachmentItem
00191         {
00192                 AttachmentItem() {}
00193                 AttachmentItem( QString Name, qint64 Pos )
00194                 {
00195                         AttachmentName = Name;
00196                         FilePos = Pos;
00197                 }
00198 
00199                 QString AttachmentName;
00200                 qint64 FilePos;
00201         };
00202 
00203         QVector< AttachmentItem > attachments_;
00204 
00205         QString text_;
00206 
00207         QByteArray boundary_;
00208         QByteArray encoding_;
00209         QByteArray retContentType_;
00210         QByteArray contentType_;
00211         QByteArray charset_;
00212         qint64 boundaryPos_;
00213         bool bAutoDelete_;
00214         bool bParseHeaderOnly_;
00215 
00216         QString attachName_;
00217         qint64 attachPos_;
00218         bool bAddAttachment_;
00219 
00220 };
00221 
00222 #endif // __EmailMessage_h__
00223 

Generated on Tue Oct 16 10:00:38 2007 for EmailParser by doxygen 1.3.4