author | alwin <alwin> | 2003-12-13 20:39:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-13 20:39:07 (UTC) |
commit | 85444223acfafd9d7955032b2cbdad3279ba27ad (patch) (unidiff) | |
tree | 444063490a58ffc7ca085219827a577ad6213442 /noncore/net/mail/libmailwrapper | |
parent | d161cb46c21ae6a9e9f74dc60fb6ac6ac8e62f1b (diff) | |
download | opie-85444223acfafd9d7955032b2cbdad3279ba27ad.zip opie-85444223acfafd9d7955032b2cbdad3279ba27ad.tar.gz opie-85444223acfafd9d7955032b2cbdad3279ba27ad.tar.bz2 |
imap/pop3 wrapper uses base virtual class so we can forward the pointer
independend of its later use.
ToDo: find a more general interface for it
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 13 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 30 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 5 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 17 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 11 |
6 files changed, 81 insertions, 16 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp new file mode 100644 index 0000000..7380c31 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -0,0 +1,13 @@ | |||
1 | #include "abstractmail.h" | ||
2 | #include "imapwrapper.h" | ||
3 | #include "pop3wrapper.h" | ||
4 | |||
5 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | ||
6 | { | ||
7 | return new IMAPwrapper(a); | ||
8 | } | ||
9 | |||
10 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | ||
11 | { | ||
12 | return new POP3wrapper(a); | ||
13 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h new file mode 100644 index 0000000..bc8938f --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef __abstract_mail_ | ||
2 | #define __abstract_mail_ | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include "settings.h" | ||
6 | |||
7 | class RecMail; | ||
8 | class RecBody; | ||
9 | class RecPart; | ||
10 | class IMAPwrapper; | ||
11 | class POP3wrapper; | ||
12 | class Folder; | ||
13 | |||
14 | class AbstractMail:public QObject | ||
15 | { | ||
16 | Q_OBJECT | ||
17 | public: | ||
18 | AbstractMail(){}; | ||
19 | virtual ~AbstractMail(){} | ||
20 | virtual QList<Folder>* listFolders()=0; | ||
21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | ||
22 | virtual RecBody fetchBody(const RecMail&mail)=0; | ||
23 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0; | ||
24 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; | ||
25 | |||
26 | static AbstractMail* getWrapper(IMAPaccount *a); | ||
27 | static AbstractMail* getWrapper(POP3account *a); | ||
28 | }; | ||
29 | |||
30 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 48e476b..e5eb335 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,20 +1,21 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | ||
9 | { | 10 | { |
10 | account = a; | 11 | account = a; |
11 | m_imap = 0; | 12 | m_imap = 0; |
12 | } | 13 | } |
13 | 14 | ||
14 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
15 | { | 16 | { |
16 | logout(); | 17 | logout(); |
17 | } | 18 | } |
18 | 19 | ||
19 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
20 | { | 21 | { |
@@ -130,32 +131,32 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
130 | if (m) { | 131 | if (m) { |
131 | m->setNumber(i); | 132 | m->setNumber(i); |
132 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
133 | target.append(m); | 134 | target.append(m); |
134 | } | 135 | } |
135 | } | 136 | } |
136 | } else { | 137 | } else { |
137 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 138 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
138 | } | 139 | } |
139 | mailimap_fetch_list_free(result); | 140 | mailimap_fetch_list_free(result); |
140 | } | 141 | } |
141 | 142 | ||
142 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 143 | QList<Folder>* IMAPwrapper::listFolders() |
143 | { | 144 | { |
144 | const char *path, *mask; | 145 | const char *path, *mask; |
145 | int err = MAILIMAP_NO_ERROR; | 146 | int err = MAILIMAP_NO_ERROR; |
146 | clist *result; | 147 | clist *result; |
147 | clistcell *current; | 148 | clistcell *current; |
148 | 149 | ||
149 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 150 | QList<Folder> * folders = new QList<Folder>(); |
150 | folders->setAutoDelete( true ); | 151 | folders->setAutoDelete( true ); |
151 | login(); | 152 | login(); |
152 | if (!m_imap) { | 153 | if (!m_imap) { |
153 | return folders; | 154 | return folders; |
154 | } | 155 | } |
155 | 156 | ||
156 | /* | 157 | /* |
157 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 158 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
158 | * We must not forget to filter them out in next loop! | 159 | * We must not forget to filter them out in next loop! |
159 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 160 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
160 | */ | 161 | */ |
161 | QString temp; | 162 | QString temp; |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 95de215..f88457a 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,42 +1,39 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "abstractmail.h" | ||
6 | 7 | ||
7 | struct mailimap; | 8 | struct mailimap; |
8 | struct mailimap_body_type_1part; | 9 | struct mailimap_body_type_1part; |
9 | struct mailimap_body_type_text; | 10 | struct mailimap_body_type_text; |
10 | struct mailimap_body_type_basic; | 11 | struct mailimap_body_type_basic; |
11 | struct mailimap_body_type_msg; | 12 | struct mailimap_body_type_msg; |
12 | struct mailimap_body_type_mpart; | 13 | struct mailimap_body_type_mpart; |
13 | struct mailimap_body_fields; | 14 | struct mailimap_body_fields; |
14 | struct mailimap_msg_att; | 15 | struct mailimap_msg_att; |
15 | class RecMail; | ||
16 | class RecBody; | ||
17 | class RecPart; | ||
18 | 16 | ||
19 | class IMAPwrapper : public QObject | 17 | class IMAPwrapper : public AbstractMail |
20 | { | 18 | { |
21 | Q_OBJECT | 19 | Q_OBJECT |
22 | |||
23 | public: | 20 | public: |
24 | IMAPwrapper( IMAPaccount *a ); | 21 | IMAPwrapper( IMAPaccount *a ); |
25 | virtual ~IMAPwrapper(); | 22 | virtual ~IMAPwrapper(); |
26 | QList<IMAPFolder>* listFolders(); | 23 | virtual QList<Folder>* listFolders(); |
27 | void listMessages(const QString & mailbox,QList<RecMail>&target ); | 24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
28 | RecBody fetchBody(const RecMail&mail); | 25 | virtual RecBody fetchBody(const RecMail&mail); |
29 | QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); | 26 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); |
30 | QString fetchPart(const RecMail&mail,const RecPart&part); | 27 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); |
31 | static void imap_progress( size_t current, size_t maximum ); | 28 | static void imap_progress( size_t current, size_t maximum ); |
32 | 29 | ||
33 | protected: | 30 | protected: |
34 | RecMail*parse_list_result(mailimap_msg_att*); | 31 | RecMail*parse_list_result(mailimap_msg_att*); |
35 | void login(); | 32 | void login(); |
36 | void logout(); | 33 | void logout(); |
37 | 34 | ||
38 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 35 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
39 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 36 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
40 | 37 | ||
41 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 38 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
42 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 39 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index abb5a42..49c3b7a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -50,25 +50,25 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
51 | if ( err != MAILIMF_NO_ERROR ) return body; | 51 | if ( err != MAILIMF_NO_ERROR ) return body; |
52 | 52 | ||
53 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 53 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
54 | qDebug( "POP3: bodytext found" ); | 54 | qDebug( "POP3: bodytext found" ); |
55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. | 55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. |
56 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 56 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
57 | } | 57 | } |
58 | 58 | ||
59 | return body; | 59 | return body; |
60 | } | 60 | } |
61 | 61 | ||
62 | void POP3wrapper::listMessages( QList<RecMail> &target ) | 62 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
63 | { | 63 | { |
64 | int err = MAILPOP3_NO_ERROR; | 64 | int err = MAILPOP3_NO_ERROR; |
65 | char *header; | 65 | char *header; |
66 | size_t length; | 66 | size_t length; |
67 | carray *messages; | 67 | carray *messages; |
68 | 68 | ||
69 | login(); | 69 | login(); |
70 | if (!m_pop3) return; | 70 | if (!m_pop3) return; |
71 | mailpop3_list( m_pop3, &messages ); | 71 | mailpop3_list( m_pop3, &messages ); |
72 | 72 | ||
73 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 73 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
@@ -259,12 +259,31 @@ void POP3wrapper::login() | |||
259 | qDebug( "POP3: logged in!" ); | 259 | qDebug( "POP3: logged in!" ); |
260 | } | 260 | } |
261 | 261 | ||
262 | void POP3wrapper::logout() | 262 | void POP3wrapper::logout() |
263 | { | 263 | { |
264 | int err = MAILPOP3_NO_ERROR; | 264 | int err = MAILPOP3_NO_ERROR; |
265 | if ( m_pop3 == NULL ) return; | 265 | if ( m_pop3 == NULL ) return; |
266 | err = mailpop3_quit( m_pop3 ); | 266 | err = mailpop3_quit( m_pop3 ); |
267 | mailpop3_free( m_pop3 ); | 267 | mailpop3_free( m_pop3 ); |
268 | m_pop3 = NULL; | 268 | m_pop3 = NULL; |
269 | } | 269 | } |
270 | 270 | ||
271 | |||
272 | QList<Folder>* POP3wrapper::listFolders() | ||
273 | { | ||
274 | QList<Folder> * folders = new QList<Folder>(); | ||
275 | folders->setAutoDelete( true ); | ||
276 | Folder*inb=new Folder("INBOX"); | ||
277 | folders->append(inb); | ||
278 | return folders; | ||
279 | } | ||
280 | |||
281 | QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) | ||
282 | { | ||
283 | return ""; | ||
284 | } | ||
285 | |||
286 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) | ||
287 | { | ||
288 | return ""; | ||
289 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 995bed0..3b24564 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,38 +1,43 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | ||
5 | 6 | ||
6 | class RecMail; | 7 | class RecMail; |
7 | class RecBody; | 8 | class RecBody; |
8 | struct mailpop3; | 9 | struct mailpop3; |
9 | 10 | ||
10 | class POP3wrapper : public QObject | 11 | class POP3wrapper : public AbstractMail |
11 | { | 12 | { |
12 | Q_OBJECT | 13 | Q_OBJECT |
13 | 14 | ||
14 | public: | 15 | public: |
15 | POP3wrapper( POP3account *a ); | 16 | POP3wrapper( POP3account *a ); |
16 | virtual ~POP3wrapper(); | 17 | virtual ~POP3wrapper(); |
17 | void listMessages( QList<RecMail> &target ); | 18 | /* mailbox will be ignored */ |
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | ||
20 | virtual QList<Folder>* listFolders(); | ||
21 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); | ||
22 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | ||
23 | |||
18 | RecBody fetchBody( const RecMail &mail ); | 24 | RecBody fetchBody( const RecMail &mail ); |
19 | static void pop3_progress( size_t current, size_t maximum ); | 25 | static void pop3_progress( size_t current, size_t maximum ); |
20 | 26 | ||
21 | protected: | 27 | protected: |
22 | void login(); | 28 | void login(); |
23 | void logout(); | 29 | void logout(); |
24 | 30 | ||
25 | private: | 31 | private: |
26 | RecMail *parseHeader( const char *header ); | 32 | RecMail *parseHeader( const char *header ); |
27 | RecBody parseBody( const char *message ); | 33 | RecBody parseBody( const char *message ); |
28 | QString parseMailboxList( mailimf_mailbox_list *list ); | 34 | QString parseMailboxList( mailimf_mailbox_list *list ); |
29 | QString parseMailbox( mailimf_mailbox *box ); | 35 | QString parseMailbox( mailimf_mailbox *box ); |
30 | QString parseGroup( mailimf_group *group ); | 36 | QString parseGroup( mailimf_group *group ); |
31 | QString parseAddressList( mailimf_address_list *list ); | 37 | QString parseAddressList( mailimf_address_list *list ); |
32 | QString parseDateTime( mailimf_date_time *date ); | 38 | QString parseDateTime( mailimf_date_time *date ); |
33 | POP3account *account; | 39 | POP3account *account; |
34 | mailpop3 *m_pop3; | 40 | mailpop3 *m_pop3; |
35 | |||
36 | }; | 41 | }; |
37 | 42 | ||
38 | #endif | 43 | #endif |