summaryrefslogtreecommitdiff
path: root/noncore/net/mail/mailwrapper.h
Unidiff
Diffstat (limited to 'noncore/net/mail/mailwrapper.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/mailwrapper.h183
1 files changed, 183 insertions, 0 deletions
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
new file mode 100644
index 0000000..3de28a0
--- a/dev/null
+++ b/noncore/net/mail/mailwrapper.h
@@ -0,0 +1,183 @@
1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H
3
4#include <qpe/applnk.h>
5
6#include <mailmime.h>
7#include <mailimf.h>
8#include <mailsmtp.h>
9#include <mailimap.h>
10#include <mailstorage.h>
11#include <maildriver.h>
12#include <qbitarray.h>
13#include <qdatetime.h>
14
15#include "settings.h"
16
17class Attachment
18{
19public:
20 Attachment( DocLnk lnk );
21 virtual ~Attachment(){}
22 const QString getFileName()const{ return doc.file(); }
23 const QString getName()const{ return doc.name(); }
24 const QString getMimeType()const{ return doc.type(); }
25 const QPixmap getPixmap()const{ return doc.pixmap(); }
26 const int getSize()const { return size; }
27 DocLnk getDocLnk() { return doc; }
28
29protected:
30 DocLnk doc;
31 int size;
32
33};
34
35#define FLAG_ANSWERED 0
36#define FLAG_FLAGGED 1
37#define FLAG_DELETED 2
38#define FLAG_SEEN 3
39#define FLAG_DRAFT 4
40#define FLAG_RECENT 5
41
42/* a class to describe mails in a mailbox */
43class RecMail
44{
45public:
46 RecMail();
47 virtual ~RecMail(){}
48
49 const int getNumber()const{return msg_number;}
50 void setNumber(int number){msg_number=number;}
51 const QString&getDate()const{ return date; }
52 void setDate( const QString&a ) { date = a; }
53 const QString&getFrom()const{ return from; }
54 void setFrom( const QString&a ) { from = a; }
55 const QString&getSubject()const { return subject; }
56 void setSubject( const QString&s ) { subject = s; }
57 void setFlags(const QBitArray&flags){msg_flags = flags;}
58 const QBitArray&getFlags()const{return msg_flags;}
59
60#if 0
61 void setDate(const QString&dstring);
62 void setDate(const QDateTime&date){mDate = date;}
63 QString getDate()const{return mDate.toString();}
64#endif
65protected:
66 QString subject,date,from;
67 int msg_number;
68 QBitArray msg_flags;
69#if 0
70 QDateTime mDate;
71#endif
72};
73
74typedef QList<RecMail> Maillist;
75
76class Mail
77{
78public:
79 Mail();
80 /* Possible that this destructor must not be declared virtual
81 * 'cause it seems that it will never have some child classes.
82 * in this case this object will not get a virtual table -> memory and
83 * speed will be a little bit better?
84 */
85 virtual ~Mail(){}
86 void addAttachment( Attachment *att ) { attList.append( att ); }
87 const QList<Attachment>& getAttachments()const { return attList; }
88 void removeAttachment( Attachment *att ) { attList.remove( att ); }
89 const QString&getName()const { return name; }
90 void setName( QString s ) { name = s; }
91 const QString&getMail()const{ return mail; }
92 void setMail( const QString&s ) { mail = s; }
93 const QString&getTo()const{ return to; }
94 void setTo( const QString&s ) { to = s; }
95 const QString&getCC()const{ return cc; }
96 void setCC( const QString&s ) { cc = s; }
97 const QString&getBCC()const { return bcc; }
98 void setBCC( const QString&s ) { bcc = s; }
99 const QString&getMessage()const { return message; }
100 void setMessage( const QString&s ) { message = s; }
101 const QString&getSubject()const { return subject; }
102 void setSubject( const QString&s ) { subject = s; }
103 const QString&getReply()const{ return reply; }
104 void setReply( const QString&a ) { reply = a; }
105
106private:
107 QList<Attachment> attList;
108 QString name, mail, to, cc, bcc, reply, subject, message;
109};
110
111class Folder : public QObject
112{
113 Q_OBJECT
114
115public:
116 Folder( const QString&init_name );
117 const QString&getDisplayName()const { return nameDisplay; }
118 const QString&getName()const { return name; }
119 virtual bool may_select()const{return true;};
120
121private:
122 QString nameDisplay, name;
123
124};
125
126class IMAPFolder : public Folder
127{
128 public:
129 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {}
130 virtual bool may_select()const{return m_MaySelect;}
131 private:
132 bool m_MaySelect;
133};
134
135class MailWrapper : public QObject
136{
137 Q_OBJECT
138
139public:
140 MailWrapper( Settings *s );
141 void sendMail( Mail mail );
142
143private:
144 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
145 mailimf_address_list *parseAddresses(const QString&addr );
146 mailimf_fields *createImfFields( Mail *mail );
147 mailmime *buildTxtPart( QString str );
148 mailmime *buildFilePart( QString filename, QString mimetype );
149 void addFileParts( mailmime *message, QList<Attachment> files );
150 mailmime *createMimeMail( Mail *mail );
151 void smtpSend( mailmime *mail );
152 mailimf_field *getField( mailimf_fields *fields, int type );
153 clist *createRcptList( mailimf_fields *fields );
154 char *getFrom( mailmime *mail );
155 SMTPaccount *getAccount( QString from );
156 void writeToFile( QString file, mailmime *mail );
157 void readFromFile( QString file, char **data, size_t *size );
158 static QString mailsmtpError( int err );
159 static QString getTmpFile();
160
161 Settings *settings;
162
163};
164
165class IMAPwrapper : public QObject
166{
167 Q_OBJECT
168
169public:
170 IMAPwrapper( IMAPaccount *a );
171 QList<IMAPFolder>* listFolders();
172 void listMessages(const QString & mailbox,Maillist&target );
173 QString fetchBody(const QString & mailbox,const RecMail&mail);
174
175protected:
176 RecMail*parse_list_result(mailimap_msg_att*);
177
178private:
179 IMAPaccount *account;
180
181};
182
183#endif