-rw-r--r-- | noncore/net/mail/accountview.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 25 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 25 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 19 | ||||
-rw-r--r-- | noncore/net/mail/mail.pro | 3 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.h | 19 |
9 files changed, 57 insertions, 41 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index c6a44ab..a531976 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -1,110 +1,111 @@ | |||
1 | #include "accountview.h" | 1 | #include "accountview.h" |
2 | #include "imapwrapper.h" | ||
2 | #include "defines.h" | 3 | #include "defines.h" |
3 | 4 | ||
4 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) | 5 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) |
5 | : AccountViewItem( parent ) | 6 | : AccountViewItem( parent ) |
6 | { | 7 | { |
7 | account = a; | 8 | account = a; |
8 | wrapper = new IMAPwrapper( account ); | 9 | wrapper = new IMAPwrapper( account ); |
9 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 10 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
10 | setText( 0, account->getAccountName() ); | 11 | setText( 0, account->getAccountName() ); |
11 | setOpen( true ); | 12 | setOpen( true ); |
12 | } | 13 | } |
13 | 14 | ||
14 | IMAPviewItem::~IMAPviewItem() | 15 | IMAPviewItem::~IMAPviewItem() |
15 | { | 16 | { |
16 | delete wrapper; | 17 | delete wrapper; |
17 | } | 18 | } |
18 | 19 | ||
19 | IMAPwrapper *IMAPviewItem::getWrapper() | 20 | IMAPwrapper *IMAPviewItem::getWrapper() |
20 | { | 21 | { |
21 | return wrapper; | 22 | return wrapper; |
22 | } | 23 | } |
23 | 24 | ||
24 | void IMAPviewItem::refresh(Maillist&) | 25 | void IMAPviewItem::refresh(Maillist&) |
25 | { | 26 | { |
26 | QList<IMAPFolder> *folders = wrapper->listFolders(); | 27 | QList<IMAPFolder> *folders = wrapper->listFolders(); |
27 | 28 | ||
28 | QListViewItem *child = firstChild(); | 29 | QListViewItem *child = firstChild(); |
29 | while ( child ) { | 30 | while ( child ) { |
30 | QListViewItem *tmp = child; | 31 | QListViewItem *tmp = child; |
31 | child = child->nextSibling(); | 32 | child = child->nextSibling(); |
32 | delete tmp; | 33 | delete tmp; |
33 | } | 34 | } |
34 | 35 | ||
35 | IMAPFolder *it; | 36 | IMAPFolder *it; |
36 | for ( it = folders->first(); it; it = folders->next() ) { | 37 | for ( it = folders->first(); it; it = folders->next() ) { |
37 | (void) new IMAPfolderItem( it, this ); | 38 | (void) new IMAPfolderItem( it, this ); |
38 | } | 39 | } |
39 | } | 40 | } |
40 | 41 | ||
41 | 42 | ||
42 | IMAPfolderItem::~IMAPfolderItem() | 43 | IMAPfolderItem::~IMAPfolderItem() |
43 | { | 44 | { |
44 | delete folder; | 45 | delete folder; |
45 | } | 46 | } |
46 | 47 | ||
47 | IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) | 48 | IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) |
48 | : AccountViewItem( parent ) | 49 | : AccountViewItem( parent ) |
49 | { | 50 | { |
50 | folder = folderInit; | 51 | folder = folderInit; |
51 | imap = parent; | 52 | imap = parent; |
52 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 53 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
53 | setText( 0, folder->getDisplayName() ); | 54 | setText( 0, folder->getDisplayName() ); |
54 | } | 55 | } |
55 | 56 | ||
56 | void IMAPfolderItem::refresh(Maillist&target) | 57 | void IMAPfolderItem::refresh(Maillist&target) |
57 | { | 58 | { |
58 | imap->getWrapper()->listMessages( folder->getName(),target ); | 59 | imap->getWrapper()->listMessages( folder->getName(),target ); |
59 | } | 60 | } |
60 | 61 | ||
61 | QString IMAPfolderItem::fetchBody(const RecMail&aMail) | 62 | QString IMAPfolderItem::fetchBody(const RecMail&aMail) |
62 | { | 63 | { |
63 | return imap->getWrapper()->fetchBody(folder->getName(),aMail); | 64 | return imap->getWrapper()->fetchBody(folder->getName(),aMail); |
64 | } | 65 | } |
65 | 66 | ||
66 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | 67 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) |
67 | : QListView( parent, name, flags ) | 68 | : QListView( parent, name, flags ) |
68 | { | 69 | { |
69 | connect( this, SIGNAL( clicked( QListViewItem * ) ), | 70 | connect( this, SIGNAL( clicked( QListViewItem * ) ), |
70 | SLOT( refresh( QListViewItem * ) ) ); | 71 | SLOT( refresh( QListViewItem * ) ) ); |
71 | } | 72 | } |
72 | 73 | ||
73 | void AccountView::populate( QList<Account> list ) | 74 | void AccountView::populate( QList<Account> list ) |
74 | { | 75 | { |
75 | clear(); | 76 | clear(); |
76 | 77 | ||
77 | Account *it; | 78 | Account *it; |
78 | for ( it = list.first(); it; it = list.next() ) { | 79 | for ( it = list.first(); it; it = list.next() ) { |
79 | if ( it->getType().compare( "IMAP" ) == 0 ) { | 80 | if ( it->getType().compare( "IMAP" ) == 0 ) { |
80 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | 81 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); |
81 | qDebug( "added IMAP " + imap->getAccountName() ); | 82 | qDebug( "added IMAP " + imap->getAccountName() ); |
82 | (void) new IMAPviewItem( imap, this ); | 83 | (void) new IMAPviewItem( imap, this ); |
83 | } | 84 | } |
84 | } | 85 | } |
85 | } | 86 | } |
86 | 87 | ||
87 | void AccountView::refresh(QListViewItem *item) { | 88 | void AccountView::refresh(QListViewItem *item) { |
88 | qDebug("AccountView refresh..."); | 89 | qDebug("AccountView refresh..."); |
89 | if ( item ) { | 90 | if ( item ) { |
90 | Maillist headerlist; | 91 | Maillist headerlist; |
91 | headerlist.setAutoDelete(true); | 92 | headerlist.setAutoDelete(true); |
92 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 93 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
93 | view->refresh(headerlist); | 94 | view->refresh(headerlist); |
94 | emit refreshMailview(&headerlist); | 95 | emit refreshMailview(&headerlist); |
95 | } | 96 | } |
96 | } | 97 | } |
97 | 98 | ||
98 | void AccountView::refreshAll() | 99 | void AccountView::refreshAll() |
99 | { | 100 | { |
100 | 101 | ||
101 | } | 102 | } |
102 | 103 | ||
103 | QString AccountView::fetchBody(const RecMail&aMail) | 104 | QString AccountView::fetchBody(const RecMail&aMail) |
104 | { | 105 | { |
105 | QString Body; | 106 | QString Body; |
106 | QListViewItem*item = selectedItem (); | 107 | QListViewItem*item = selectedItem (); |
107 | if (!item) return Body; | 108 | if (!item) return Body; |
108 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 109 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
109 | return view->fetchBody(aMail); | 110 | return view->fetchBody(aMail); |
110 | } | 111 | } |
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index 14d8efa..2bc8023 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h | |||
@@ -1,67 +1,69 @@ | |||
1 | #ifndef ACCOUNTVIEW_H | 1 | #ifndef ACCOUNTVIEW_H |
2 | #define ACCOUNTVIEW_H | 2 | #define ACCOUNTVIEW_H |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | 5 | ||
6 | #include "settings.h" | 6 | #include "settings.h" |
7 | #include "mailwrapper.h" | 7 | #include "mailwrapper.h" |
8 | 8 | ||
9 | class IMAPwrapper; | ||
10 | |||
9 | class AccountViewItem : public QListViewItem | 11 | class AccountViewItem : public QListViewItem |
10 | { | 12 | { |
11 | 13 | ||
12 | public: | 14 | public: |
13 | AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} | 15 | AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} |
14 | AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} | 16 | AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} |
15 | virtual void refresh(Maillist&)=0; | 17 | virtual void refresh(Maillist&)=0; |
16 | virtual QString fetchBody(const RecMail&)=0; | 18 | virtual QString fetchBody(const RecMail&)=0; |
17 | }; | 19 | }; |
18 | 20 | ||
19 | class IMAPviewItem : public AccountViewItem | 21 | class IMAPviewItem : public AccountViewItem |
20 | { | 22 | { |
21 | 23 | ||
22 | public: | 24 | public: |
23 | IMAPviewItem( IMAPaccount *a, QListView *parent ); | 25 | IMAPviewItem( IMAPaccount *a, QListView *parent ); |
24 | ~IMAPviewItem(); | 26 | ~IMAPviewItem(); |
25 | virtual void refresh(Maillist&); | 27 | virtual void refresh(Maillist&); |
26 | virtual QString fetchBody(const RecMail&){return "";} | 28 | virtual QString fetchBody(const RecMail&){return "";} |
27 | IMAPwrapper *getWrapper(); | 29 | IMAPwrapper *getWrapper(); |
28 | 30 | ||
29 | private: | 31 | private: |
30 | IMAPaccount *account; | 32 | IMAPaccount *account; |
31 | IMAPwrapper *wrapper; | 33 | IMAPwrapper *wrapper; |
32 | 34 | ||
33 | }; | 35 | }; |
34 | 36 | ||
35 | class IMAPfolderItem : public AccountViewItem | 37 | class IMAPfolderItem : public AccountViewItem |
36 | { | 38 | { |
37 | 39 | ||
38 | public: | 40 | public: |
39 | IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); | 41 | IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); |
40 | ~IMAPfolderItem(); | 42 | ~IMAPfolderItem(); |
41 | virtual void refresh(Maillist&); | 43 | virtual void refresh(Maillist&); |
42 | virtual QString fetchBody(const RecMail&); | 44 | virtual QString fetchBody(const RecMail&); |
43 | 45 | ||
44 | private: | 46 | private: |
45 | IMAPFolder *folder; | 47 | IMAPFolder *folder; |
46 | IMAPviewItem *imap; | 48 | IMAPviewItem *imap; |
47 | 49 | ||
48 | }; | 50 | }; |
49 | 51 | ||
50 | class AccountView : public QListView | 52 | class AccountView : public QListView |
51 | { | 53 | { |
52 | Q_OBJECT | 54 | Q_OBJECT |
53 | 55 | ||
54 | public: | 56 | public: |
55 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | 57 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); |
56 | void populate( QList<Account> list ); | 58 | void populate( QList<Account> list ); |
57 | QString fetchBody(const RecMail&aMail); | 59 | QString fetchBody(const RecMail&aMail); |
58 | 60 | ||
59 | public slots: | 61 | public slots: |
60 | void refreshAll(); | 62 | void refreshAll(); |
61 | void refresh(QListViewItem *item); | 63 | void refresh(QListViewItem *item); |
62 | 64 | ||
63 | signals: | 65 | signals: |
64 | void refreshMailview(Maillist*); | 66 | void refreshMailview(Maillist*); |
65 | }; | 67 | }; |
66 | 68 | ||
67 | #endif | 69 | #endif |
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index fc12947..7b78499 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,420 +1,420 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "imapwrapper.h" |
5 | 5 | ||
6 | 6 | ||
7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
8 | { | 8 | { |
9 | account = a; | 9 | account = a; |
10 | } | 10 | } |
11 | 11 | ||
12 | void imap_progress( size_t current, size_t maximum ) | 12 | void imap_progress( size_t current, size_t maximum ) |
13 | { | 13 | { |
14 | qDebug( "IMAP: %i of %i", current, maximum ); | 14 | qDebug( "IMAP: %i of %i", current, maximum ); |
15 | } | 15 | } |
16 | 16 | ||
17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) | 17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) |
18 | { | 18 | { |
19 | const char *server, *user, *pass, *mb; | 19 | const char *server, *user, *pass, *mb; |
20 | uint16_t port; | 20 | uint16_t port; |
21 | int err = MAILIMAP_NO_ERROR; | 21 | int err = MAILIMAP_NO_ERROR; |
22 | clist *result; | 22 | clist *result; |
23 | clistcell *current; | 23 | clistcell *current; |
24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; | 24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; |
25 | mailimap_fetch_type *fetchType; | 25 | mailimap_fetch_type *fetchType; |
26 | mailimap_set *set; | 26 | mailimap_set *set; |
27 | 27 | ||
28 | mb = mailbox.latin1(); | 28 | mb = mailbox.latin1(); |
29 | server = account->getServer().latin1(); | 29 | server = account->getServer().latin1(); |
30 | port = account->getPort().toUInt(); | 30 | port = account->getPort().toUInt(); |
31 | user = account->getUser().latin1(); | 31 | user = account->getUser().latin1(); |
32 | pass = account->getPassword().latin1(); | 32 | pass = account->getPassword().latin1(); |
33 | 33 | ||
34 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 34 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
35 | if ( imap == NULL ) { | 35 | if ( imap == NULL ) { |
36 | qDebug("IMAP Memory error"); | 36 | qDebug("IMAP Memory error"); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | 39 | ||
40 | /* connect */ | 40 | /* connect */ |
41 | err = mailimap_socket_connect( imap, (char*)server, port ); | 41 | err = mailimap_socket_connect( imap, (char*)server, port ); |
42 | if ( err != MAILIMAP_NO_ERROR && | 42 | if ( err != MAILIMAP_NO_ERROR && |
43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
45 | qDebug("error connecting server: %s",imap->response); | 45 | qDebug("error connecting server: %s",imap->response); |
46 | mailimap_free( imap ); | 46 | mailimap_free( imap ); |
47 | return; | 47 | return; |
48 | } | 48 | } |
49 | 49 | ||
50 | /* login */ | 50 | /* login */ |
51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
52 | if ( err != MAILIMAP_NO_ERROR ) { | 52 | if ( err != MAILIMAP_NO_ERROR ) { |
53 | qDebug("error logging in imap: %s",imap->response); | 53 | qDebug("error logging in imap: %s",imap->response); |
54 | err = mailimap_close( imap ); | 54 | err = mailimap_close( imap ); |
55 | mailimap_free( imap ); | 55 | mailimap_free( imap ); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* select mailbox READONLY for operations */ | 59 | /* select mailbox READONLY for operations */ |
60 | err = mailimap_examine( imap, (char*)mb); | 60 | err = mailimap_examine( imap, (char*)mb); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error selecting mailbox: %s",imap->response); | 62 | qDebug("error selecting mailbox: %s",imap->response); |
63 | err = mailimap_logout( imap ); | 63 | err = mailimap_logout( imap ); |
64 | err = mailimap_close( imap ); | 64 | err = mailimap_close( imap ); |
65 | mailimap_free( imap ); | 65 | mailimap_free( imap ); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | 68 | ||
69 | int last = imap->selection_info->exists; | 69 | int last = imap->selection_info->exists; |
70 | if (last == 0) { | 70 | if (last == 0) { |
71 | qDebug("mailbox has no mails"); | 71 | qDebug("mailbox has no mails"); |
72 | err = mailimap_logout( imap ); | 72 | err = mailimap_logout( imap ); |
73 | err = mailimap_close( imap ); | 73 | err = mailimap_close( imap ); |
74 | mailimap_free( imap ); | 74 | mailimap_free( imap ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | result = clist_new(); | 79 | result = clist_new(); |
80 | /* the range has to start at 1!!! not with 0!!!! */ | 80 | /* the range has to start at 1!!! not with 0!!!! */ |
81 | set = mailimap_set_new_interval( 1, last ); | 81 | set = mailimap_set_new_interval( 1, last ); |
82 | fetchAtt = mailimap_fetch_att_new_envelope(); | 82 | fetchAtt = mailimap_fetch_att_new_envelope(); |
83 | fetchAttFlags = mailimap_fetch_att_new_flags(); | 83 | fetchAttFlags = mailimap_fetch_att_new_flags(); |
84 | fetchAttDate = mailimap_fetch_att_new_internaldate(); | 84 | fetchAttDate = mailimap_fetch_att_new_internaldate(); |
85 | 85 | ||
86 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 86 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
87 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 87 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | 88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); |
89 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | 89 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); |
90 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); | 90 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); |
91 | 91 | ||
92 | err = mailimap_fetch( imap, set, fetchType, &result ); | 92 | err = mailimap_fetch( imap, set, fetchType, &result ); |
93 | mailimap_set_free( set ); | 93 | mailimap_set_free( set ); |
94 | /* cleans up the fetch_att's too! */ | 94 | /* cleans up the fetch_att's too! */ |
95 | mailimap_fetch_type_free( fetchType ); | 95 | mailimap_fetch_type_free( fetchType ); |
96 | 96 | ||
97 | QString date,subject,from; | 97 | QString date,subject,from; |
98 | 98 | ||
99 | if ( err == MAILIMAP_NO_ERROR ) { | 99 | if ( err == MAILIMAP_NO_ERROR ) { |
100 | current = clist_begin(result); | 100 | current = clist_begin(result); |
101 | mailimap_msg_att * msg_att; | 101 | mailimap_msg_att * msg_att; |
102 | int i = 0; | 102 | int i = 0; |
103 | while ( current != 0 ) { | 103 | while ( current != 0 ) { |
104 | ++i; | 104 | ++i; |
105 | msg_att = (mailimap_msg_att*)current->data; | 105 | msg_att = (mailimap_msg_att*)current->data; |
106 | RecMail*m = parse_list_result(msg_att); | 106 | RecMail*m = parse_list_result(msg_att); |
107 | if (m) { | 107 | if (m) { |
108 | m->setNumber(i); | 108 | m->setNumber(i); |
109 | target.append(m); | 109 | target.append(m); |
110 | } | 110 | } |
111 | current = current->next; | 111 | current = current->next; |
112 | } | 112 | } |
113 | } else { | 113 | } else { |
114 | qDebug("Error fetching headers: %s",imap->response); | 114 | qDebug("Error fetching headers: %s",imap->response); |
115 | } | 115 | } |
116 | 116 | ||
117 | err = mailimap_logout( imap ); | 117 | err = mailimap_logout( imap ); |
118 | err = mailimap_close( imap ); | 118 | err = mailimap_close( imap ); |
119 | clist_free(result); | 119 | clist_free(result); |
120 | mailimap_free( imap ); | 120 | mailimap_free( imap ); |
121 | } | 121 | } |
122 | 122 | ||
123 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 123 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
124 | { | 124 | { |
125 | const char *server, *user, *pass, *path, *mask; | 125 | const char *server, *user, *pass, *path, *mask; |
126 | uint16_t port; | 126 | uint16_t port; |
127 | int err = MAILIMAP_NO_ERROR; | 127 | int err = MAILIMAP_NO_ERROR; |
128 | clist *result; | 128 | clist *result; |
129 | clistcell *current; | 129 | clistcell *current; |
130 | 130 | ||
131 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 131 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
132 | folders->setAutoDelete( true ); | 132 | folders->setAutoDelete( true ); |
133 | 133 | ||
134 | server = account->getServer().latin1(); | 134 | server = account->getServer().latin1(); |
135 | port = account->getPort().toUInt(); | 135 | port = account->getPort().toUInt(); |
136 | user = account->getUser().latin1(); | 136 | user = account->getUser().latin1(); |
137 | pass = account->getPassword().latin1(); | 137 | pass = account->getPassword().latin1(); |
138 | path = account->getPrefix().latin1(); | 138 | path = account->getPrefix().latin1(); |
139 | 139 | ||
140 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 140 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
141 | if ( imap == NULL ) { | 141 | if ( imap == NULL ) { |
142 | qDebug("error mailimap_new"); | 142 | qDebug("error mailimap_new"); |
143 | return folders; | 143 | return folders; |
144 | } | 144 | } |
145 | 145 | ||
146 | err = mailimap_socket_connect( imap, (char*)server, port ); | 146 | err = mailimap_socket_connect( imap, (char*)server, port ); |
147 | if ( err != MAILIMAP_NO_ERROR && | 147 | if ( err != MAILIMAP_NO_ERROR && |
148 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 148 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
149 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 149 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
150 | mailimap_free(imap); | 150 | mailimap_free(imap); |
151 | qDebug("error imap_socket_connect: %s",imap->response); | 151 | qDebug("error imap_socket_connect: %s",imap->response); |
152 | return folders; | 152 | return folders; |
153 | } | 153 | } |
154 | 154 | ||
155 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 155 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
156 | if ( err != MAILIMAP_NO_ERROR ) { | 156 | if ( err != MAILIMAP_NO_ERROR ) { |
157 | mailimap_free(imap); | 157 | mailimap_free(imap); |
158 | qDebug("error logging in: %s",imap->response); | 158 | qDebug("error logging in: %s",imap->response); |
159 | return folders; | 159 | return folders; |
160 | } | 160 | } |
161 | /* | 161 | /* |
162 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 162 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
163 | * We must not forget to filter them out in next loop! | 163 | * We must not forget to filter them out in next loop! |
164 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 164 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
165 | */ | 165 | */ |
166 | QString temp; | 166 | QString temp; |
167 | mask = "INBOX" ; | 167 | mask = "INBOX" ; |
168 | result = clist_new(); | 168 | result = clist_new(); |
169 | mailimap_mailbox_list *list; | 169 | mailimap_mailbox_list *list; |
170 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); | 170 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); |
171 | if ( err == MAILIMAP_NO_ERROR ) { | 171 | if ( err == MAILIMAP_NO_ERROR ) { |
172 | current = result->first; | 172 | current = result->first; |
173 | for ( int i = result->count; i > 0; i-- ) { | 173 | for ( int i = result->count; i > 0; i-- ) { |
174 | list = (mailimap_mailbox_list *) current->data; | 174 | list = (mailimap_mailbox_list *) current->data; |
175 | // it is better use the deep copy mechanism of qt itself | 175 | // it is better use the deep copy mechanism of qt itself |
176 | // instead of using strdup! | 176 | // instead of using strdup! |
177 | temp = list->mb; | 177 | temp = list->mb; |
178 | folders->append( new IMAPFolder(temp)); | 178 | folders->append( new IMAPFolder(temp)); |
179 | current = current->next; | 179 | current = current->next; |
180 | } | 180 | } |
181 | } else { | 181 | } else { |
182 | qDebug("error fetching folders: %s",imap->response); | 182 | qDebug("error fetching folders: %s",imap->response); |
183 | } | 183 | } |
184 | mailimap_list_result_free( result ); | 184 | mailimap_list_result_free( result ); |
185 | 185 | ||
186 | /* | 186 | /* |
187 | * second stage - get the other then inbox folders | 187 | * second stage - get the other then inbox folders |
188 | */ | 188 | */ |
189 | mask = "*" ; | 189 | mask = "*" ; |
190 | result = clist_new(); | 190 | result = clist_new(); |
191 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); | 191 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); |
192 | if ( err == MAILIMAP_NO_ERROR ) { | 192 | if ( err == MAILIMAP_NO_ERROR ) { |
193 | current = result->first; | 193 | current = result->first; |
194 | for ( int i = result->count; i > 0; i-- ) { | 194 | for ( int i = result->count; i > 0; i-- ) { |
195 | list = (mailimap_mailbox_list *) current->data; | 195 | list = (mailimap_mailbox_list *) current->data; |
196 | // it is better use the deep copy mechanism of qt itself | 196 | // it is better use the deep copy mechanism of qt itself |
197 | // instead of using strdup! | 197 | // instead of using strdup! |
198 | temp = list->mb; | 198 | temp = list->mb; |
199 | current = current->next; | 199 | current = current->next; |
200 | if (temp.lower()=="inbox") | 200 | if (temp.lower()=="inbox") |
201 | continue; | 201 | continue; |
202 | folders->append(new IMAPFolder(temp)); | 202 | folders->append(new IMAPFolder(temp)); |
203 | 203 | ||
204 | } | 204 | } |
205 | } else { | 205 | } else { |
206 | qDebug("error fetching folders"); | 206 | qDebug("error fetching folders"); |
207 | } | 207 | } |
208 | mailimap_list_result_free( result ); | 208 | mailimap_list_result_free( result ); |
209 | err = mailimap_logout( imap ); | 209 | err = mailimap_logout( imap ); |
210 | err = mailimap_close( imap ); | 210 | err = mailimap_close( imap ); |
211 | mailimap_free( imap ); | 211 | mailimap_free( imap ); |
212 | return folders; | 212 | return folders; |
213 | } | 213 | } |
214 | 214 | ||
215 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 215 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
216 | { | 216 | { |
217 | RecMail * m = 0; | 217 | RecMail * m = 0; |
218 | mailimap_msg_att_item *item=0; | 218 | mailimap_msg_att_item *item=0; |
219 | bool named_from = false; | 219 | bool named_from = false; |
220 | QString from,date,subject; | 220 | QString from,date,subject; |
221 | date = from = subject = ""; | 221 | date = from = subject = ""; |
222 | clistcell *current,*c,*cf, *current_from = NULL; | 222 | clistcell *current,*c,*cf, *current_from = NULL; |
223 | mailimap_address * current_address = NULL; | 223 | mailimap_address * current_address = NULL; |
224 | mailimap_msg_att_dynamic*flist; | 224 | mailimap_msg_att_dynamic*flist; |
225 | mailimap_flag_fetch*cflag; | 225 | mailimap_flag_fetch*cflag; |
226 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
227 | 227 | ||
228 | if (!m_att) { | 228 | if (!m_att) { |
229 | return m; | 229 | return m; |
230 | } | 230 | } |
231 | 231 | ||
232 | #if 0 | 232 | #if 0 |
233 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | 233 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ |
234 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | 234 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ |
235 | #endif | 235 | #endif |
236 | c = clist_begin(m_att->list); | 236 | c = clist_begin(m_att->list); |
237 | while ( c ) { | 237 | while ( c ) { |
238 | current = c; | 238 | current = c; |
239 | c = c->next; | 239 | c = c->next; |
240 | item = (mailimap_msg_att_item*)current->data; | 240 | item = (mailimap_msg_att_item*)current->data; |
241 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 241 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
242 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | 242 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; |
243 | if (!flist->list) { | 243 | if (!flist->list) { |
244 | continue; | 244 | continue; |
245 | } | 245 | } |
246 | cf = flist->list->first; | 246 | cf = flist->list->first; |
247 | while (cf) { | 247 | while (cf) { |
248 | cflag = (mailimap_flag_fetch*)cf->data; | 248 | cflag = (mailimap_flag_fetch*)cf->data; |
249 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | 249 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { |
250 | switch (cflag->flag->type) { | 250 | switch (cflag->flag->type) { |
251 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 251 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
252 | mFlags.setBit(FLAG_ANSWERED); | 252 | mFlags.setBit(FLAG_ANSWERED); |
253 | break; | 253 | break; |
254 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 254 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
255 | mFlags.setBit(FLAG_FLAGGED); | 255 | mFlags.setBit(FLAG_FLAGGED); |
256 | break; | 256 | break; |
257 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 257 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
258 | mFlags.setBit(FLAG_DELETED); | 258 | mFlags.setBit(FLAG_DELETED); |
259 | break; | 259 | break; |
260 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 260 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
261 | mFlags.setBit(FLAG_SEEN); | 261 | mFlags.setBit(FLAG_SEEN); |
262 | break; | 262 | break; |
263 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 263 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
264 | mFlags.setBit(FLAG_DRAFT); | 264 | mFlags.setBit(FLAG_DRAFT); |
265 | break; | 265 | break; |
266 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 266 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
267 | break; | 267 | break; |
268 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 268 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
269 | break; | 269 | break; |
270 | default: | 270 | default: |
271 | break; | 271 | break; |
272 | } | 272 | } |
273 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | 273 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { |
274 | mFlags.setBit(FLAG_RECENT); | 274 | mFlags.setBit(FLAG_RECENT); |
275 | } | 275 | } |
276 | 276 | ||
277 | cf = cf->next; | 277 | cf = cf->next; |
278 | } | 278 | } |
279 | continue; | 279 | continue; |
280 | } | 280 | } |
281 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 281 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { |
282 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | 282 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); |
283 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | 283 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { |
284 | mailimap_envelope * head = item->msg_att_static->env; | 284 | mailimap_envelope * head = item->msg_att_static->env; |
285 | date = head->date; | 285 | date = head->date; |
286 | subject = head->subject; | 286 | subject = head->subject; |
287 | if (head->from!=NULL) | 287 | if (head->from!=NULL) |
288 | current_from = head->from->list->first; | 288 | current_from = head->from->list->first; |
289 | while (current_from != NULL) { | 289 | while (current_from != NULL) { |
290 | from = ""; | 290 | from = ""; |
291 | named_from = false; | 291 | named_from = false; |
292 | current_address=(mailimap_address*)current_from->data; | 292 | current_address=(mailimap_address*)current_from->data; |
293 | current_from = current_from->next; | 293 | current_from = current_from->next; |
294 | if (current_address->personal_name){ | 294 | if (current_address->personal_name){ |
295 | from+=QString(current_address->personal_name); | 295 | from+=QString(current_address->personal_name); |
296 | from+=" "; | 296 | from+=" "; |
297 | named_from = true; | 297 | named_from = true; |
298 | } | 298 | } |
299 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | 299 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { |
300 | from+="<"; | 300 | from+="<"; |
301 | } | 301 | } |
302 | if (current_address->mailbox_name) { | 302 | if (current_address->mailbox_name) { |
303 | from+=QString(current_address->mailbox_name); | 303 | from+=QString(current_address->mailbox_name); |
304 | from+="@"; | 304 | from+="@"; |
305 | } | 305 | } |
306 | if (current_address->host_name) { | 306 | if (current_address->host_name) { |
307 | from+=QString(current_address->host_name); | 307 | from+=QString(current_address->host_name); |
308 | } | 308 | } |
309 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | 309 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { |
310 | from+=">"; | 310 | from+=">"; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | 313 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", |
314 | from.latin1(), | 314 | from.latin1(), |
315 | subject.latin1(),date.latin1()); | 315 | subject.latin1(),date.latin1()); |
316 | m = new RecMail(); | 316 | m = new RecMail(); |
317 | m->setSubject(subject); | 317 | m->setSubject(subject); |
318 | m->setFrom(from); | 318 | m->setFrom(from); |
319 | m->setDate(date); | 319 | m->setDate(date); |
320 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 320 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
321 | mailimap_date_time*d = item->msg_att_static->internal_date; | 321 | mailimap_date_time*d = item->msg_att_static->internal_date; |
322 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); | 322 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); |
323 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); | 323 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); |
324 | qDebug(da.toString()); | 324 | qDebug(da.toString()); |
325 | } else { | 325 | } else { |
326 | qDebug("Another type"); | 326 | qDebug("Another type"); |
327 | } | 327 | } |
328 | } | 328 | } |
329 | /* msg is already deleted */ | 329 | /* msg is already deleted */ |
330 | if (mFlags.testBit(FLAG_DELETED) && m) { | 330 | if (mFlags.testBit(FLAG_DELETED) && m) { |
331 | delete m; | 331 | delete m; |
332 | m = 0; | 332 | m = 0; |
333 | } | 333 | } |
334 | if (m) { | 334 | if (m) { |
335 | m->setFlags(mFlags); | 335 | m->setFlags(mFlags); |
336 | } | 336 | } |
337 | return m; | 337 | return m; |
338 | } | 338 | } |
339 | 339 | ||
340 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) | 340 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) |
341 | { | 341 | { |
342 | QString body = ""; | 342 | QString body = ""; |
343 | const char *server, *user, *pass, *mb; | 343 | const char *server, *user, *pass, *mb; |
344 | uint16_t port; | 344 | uint16_t port; |
345 | int err = MAILIMAP_NO_ERROR; | 345 | int err = MAILIMAP_NO_ERROR; |
346 | clist *result; | 346 | clist *result; |
347 | clistcell *current; | 347 | clistcell *current; |
348 | mailimap_fetch_att *fetchAtt; | 348 | mailimap_fetch_att *fetchAtt; |
349 | mailimap_fetch_type *fetchType; | 349 | mailimap_fetch_type *fetchType; |
350 | mailimap_set *set; | 350 | mailimap_set *set; |
351 | 351 | ||
352 | mb = mailbox.latin1(); | 352 | mb = mailbox.latin1(); |
353 | server = account->getServer().latin1(); | 353 | server = account->getServer().latin1(); |
354 | port = account->getPort().toUInt(); | 354 | port = account->getPort().toUInt(); |
355 | user = account->getUser().latin1(); | 355 | user = account->getUser().latin1(); |
356 | pass = account->getPassword().latin1(); | 356 | pass = account->getPassword().latin1(); |
357 | 357 | ||
358 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 358 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
359 | if ( imap == NULL ) { | 359 | if ( imap == NULL ) { |
360 | qDebug("IMAP Memory error"); | 360 | qDebug("IMAP Memory error"); |
361 | return body; | 361 | return body; |
362 | } | 362 | } |
363 | 363 | ||
364 | /* connect */ | 364 | /* connect */ |
365 | err = mailimap_socket_connect( imap, (char*)server, port ); | 365 | err = mailimap_socket_connect( imap, (char*)server, port ); |
366 | if ( err != MAILIMAP_NO_ERROR && | 366 | if ( err != MAILIMAP_NO_ERROR && |
367 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 367 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
368 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 368 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
369 | qDebug("error connecting server: %s",imap->response); | 369 | qDebug("error connecting server: %s",imap->response); |
370 | mailimap_free( imap ); | 370 | mailimap_free( imap ); |
371 | return body; | 371 | return body; |
372 | } | 372 | } |
373 | 373 | ||
374 | /* login */ | 374 | /* login */ |
375 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 375 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
376 | if ( err != MAILIMAP_NO_ERROR ) { | 376 | if ( err != MAILIMAP_NO_ERROR ) { |
377 | qDebug("error logging in imap: %s",imap->response); | 377 | qDebug("error logging in imap: %s",imap->response); |
378 | err = mailimap_close( imap ); | 378 | err = mailimap_close( imap ); |
379 | mailimap_free( imap ); | 379 | mailimap_free( imap ); |
380 | return body; | 380 | return body; |
381 | } | 381 | } |
382 | 382 | ||
383 | /* select mailbox READONLY for operations */ | 383 | /* select mailbox READONLY for operations */ |
384 | err = mailimap_examine( imap, (char*)mb); | 384 | err = mailimap_examine( imap, (char*)mb); |
385 | if ( err != MAILIMAP_NO_ERROR ) { | 385 | if ( err != MAILIMAP_NO_ERROR ) { |
386 | qDebug("error selecting mailbox: %s",imap->response); | 386 | qDebug("error selecting mailbox: %s",imap->response); |
387 | err = mailimap_logout( imap ); | 387 | err = mailimap_logout( imap ); |
388 | err = mailimap_close( imap ); | 388 | err = mailimap_close( imap ); |
389 | mailimap_free( imap ); | 389 | mailimap_free( imap ); |
390 | return body; | 390 | return body; |
391 | } | 391 | } |
392 | result = clist_new(); | 392 | result = clist_new(); |
393 | /* the range has to start at 1!!! not with 0!!!! */ | 393 | /* the range has to start at 1!!! not with 0!!!! */ |
394 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 394 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
395 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | 395 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); |
396 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 396 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
397 | err = mailimap_fetch( imap, set, fetchType, &result ); | 397 | err = mailimap_fetch( imap, set, fetchType, &result ); |
398 | mailimap_set_free( set ); | 398 | mailimap_set_free( set ); |
399 | mailimap_fetch_type_free( fetchType ); | 399 | mailimap_fetch_type_free( fetchType ); |
400 | 400 | ||
401 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 401 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
402 | mailimap_msg_att * msg_att; | 402 | mailimap_msg_att * msg_att; |
403 | msg_att = (mailimap_msg_att*)current->data; | 403 | msg_att = (mailimap_msg_att*)current->data; |
404 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 404 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
405 | 405 | ||
406 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | 406 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { |
407 | body = item->msg_att_static->rfc822_text; | 407 | body = item->msg_att_static->rfc822_text; |
408 | } | 408 | } |
409 | } else { | 409 | } else { |
410 | qDebug("error fetching text: %s",imap->response); | 410 | qDebug("error fetching text: %s",imap->response); |
411 | } | 411 | } |
412 | 412 | ||
413 | err = mailimap_logout( imap ); | 413 | err = mailimap_logout( imap ); |
414 | err = mailimap_close( imap ); | 414 | err = mailimap_close( imap ); |
415 | mailimap_free( imap ); | 415 | mailimap_free( imap ); |
416 | clist_free(result); | 416 | clist_free(result); |
417 | 417 | ||
418 | return body; | 418 | return body; |
419 | } | 419 | } |
420 | 420 | ||
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h new file mode 100644 index 0000000..65c36e0 --- a/dev/null +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef __IMAPWRAPPER | ||
2 | #define __IMAPWRAPPER | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | #include <libetpan/mailimap.h> | ||
6 | |||
7 | class IMAPwrapper : public QObject | ||
8 | { | ||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | IMAPwrapper( IMAPaccount *a ); | ||
13 | QList<IMAPFolder>* listFolders(); | ||
14 | void listMessages(const QString & mailbox,Maillist&target ); | ||
15 | QString fetchBody(const QString & mailbox,const RecMail&mail); | ||
16 | |||
17 | protected: | ||
18 | RecMail*parse_list_result(mailimap_msg_att*); | ||
19 | |||
20 | private: | ||
21 | IMAPaccount *account; | ||
22 | |||
23 | }; | ||
24 | |||
25 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index fc12947..7b78499 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,420 +1,420 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "imapwrapper.h" |
5 | 5 | ||
6 | 6 | ||
7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
8 | { | 8 | { |
9 | account = a; | 9 | account = a; |
10 | } | 10 | } |
11 | 11 | ||
12 | void imap_progress( size_t current, size_t maximum ) | 12 | void imap_progress( size_t current, size_t maximum ) |
13 | { | 13 | { |
14 | qDebug( "IMAP: %i of %i", current, maximum ); | 14 | qDebug( "IMAP: %i of %i", current, maximum ); |
15 | } | 15 | } |
16 | 16 | ||
17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) | 17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) |
18 | { | 18 | { |
19 | const char *server, *user, *pass, *mb; | 19 | const char *server, *user, *pass, *mb; |
20 | uint16_t port; | 20 | uint16_t port; |
21 | int err = MAILIMAP_NO_ERROR; | 21 | int err = MAILIMAP_NO_ERROR; |
22 | clist *result; | 22 | clist *result; |
23 | clistcell *current; | 23 | clistcell *current; |
24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; | 24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; |
25 | mailimap_fetch_type *fetchType; | 25 | mailimap_fetch_type *fetchType; |
26 | mailimap_set *set; | 26 | mailimap_set *set; |
27 | 27 | ||
28 | mb = mailbox.latin1(); | 28 | mb = mailbox.latin1(); |
29 | server = account->getServer().latin1(); | 29 | server = account->getServer().latin1(); |
30 | port = account->getPort().toUInt(); | 30 | port = account->getPort().toUInt(); |
31 | user = account->getUser().latin1(); | 31 | user = account->getUser().latin1(); |
32 | pass = account->getPassword().latin1(); | 32 | pass = account->getPassword().latin1(); |
33 | 33 | ||
34 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 34 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
35 | if ( imap == NULL ) { | 35 | if ( imap == NULL ) { |
36 | qDebug("IMAP Memory error"); | 36 | qDebug("IMAP Memory error"); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | 39 | ||
40 | /* connect */ | 40 | /* connect */ |
41 | err = mailimap_socket_connect( imap, (char*)server, port ); | 41 | err = mailimap_socket_connect( imap, (char*)server, port ); |
42 | if ( err != MAILIMAP_NO_ERROR && | 42 | if ( err != MAILIMAP_NO_ERROR && |
43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
45 | qDebug("error connecting server: %s",imap->response); | 45 | qDebug("error connecting server: %s",imap->response); |
46 | mailimap_free( imap ); | 46 | mailimap_free( imap ); |
47 | return; | 47 | return; |
48 | } | 48 | } |
49 | 49 | ||
50 | /* login */ | 50 | /* login */ |
51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
52 | if ( err != MAILIMAP_NO_ERROR ) { | 52 | if ( err != MAILIMAP_NO_ERROR ) { |
53 | qDebug("error logging in imap: %s",imap->response); | 53 | qDebug("error logging in imap: %s",imap->response); |
54 | err = mailimap_close( imap ); | 54 | err = mailimap_close( imap ); |
55 | mailimap_free( imap ); | 55 | mailimap_free( imap ); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* select mailbox READONLY for operations */ | 59 | /* select mailbox READONLY for operations */ |
60 | err = mailimap_examine( imap, (char*)mb); | 60 | err = mailimap_examine( imap, (char*)mb); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error selecting mailbox: %s",imap->response); | 62 | qDebug("error selecting mailbox: %s",imap->response); |
63 | err = mailimap_logout( imap ); | 63 | err = mailimap_logout( imap ); |
64 | err = mailimap_close( imap ); | 64 | err = mailimap_close( imap ); |
65 | mailimap_free( imap ); | 65 | mailimap_free( imap ); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | 68 | ||
69 | int last = imap->selection_info->exists; | 69 | int last = imap->selection_info->exists; |
70 | if (last == 0) { | 70 | if (last == 0) { |
71 | qDebug("mailbox has no mails"); | 71 | qDebug("mailbox has no mails"); |
72 | err = mailimap_logout( imap ); | 72 | err = mailimap_logout( imap ); |
73 | err = mailimap_close( imap ); | 73 | err = mailimap_close( imap ); |
74 | mailimap_free( imap ); | 74 | mailimap_free( imap ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | result = clist_new(); | 79 | result = clist_new(); |
80 | /* the range has to start at 1!!! not with 0!!!! */ | 80 | /* the range has to start at 1!!! not with 0!!!! */ |
81 | set = mailimap_set_new_interval( 1, last ); | 81 | set = mailimap_set_new_interval( 1, last ); |
82 | fetchAtt = mailimap_fetch_att_new_envelope(); | 82 | fetchAtt = mailimap_fetch_att_new_envelope(); |
83 | fetchAttFlags = mailimap_fetch_att_new_flags(); | 83 | fetchAttFlags = mailimap_fetch_att_new_flags(); |
84 | fetchAttDate = mailimap_fetch_att_new_internaldate(); | 84 | fetchAttDate = mailimap_fetch_att_new_internaldate(); |
85 | 85 | ||
86 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 86 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
87 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 87 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | 88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); |
89 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | 89 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); |
90 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); | 90 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); |
91 | 91 | ||
92 | err = mailimap_fetch( imap, set, fetchType, &result ); | 92 | err = mailimap_fetch( imap, set, fetchType, &result ); |
93 | mailimap_set_free( set ); | 93 | mailimap_set_free( set ); |
94 | /* cleans up the fetch_att's too! */ | 94 | /* cleans up the fetch_att's too! */ |
95 | mailimap_fetch_type_free( fetchType ); | 95 | mailimap_fetch_type_free( fetchType ); |
96 | 96 | ||
97 | QString date,subject,from; | 97 | QString date,subject,from; |
98 | 98 | ||
99 | if ( err == MAILIMAP_NO_ERROR ) { | 99 | if ( err == MAILIMAP_NO_ERROR ) { |
100 | current = clist_begin(result); | 100 | current = clist_begin(result); |
101 | mailimap_msg_att * msg_att; | 101 | mailimap_msg_att * msg_att; |
102 | int i = 0; | 102 | int i = 0; |
103 | while ( current != 0 ) { | 103 | while ( current != 0 ) { |
104 | ++i; | 104 | ++i; |
105 | msg_att = (mailimap_msg_att*)current->data; | 105 | msg_att = (mailimap_msg_att*)current->data; |
106 | RecMail*m = parse_list_result(msg_att); | 106 | RecMail*m = parse_list_result(msg_att); |
107 | if (m) { | 107 | if (m) { |
108 | m->setNumber(i); | 108 | m->setNumber(i); |
109 | target.append(m); | 109 | target.append(m); |
110 | } | 110 | } |
111 | current = current->next; | 111 | current = current->next; |
112 | } | 112 | } |
113 | } else { | 113 | } else { |
114 | qDebug("Error fetching headers: %s",imap->response); | 114 | qDebug("Error fetching headers: %s",imap->response); |
115 | } | 115 | } |
116 | 116 | ||
117 | err = mailimap_logout( imap ); | 117 | err = mailimap_logout( imap ); |
118 | err = mailimap_close( imap ); | 118 | err = mailimap_close( imap ); |
119 | clist_free(result); | 119 | clist_free(result); |
120 | mailimap_free( imap ); | 120 | mailimap_free( imap ); |
121 | } | 121 | } |
122 | 122 | ||
123 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 123 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
124 | { | 124 | { |
125 | const char *server, *user, *pass, *path, *mask; | 125 | const char *server, *user, *pass, *path, *mask; |
126 | uint16_t port; | 126 | uint16_t port; |
127 | int err = MAILIMAP_NO_ERROR; | 127 | int err = MAILIMAP_NO_ERROR; |
128 | clist *result; | 128 | clist *result; |
129 | clistcell *current; | 129 | clistcell *current; |
130 | 130 | ||
131 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 131 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
132 | folders->setAutoDelete( true ); | 132 | folders->setAutoDelete( true ); |
133 | 133 | ||
134 | server = account->getServer().latin1(); | 134 | server = account->getServer().latin1(); |
135 | port = account->getPort().toUInt(); | 135 | port = account->getPort().toUInt(); |
136 | user = account->getUser().latin1(); | 136 | user = account->getUser().latin1(); |
137 | pass = account->getPassword().latin1(); | 137 | pass = account->getPassword().latin1(); |
138 | path = account->getPrefix().latin1(); | 138 | path = account->getPrefix().latin1(); |
139 | 139 | ||
140 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 140 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
141 | if ( imap == NULL ) { | 141 | if ( imap == NULL ) { |
142 | qDebug("error mailimap_new"); | 142 | qDebug("error mailimap_new"); |
143 | return folders; | 143 | return folders; |
144 | } | 144 | } |
145 | 145 | ||
146 | err = mailimap_socket_connect( imap, (char*)server, port ); | 146 | err = mailimap_socket_connect( imap, (char*)server, port ); |
147 | if ( err != MAILIMAP_NO_ERROR && | 147 | if ( err != MAILIMAP_NO_ERROR && |
148 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 148 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
149 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 149 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
150 | mailimap_free(imap); | 150 | mailimap_free(imap); |
151 | qDebug("error imap_socket_connect: %s",imap->response); | 151 | qDebug("error imap_socket_connect: %s",imap->response); |
152 | return folders; | 152 | return folders; |
153 | } | 153 | } |
154 | 154 | ||
155 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 155 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
156 | if ( err != MAILIMAP_NO_ERROR ) { | 156 | if ( err != MAILIMAP_NO_ERROR ) { |
157 | mailimap_free(imap); | 157 | mailimap_free(imap); |
158 | qDebug("error logging in: %s",imap->response); | 158 | qDebug("error logging in: %s",imap->response); |
159 | return folders; | 159 | return folders; |
160 | } | 160 | } |
161 | /* | 161 | /* |
162 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 162 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
163 | * We must not forget to filter them out in next loop! | 163 | * We must not forget to filter them out in next loop! |
164 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 164 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
165 | */ | 165 | */ |
166 | QString temp; | 166 | QString temp; |
167 | mask = "INBOX" ; | 167 | mask = "INBOX" ; |
168 | result = clist_new(); | 168 | result = clist_new(); |
169 | mailimap_mailbox_list *list; | 169 | mailimap_mailbox_list *list; |
170 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); | 170 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); |
171 | if ( err == MAILIMAP_NO_ERROR ) { | 171 | if ( err == MAILIMAP_NO_ERROR ) { |
172 | current = result->first; | 172 | current = result->first; |
173 | for ( int i = result->count; i > 0; i-- ) { | 173 | for ( int i = result->count; i > 0; i-- ) { |
174 | list = (mailimap_mailbox_list *) current->data; | 174 | list = (mailimap_mailbox_list *) current->data; |
175 | // it is better use the deep copy mechanism of qt itself | 175 | // it is better use the deep copy mechanism of qt itself |
176 | // instead of using strdup! | 176 | // instead of using strdup! |
177 | temp = list->mb; | 177 | temp = list->mb; |
178 | folders->append( new IMAPFolder(temp)); | 178 | folders->append( new IMAPFolder(temp)); |
179 | current = current->next; | 179 | current = current->next; |
180 | } | 180 | } |
181 | } else { | 181 | } else { |
182 | qDebug("error fetching folders: %s",imap->response); | 182 | qDebug("error fetching folders: %s",imap->response); |
183 | } | 183 | } |
184 | mailimap_list_result_free( result ); | 184 | mailimap_list_result_free( result ); |
185 | 185 | ||
186 | /* | 186 | /* |
187 | * second stage - get the other then inbox folders | 187 | * second stage - get the other then inbox folders |
188 | */ | 188 | */ |
189 | mask = "*" ; | 189 | mask = "*" ; |
190 | result = clist_new(); | 190 | result = clist_new(); |
191 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); | 191 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); |
192 | if ( err == MAILIMAP_NO_ERROR ) { | 192 | if ( err == MAILIMAP_NO_ERROR ) { |
193 | current = result->first; | 193 | current = result->first; |
194 | for ( int i = result->count; i > 0; i-- ) { | 194 | for ( int i = result->count; i > 0; i-- ) { |
195 | list = (mailimap_mailbox_list *) current->data; | 195 | list = (mailimap_mailbox_list *) current->data; |
196 | // it is better use the deep copy mechanism of qt itself | 196 | // it is better use the deep copy mechanism of qt itself |
197 | // instead of using strdup! | 197 | // instead of using strdup! |
198 | temp = list->mb; | 198 | temp = list->mb; |
199 | current = current->next; | 199 | current = current->next; |
200 | if (temp.lower()=="inbox") | 200 | if (temp.lower()=="inbox") |
201 | continue; | 201 | continue; |
202 | folders->append(new IMAPFolder(temp)); | 202 | folders->append(new IMAPFolder(temp)); |
203 | 203 | ||
204 | } | 204 | } |
205 | } else { | 205 | } else { |
206 | qDebug("error fetching folders"); | 206 | qDebug("error fetching folders"); |
207 | } | 207 | } |
208 | mailimap_list_result_free( result ); | 208 | mailimap_list_result_free( result ); |
209 | err = mailimap_logout( imap ); | 209 | err = mailimap_logout( imap ); |
210 | err = mailimap_close( imap ); | 210 | err = mailimap_close( imap ); |
211 | mailimap_free( imap ); | 211 | mailimap_free( imap ); |
212 | return folders; | 212 | return folders; |
213 | } | 213 | } |
214 | 214 | ||
215 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 215 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
216 | { | 216 | { |
217 | RecMail * m = 0; | 217 | RecMail * m = 0; |
218 | mailimap_msg_att_item *item=0; | 218 | mailimap_msg_att_item *item=0; |
219 | bool named_from = false; | 219 | bool named_from = false; |
220 | QString from,date,subject; | 220 | QString from,date,subject; |
221 | date = from = subject = ""; | 221 | date = from = subject = ""; |
222 | clistcell *current,*c,*cf, *current_from = NULL; | 222 | clistcell *current,*c,*cf, *current_from = NULL; |
223 | mailimap_address * current_address = NULL; | 223 | mailimap_address * current_address = NULL; |
224 | mailimap_msg_att_dynamic*flist; | 224 | mailimap_msg_att_dynamic*flist; |
225 | mailimap_flag_fetch*cflag; | 225 | mailimap_flag_fetch*cflag; |
226 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
227 | 227 | ||
228 | if (!m_att) { | 228 | if (!m_att) { |
229 | return m; | 229 | return m; |
230 | } | 230 | } |
231 | 231 | ||
232 | #if 0 | 232 | #if 0 |
233 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | 233 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ |
234 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | 234 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ |
235 | #endif | 235 | #endif |
236 | c = clist_begin(m_att->list); | 236 | c = clist_begin(m_att->list); |
237 | while ( c ) { | 237 | while ( c ) { |
238 | current = c; | 238 | current = c; |
239 | c = c->next; | 239 | c = c->next; |
240 | item = (mailimap_msg_att_item*)current->data; | 240 | item = (mailimap_msg_att_item*)current->data; |
241 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 241 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
242 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | 242 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; |
243 | if (!flist->list) { | 243 | if (!flist->list) { |
244 | continue; | 244 | continue; |
245 | } | 245 | } |
246 | cf = flist->list->first; | 246 | cf = flist->list->first; |
247 | while (cf) { | 247 | while (cf) { |
248 | cflag = (mailimap_flag_fetch*)cf->data; | 248 | cflag = (mailimap_flag_fetch*)cf->data; |
249 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | 249 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { |
250 | switch (cflag->flag->type) { | 250 | switch (cflag->flag->type) { |
251 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 251 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
252 | mFlags.setBit(FLAG_ANSWERED); | 252 | mFlags.setBit(FLAG_ANSWERED); |
253 | break; | 253 | break; |
254 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 254 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
255 | mFlags.setBit(FLAG_FLAGGED); | 255 | mFlags.setBit(FLAG_FLAGGED); |
256 | break; | 256 | break; |
257 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 257 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
258 | mFlags.setBit(FLAG_DELETED); | 258 | mFlags.setBit(FLAG_DELETED); |
259 | break; | 259 | break; |
260 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 260 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
261 | mFlags.setBit(FLAG_SEEN); | 261 | mFlags.setBit(FLAG_SEEN); |
262 | break; | 262 | break; |
263 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 263 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
264 | mFlags.setBit(FLAG_DRAFT); | 264 | mFlags.setBit(FLAG_DRAFT); |
265 | break; | 265 | break; |
266 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 266 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
267 | break; | 267 | break; |
268 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 268 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
269 | break; | 269 | break; |
270 | default: | 270 | default: |
271 | break; | 271 | break; |
272 | } | 272 | } |
273 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | 273 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { |
274 | mFlags.setBit(FLAG_RECENT); | 274 | mFlags.setBit(FLAG_RECENT); |
275 | } | 275 | } |
276 | 276 | ||
277 | cf = cf->next; | 277 | cf = cf->next; |
278 | } | 278 | } |
279 | continue; | 279 | continue; |
280 | } | 280 | } |
281 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 281 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { |
282 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | 282 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); |
283 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | 283 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { |
284 | mailimap_envelope * head = item->msg_att_static->env; | 284 | mailimap_envelope * head = item->msg_att_static->env; |
285 | date = head->date; | 285 | date = head->date; |
286 | subject = head->subject; | 286 | subject = head->subject; |
287 | if (head->from!=NULL) | 287 | if (head->from!=NULL) |
288 | current_from = head->from->list->first; | 288 | current_from = head->from->list->first; |
289 | while (current_from != NULL) { | 289 | while (current_from != NULL) { |
290 | from = ""; | 290 | from = ""; |
291 | named_from = false; | 291 | named_from = false; |
292 | current_address=(mailimap_address*)current_from->data; | 292 | current_address=(mailimap_address*)current_from->data; |
293 | current_from = current_from->next; | 293 | current_from = current_from->next; |
294 | if (current_address->personal_name){ | 294 | if (current_address->personal_name){ |
295 | from+=QString(current_address->personal_name); | 295 | from+=QString(current_address->personal_name); |
296 | from+=" "; | 296 | from+=" "; |
297 | named_from = true; | 297 | named_from = true; |
298 | } | 298 | } |
299 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | 299 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { |
300 | from+="<"; | 300 | from+="<"; |
301 | } | 301 | } |
302 | if (current_address->mailbox_name) { | 302 | if (current_address->mailbox_name) { |
303 | from+=QString(current_address->mailbox_name); | 303 | from+=QString(current_address->mailbox_name); |
304 | from+="@"; | 304 | from+="@"; |
305 | } | 305 | } |
306 | if (current_address->host_name) { | 306 | if (current_address->host_name) { |
307 | from+=QString(current_address->host_name); | 307 | from+=QString(current_address->host_name); |
308 | } | 308 | } |
309 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | 309 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { |
310 | from+=">"; | 310 | from+=">"; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | 313 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", |
314 | from.latin1(), | 314 | from.latin1(), |
315 | subject.latin1(),date.latin1()); | 315 | subject.latin1(),date.latin1()); |
316 | m = new RecMail(); | 316 | m = new RecMail(); |
317 | m->setSubject(subject); | 317 | m->setSubject(subject); |
318 | m->setFrom(from); | 318 | m->setFrom(from); |
319 | m->setDate(date); | 319 | m->setDate(date); |
320 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 320 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
321 | mailimap_date_time*d = item->msg_att_static->internal_date; | 321 | mailimap_date_time*d = item->msg_att_static->internal_date; |
322 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); | 322 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); |
323 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); | 323 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); |
324 | qDebug(da.toString()); | 324 | qDebug(da.toString()); |
325 | } else { | 325 | } else { |
326 | qDebug("Another type"); | 326 | qDebug("Another type"); |
327 | } | 327 | } |
328 | } | 328 | } |
329 | /* msg is already deleted */ | 329 | /* msg is already deleted */ |
330 | if (mFlags.testBit(FLAG_DELETED) && m) { | 330 | if (mFlags.testBit(FLAG_DELETED) && m) { |
331 | delete m; | 331 | delete m; |
332 | m = 0; | 332 | m = 0; |
333 | } | 333 | } |
334 | if (m) { | 334 | if (m) { |
335 | m->setFlags(mFlags); | 335 | m->setFlags(mFlags); |
336 | } | 336 | } |
337 | return m; | 337 | return m; |
338 | } | 338 | } |
339 | 339 | ||
340 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) | 340 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) |
341 | { | 341 | { |
342 | QString body = ""; | 342 | QString body = ""; |
343 | const char *server, *user, *pass, *mb; | 343 | const char *server, *user, *pass, *mb; |
344 | uint16_t port; | 344 | uint16_t port; |
345 | int err = MAILIMAP_NO_ERROR; | 345 | int err = MAILIMAP_NO_ERROR; |
346 | clist *result; | 346 | clist *result; |
347 | clistcell *current; | 347 | clistcell *current; |
348 | mailimap_fetch_att *fetchAtt; | 348 | mailimap_fetch_att *fetchAtt; |
349 | mailimap_fetch_type *fetchType; | 349 | mailimap_fetch_type *fetchType; |
350 | mailimap_set *set; | 350 | mailimap_set *set; |
351 | 351 | ||
352 | mb = mailbox.latin1(); | 352 | mb = mailbox.latin1(); |
353 | server = account->getServer().latin1(); | 353 | server = account->getServer().latin1(); |
354 | port = account->getPort().toUInt(); | 354 | port = account->getPort().toUInt(); |
355 | user = account->getUser().latin1(); | 355 | user = account->getUser().latin1(); |
356 | pass = account->getPassword().latin1(); | 356 | pass = account->getPassword().latin1(); |
357 | 357 | ||
358 | mailimap *imap = mailimap_new( 20, &imap_progress ); | 358 | mailimap *imap = mailimap_new( 20, &imap_progress ); |
359 | if ( imap == NULL ) { | 359 | if ( imap == NULL ) { |
360 | qDebug("IMAP Memory error"); | 360 | qDebug("IMAP Memory error"); |
361 | return body; | 361 | return body; |
362 | } | 362 | } |
363 | 363 | ||
364 | /* connect */ | 364 | /* connect */ |
365 | err = mailimap_socket_connect( imap, (char*)server, port ); | 365 | err = mailimap_socket_connect( imap, (char*)server, port ); |
366 | if ( err != MAILIMAP_NO_ERROR && | 366 | if ( err != MAILIMAP_NO_ERROR && |
367 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 367 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
368 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 368 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
369 | qDebug("error connecting server: %s",imap->response); | 369 | qDebug("error connecting server: %s",imap->response); |
370 | mailimap_free( imap ); | 370 | mailimap_free( imap ); |
371 | return body; | 371 | return body; |
372 | } | 372 | } |
373 | 373 | ||
374 | /* login */ | 374 | /* login */ |
375 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | 375 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); |
376 | if ( err != MAILIMAP_NO_ERROR ) { | 376 | if ( err != MAILIMAP_NO_ERROR ) { |
377 | qDebug("error logging in imap: %s",imap->response); | 377 | qDebug("error logging in imap: %s",imap->response); |
378 | err = mailimap_close( imap ); | 378 | err = mailimap_close( imap ); |
379 | mailimap_free( imap ); | 379 | mailimap_free( imap ); |
380 | return body; | 380 | return body; |
381 | } | 381 | } |
382 | 382 | ||
383 | /* select mailbox READONLY for operations */ | 383 | /* select mailbox READONLY for operations */ |
384 | err = mailimap_examine( imap, (char*)mb); | 384 | err = mailimap_examine( imap, (char*)mb); |
385 | if ( err != MAILIMAP_NO_ERROR ) { | 385 | if ( err != MAILIMAP_NO_ERROR ) { |
386 | qDebug("error selecting mailbox: %s",imap->response); | 386 | qDebug("error selecting mailbox: %s",imap->response); |
387 | err = mailimap_logout( imap ); | 387 | err = mailimap_logout( imap ); |
388 | err = mailimap_close( imap ); | 388 | err = mailimap_close( imap ); |
389 | mailimap_free( imap ); | 389 | mailimap_free( imap ); |
390 | return body; | 390 | return body; |
391 | } | 391 | } |
392 | result = clist_new(); | 392 | result = clist_new(); |
393 | /* the range has to start at 1!!! not with 0!!!! */ | 393 | /* the range has to start at 1!!! not with 0!!!! */ |
394 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 394 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
395 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | 395 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); |
396 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 396 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
397 | err = mailimap_fetch( imap, set, fetchType, &result ); | 397 | err = mailimap_fetch( imap, set, fetchType, &result ); |
398 | mailimap_set_free( set ); | 398 | mailimap_set_free( set ); |
399 | mailimap_fetch_type_free( fetchType ); | 399 | mailimap_fetch_type_free( fetchType ); |
400 | 400 | ||
401 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 401 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
402 | mailimap_msg_att * msg_att; | 402 | mailimap_msg_att * msg_att; |
403 | msg_att = (mailimap_msg_att*)current->data; | 403 | msg_att = (mailimap_msg_att*)current->data; |
404 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 404 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
405 | 405 | ||
406 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | 406 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { |
407 | body = item->msg_att_static->rfc822_text; | 407 | body = item->msg_att_static->rfc822_text; |
408 | } | 408 | } |
409 | } else { | 409 | } else { |
410 | qDebug("error fetching text: %s",imap->response); | 410 | qDebug("error fetching text: %s",imap->response); |
411 | } | 411 | } |
412 | 412 | ||
413 | err = mailimap_logout( imap ); | 413 | err = mailimap_logout( imap ); |
414 | err = mailimap_close( imap ); | 414 | err = mailimap_close( imap ); |
415 | mailimap_free( imap ); | 415 | mailimap_free( imap ); |
416 | clist_free(result); | 416 | clist_free(result); |
417 | 417 | ||
418 | return body; | 418 | return body; |
419 | } | 419 | } |
420 | 420 | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h new file mode 100644 index 0000000..65c36e0 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef __IMAPWRAPPER | ||
2 | #define __IMAPWRAPPER | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | #include <libetpan/mailimap.h> | ||
6 | |||
7 | class IMAPwrapper : public QObject | ||
8 | { | ||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | IMAPwrapper( IMAPaccount *a ); | ||
13 | QList<IMAPFolder>* listFolders(); | ||
14 | void listMessages(const QString & mailbox,Maillist&target ); | ||
15 | QString fetchBody(const QString & mailbox,const RecMail&mail); | ||
16 | |||
17 | protected: | ||
18 | RecMail*parse_list_result(mailimap_msg_att*); | ||
19 | |||
20 | private: | ||
21 | IMAPaccount *account; | ||
22 | |||
23 | }; | ||
24 | |||
25 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index f45eab7..955a8e2 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -1,183 +1,164 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <libetpan/mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <libetpan/mailimap.h> | ||
10 | #include <libetpan/mailstorage.h> | 9 | #include <libetpan/mailstorage.h> |
11 | #include <libetpan/maildriver.h> | 10 | #include <libetpan/maildriver.h> |
12 | #include <qbitarray.h> | 11 | #include <qbitarray.h> |
13 | #include <qdatetime.h> | 12 | #include <qdatetime.h> |
14 | 13 | ||
15 | #include "settings.h" | 14 | #include "settings.h" |
16 | 15 | ||
17 | class Attachment | 16 | class Attachment |
18 | { | 17 | { |
19 | public: | 18 | public: |
20 | Attachment( DocLnk lnk ); | 19 | Attachment( DocLnk lnk ); |
21 | virtual ~Attachment(){} | 20 | virtual ~Attachment(){} |
22 | const QString getFileName()const{ return doc.file(); } | 21 | const QString getFileName()const{ return doc.file(); } |
23 | const QString getName()const{ return doc.name(); } | 22 | const QString getName()const{ return doc.name(); } |
24 | const QString getMimeType()const{ return doc.type(); } | 23 | const QString getMimeType()const{ return doc.type(); } |
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 24 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
26 | const int getSize()const { return size; } | 25 | const int getSize()const { return size; } |
27 | DocLnk getDocLnk() { return doc; } | 26 | DocLnk getDocLnk() { return doc; } |
28 | 27 | ||
29 | protected: | 28 | protected: |
30 | DocLnk doc; | 29 | DocLnk doc; |
31 | int size; | 30 | int size; |
32 | 31 | ||
33 | }; | 32 | }; |
34 | 33 | ||
35 | #define FLAG_ANSWERED 0 | 34 | #define FLAG_ANSWERED 0 |
36 | #define FLAG_FLAGGED 1 | 35 | #define FLAG_FLAGGED 1 |
37 | #define FLAG_DELETED 2 | 36 | #define FLAG_DELETED 2 |
38 | #define FLAG_SEEN 3 | 37 | #define FLAG_SEEN 3 |
39 | #define FLAG_DRAFT 4 | 38 | #define FLAG_DRAFT 4 |
40 | #define FLAG_RECENT 5 | 39 | #define FLAG_RECENT 5 |
41 | 40 | ||
42 | /* a class to describe mails in a mailbox */ | 41 | /* a class to describe mails in a mailbox */ |
43 | class RecMail | 42 | class RecMail |
44 | { | 43 | { |
45 | public: | 44 | public: |
46 | RecMail(); | 45 | RecMail(); |
47 | virtual ~RecMail(){} | 46 | virtual ~RecMail(){} |
48 | 47 | ||
49 | const int getNumber()const{return msg_number;} | 48 | const int getNumber()const{return msg_number;} |
50 | void setNumber(int number){msg_number=number;} | 49 | void setNumber(int number){msg_number=number;} |
51 | const QString&getDate()const{ return date; } | 50 | const QString&getDate()const{ return date; } |
52 | void setDate( const QString&a ) { date = a; } | 51 | void setDate( const QString&a ) { date = a; } |
53 | const QString&getFrom()const{ return from; } | 52 | const QString&getFrom()const{ return from; } |
54 | void setFrom( const QString&a ) { from = a; } | 53 | void setFrom( const QString&a ) { from = a; } |
55 | const QString&getSubject()const { return subject; } | 54 | const QString&getSubject()const { return subject; } |
56 | void setSubject( const QString&s ) { subject = s; } | 55 | void setSubject( const QString&s ) { subject = s; } |
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 56 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
58 | const QBitArray&getFlags()const{return msg_flags;} | 57 | const QBitArray&getFlags()const{return msg_flags;} |
59 | 58 | ||
60 | #if 0 | 59 | #if 0 |
61 | void setDate(const QString&dstring); | 60 | void setDate(const QString&dstring); |
62 | void setDate(const QDateTime&date){mDate = date;} | 61 | void setDate(const QDateTime&date){mDate = date;} |
63 | QString getDate()const{return mDate.toString();} | 62 | QString getDate()const{return mDate.toString();} |
64 | #endif | 63 | #endif |
65 | protected: | 64 | protected: |
66 | QString subject,date,from; | 65 | QString subject,date,from; |
67 | int msg_number; | 66 | int msg_number; |
68 | QBitArray msg_flags; | 67 | QBitArray msg_flags; |
69 | #if 0 | 68 | #if 0 |
70 | QDateTime mDate; | 69 | QDateTime mDate; |
71 | #endif | 70 | #endif |
72 | }; | 71 | }; |
73 | 72 | ||
74 | typedef QList<RecMail> Maillist; | 73 | typedef QList<RecMail> Maillist; |
75 | 74 | ||
76 | class Mail | 75 | class Mail |
77 | { | 76 | { |
78 | public: | 77 | public: |
79 | Mail(); | 78 | Mail(); |
80 | /* Possible that this destructor must not be declared virtual | 79 | /* Possible that this destructor must not be declared virtual |
81 | * 'cause it seems that it will never have some child classes. | 80 | * '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 | 81 | * in this case this object will not get a virtual table -> memory and |
83 | * speed will be a little bit better? | 82 | * speed will be a little bit better? |
84 | */ | 83 | */ |
85 | virtual ~Mail(){} | 84 | virtual ~Mail(){} |
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | 85 | void addAttachment( Attachment *att ) { attList.append( att ); } |
87 | const QList<Attachment>& getAttachments()const { return attList; } | 86 | const QList<Attachment>& getAttachments()const { return attList; } |
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 87 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
89 | const QString&getName()const { return name; } | 88 | const QString&getName()const { return name; } |
90 | void setName( QString s ) { name = s; } | 89 | void setName( QString s ) { name = s; } |
91 | const QString&getMail()const{ return mail; } | 90 | const QString&getMail()const{ return mail; } |
92 | void setMail( const QString&s ) { mail = s; } | 91 | void setMail( const QString&s ) { mail = s; } |
93 | const QString&getTo()const{ return to; } | 92 | const QString&getTo()const{ return to; } |
94 | void setTo( const QString&s ) { to = s; } | 93 | void setTo( const QString&s ) { to = s; } |
95 | const QString&getCC()const{ return cc; } | 94 | const QString&getCC()const{ return cc; } |
96 | void setCC( const QString&s ) { cc = s; } | 95 | void setCC( const QString&s ) { cc = s; } |
97 | const QString&getBCC()const { return bcc; } | 96 | const QString&getBCC()const { return bcc; } |
98 | void setBCC( const QString&s ) { bcc = s; } | 97 | void setBCC( const QString&s ) { bcc = s; } |
99 | const QString&getMessage()const { return message; } | 98 | const QString&getMessage()const { return message; } |
100 | void setMessage( const QString&s ) { message = s; } | 99 | void setMessage( const QString&s ) { message = s; } |
101 | const QString&getSubject()const { return subject; } | 100 | const QString&getSubject()const { return subject; } |
102 | void setSubject( const QString&s ) { subject = s; } | 101 | void setSubject( const QString&s ) { subject = s; } |
103 | const QString&getReply()const{ return reply; } | 102 | const QString&getReply()const{ return reply; } |
104 | void setReply( const QString&a ) { reply = a; } | 103 | void setReply( const QString&a ) { reply = a; } |
105 | 104 | ||
106 | private: | 105 | private: |
107 | QList<Attachment> attList; | 106 | QList<Attachment> attList; |
108 | QString name, mail, to, cc, bcc, reply, subject, message; | 107 | QString name, mail, to, cc, bcc, reply, subject, message; |
109 | }; | 108 | }; |
110 | 109 | ||
111 | class Folder : public QObject | 110 | class Folder : public QObject |
112 | { | 111 | { |
113 | Q_OBJECT | 112 | Q_OBJECT |
114 | 113 | ||
115 | public: | 114 | public: |
116 | Folder( const QString&init_name ); | 115 | Folder( const QString&init_name ); |
117 | const QString&getDisplayName()const { return nameDisplay; } | 116 | const QString&getDisplayName()const { return nameDisplay; } |
118 | const QString&getName()const { return name; } | 117 | const QString&getName()const { return name; } |
119 | virtual bool may_select()const{return true;}; | 118 | virtual bool may_select()const{return true;}; |
120 | 119 | ||
121 | private: | 120 | private: |
122 | QString nameDisplay, name; | 121 | QString nameDisplay, name; |
123 | 122 | ||
124 | }; | 123 | }; |
125 | 124 | ||
126 | class IMAPFolder : public Folder | 125 | class IMAPFolder : public Folder |
127 | { | 126 | { |
128 | public: | 127 | public: |
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 128 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} |
130 | virtual bool may_select()const{return m_MaySelect;} | 129 | virtual bool may_select()const{return m_MaySelect;} |
131 | private: | 130 | private: |
132 | bool m_MaySelect; | 131 | bool m_MaySelect; |
133 | }; | 132 | }; |
134 | 133 | ||
135 | class MailWrapper : public QObject | 134 | class MailWrapper : public QObject |
136 | { | 135 | { |
137 | Q_OBJECT | 136 | Q_OBJECT |
138 | 137 | ||
139 | public: | 138 | public: |
140 | MailWrapper( Settings *s ); | 139 | MailWrapper( Settings *s ); |
141 | void sendMail( Mail mail ); | 140 | void sendMail( Mail mail ); |
142 | 141 | ||
143 | private: | 142 | private: |
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 143 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
145 | mailimf_address_list *parseAddresses(const QString&addr ); | 144 | mailimf_address_list *parseAddresses(const QString&addr ); |
146 | mailimf_fields *createImfFields( Mail *mail ); | 145 | mailimf_fields *createImfFields( Mail *mail ); |
147 | mailmime *buildTxtPart( QString str ); | 146 | mailmime *buildTxtPart( QString str ); |
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | 147 | mailmime *buildFilePart( QString filename, QString mimetype ); |
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | 148 | void addFileParts( mailmime *message, QList<Attachment> files ); |
150 | mailmime *createMimeMail( Mail *mail ); | 149 | mailmime *createMimeMail( Mail *mail ); |
151 | void smtpSend( mailmime *mail ); | 150 | void smtpSend( mailmime *mail ); |
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | 151 | mailimf_field *getField( mailimf_fields *fields, int type ); |
153 | clist *createRcptList( mailimf_fields *fields ); | 152 | clist *createRcptList( mailimf_fields *fields ); |
154 | char *getFrom( mailmime *mail ); | 153 | char *getFrom( mailmime *mail ); |
155 | SMTPaccount *getAccount( QString from ); | 154 | SMTPaccount *getAccount( QString from ); |
156 | void writeToFile( QString file, mailmime *mail ); | 155 | void writeToFile( QString file, mailmime *mail ); |
157 | void readFromFile( QString file, char **data, size_t *size ); | 156 | void readFromFile( QString file, char **data, size_t *size ); |
158 | static QString mailsmtpError( int err ); | 157 | static QString mailsmtpError( int err ); |
159 | static QString getTmpFile(); | 158 | static QString getTmpFile(); |
160 | 159 | ||
161 | Settings *settings; | 160 | Settings *settings; |
162 | 161 | ||
163 | }; | 162 | }; |
164 | 163 | ||
165 | class IMAPwrapper : public QObject | ||
166 | { | ||
167 | Q_OBJECT | ||
168 | |||
169 | public: | ||
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 | |||
175 | protected: | ||
176 | RecMail*parse_list_result(mailimap_msg_att*); | ||
177 | |||
178 | private: | ||
179 | IMAPaccount *account; | ||
180 | |||
181 | }; | ||
182 | |||
183 | #endif | 164 | #endif |
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index 46a476d..2142cdc 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro | |||
@@ -1,39 +1,40 @@ | |||
1 | CONFIG += qt warn_on debug quick-app | 1 | CONFIG += qt warn_on debug quick-app |
2 | 2 | ||
3 | HEADERS = defines.h \ | 3 | HEADERS = defines.h \ |
4 | logindialog.h \ | 4 | logindialog.h \ |
5 | settings.h \ | 5 | settings.h \ |
6 | editaccounts.h \ | 6 | editaccounts.h \ |
7 | mailwrapper.h \ | 7 | mailwrapper.h \ |
8 | composemail.h \ | 8 | composemail.h \ |
9 | accountview.h \ | 9 | accountview.h \ |
10 | mainwindow.h \ | 10 | mainwindow.h \ |
11 | opiemail.h | 11 | opiemail.h \ |
12 | imapwrapper.h | ||
12 | 13 | ||
13 | SOURCES = main.cpp \ | 14 | SOURCES = main.cpp \ |
14 | opiemail.cpp \ | 15 | opiemail.cpp \ |
15 | mainwindow.cpp \ | 16 | mainwindow.cpp \ |
16 | accountview.cpp \ | 17 | accountview.cpp \ |
17 | composemail.cpp \ | 18 | composemail.cpp \ |
18 | mailwrapper.cpp \ | 19 | mailwrapper.cpp \ |
19 | imapwrapper.cpp \ | 20 | imapwrapper.cpp \ |
20 | addresspicker.cpp \ | 21 | addresspicker.cpp \ |
21 | editaccounts.cpp \ | 22 | editaccounts.cpp \ |
22 | logindialog.cpp \ | 23 | logindialog.cpp \ |
23 | settings.cpp | 24 | settings.cpp |
24 | 25 | ||
25 | INTERFACES = editaccountsui.ui \ | 26 | INTERFACES = editaccountsui.ui \ |
26 | selectmailtypeui.ui \ | 27 | selectmailtypeui.ui \ |
27 | imapconfigui.ui \ | 28 | imapconfigui.ui \ |
28 | pop3configui.ui \ | 29 | pop3configui.ui \ |
29 | nntpconfigui.ui \ | 30 | nntpconfigui.ui \ |
30 | smtpconfigui.ui \ | 31 | smtpconfigui.ui \ |
31 | addresspickerui.ui \ | 32 | addresspickerui.ui \ |
32 | logindialogui.ui \ | 33 | logindialogui.ui \ |
33 | composemailui.ui | 34 | composemailui.ui |
34 | 35 | ||
35 | INCLUDEPATH += $(OPIEDIR)/include | 36 | INCLUDEPATH += $(OPIEDIR)/include |
36 | LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb | 37 | LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb |
37 | TARGET = opiemail | 38 | TARGET = opiemail |
38 | 39 | ||
39 | include ( $(OPIEDIR)/include.pro ) | 40 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h index f45eab7..955a8e2 100644 --- a/noncore/net/mail/mailwrapper.h +++ b/noncore/net/mail/mailwrapper.h | |||
@@ -1,183 +1,164 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <libetpan/mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <libetpan/mailimap.h> | ||
10 | #include <libetpan/mailstorage.h> | 9 | #include <libetpan/mailstorage.h> |
11 | #include <libetpan/maildriver.h> | 10 | #include <libetpan/maildriver.h> |
12 | #include <qbitarray.h> | 11 | #include <qbitarray.h> |
13 | #include <qdatetime.h> | 12 | #include <qdatetime.h> |
14 | 13 | ||
15 | #include "settings.h" | 14 | #include "settings.h" |
16 | 15 | ||
17 | class Attachment | 16 | class Attachment |
18 | { | 17 | { |
19 | public: | 18 | public: |
20 | Attachment( DocLnk lnk ); | 19 | Attachment( DocLnk lnk ); |
21 | virtual ~Attachment(){} | 20 | virtual ~Attachment(){} |
22 | const QString getFileName()const{ return doc.file(); } | 21 | const QString getFileName()const{ return doc.file(); } |
23 | const QString getName()const{ return doc.name(); } | 22 | const QString getName()const{ return doc.name(); } |
24 | const QString getMimeType()const{ return doc.type(); } | 23 | const QString getMimeType()const{ return doc.type(); } |
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 24 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
26 | const int getSize()const { return size; } | 25 | const int getSize()const { return size; } |
27 | DocLnk getDocLnk() { return doc; } | 26 | DocLnk getDocLnk() { return doc; } |
28 | 27 | ||
29 | protected: | 28 | protected: |
30 | DocLnk doc; | 29 | DocLnk doc; |
31 | int size; | 30 | int size; |
32 | 31 | ||
33 | }; | 32 | }; |
34 | 33 | ||
35 | #define FLAG_ANSWERED 0 | 34 | #define FLAG_ANSWERED 0 |
36 | #define FLAG_FLAGGED 1 | 35 | #define FLAG_FLAGGED 1 |
37 | #define FLAG_DELETED 2 | 36 | #define FLAG_DELETED 2 |
38 | #define FLAG_SEEN 3 | 37 | #define FLAG_SEEN 3 |
39 | #define FLAG_DRAFT 4 | 38 | #define FLAG_DRAFT 4 |
40 | #define FLAG_RECENT 5 | 39 | #define FLAG_RECENT 5 |
41 | 40 | ||
42 | /* a class to describe mails in a mailbox */ | 41 | /* a class to describe mails in a mailbox */ |
43 | class RecMail | 42 | class RecMail |
44 | { | 43 | { |
45 | public: | 44 | public: |
46 | RecMail(); | 45 | RecMail(); |
47 | virtual ~RecMail(){} | 46 | virtual ~RecMail(){} |
48 | 47 | ||
49 | const int getNumber()const{return msg_number;} | 48 | const int getNumber()const{return msg_number;} |
50 | void setNumber(int number){msg_number=number;} | 49 | void setNumber(int number){msg_number=number;} |
51 | const QString&getDate()const{ return date; } | 50 | const QString&getDate()const{ return date; } |
52 | void setDate( const QString&a ) { date = a; } | 51 | void setDate( const QString&a ) { date = a; } |
53 | const QString&getFrom()const{ return from; } | 52 | const QString&getFrom()const{ return from; } |
54 | void setFrom( const QString&a ) { from = a; } | 53 | void setFrom( const QString&a ) { from = a; } |
55 | const QString&getSubject()const { return subject; } | 54 | const QString&getSubject()const { return subject; } |
56 | void setSubject( const QString&s ) { subject = s; } | 55 | void setSubject( const QString&s ) { subject = s; } |
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 56 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
58 | const QBitArray&getFlags()const{return msg_flags;} | 57 | const QBitArray&getFlags()const{return msg_flags;} |
59 | 58 | ||
60 | #if 0 | 59 | #if 0 |
61 | void setDate(const QString&dstring); | 60 | void setDate(const QString&dstring); |
62 | void setDate(const QDateTime&date){mDate = date;} | 61 | void setDate(const QDateTime&date){mDate = date;} |
63 | QString getDate()const{return mDate.toString();} | 62 | QString getDate()const{return mDate.toString();} |
64 | #endif | 63 | #endif |
65 | protected: | 64 | protected: |
66 | QString subject,date,from; | 65 | QString subject,date,from; |
67 | int msg_number; | 66 | int msg_number; |
68 | QBitArray msg_flags; | 67 | QBitArray msg_flags; |
69 | #if 0 | 68 | #if 0 |
70 | QDateTime mDate; | 69 | QDateTime mDate; |
71 | #endif | 70 | #endif |
72 | }; | 71 | }; |
73 | 72 | ||
74 | typedef QList<RecMail> Maillist; | 73 | typedef QList<RecMail> Maillist; |
75 | 74 | ||
76 | class Mail | 75 | class Mail |
77 | { | 76 | { |
78 | public: | 77 | public: |
79 | Mail(); | 78 | Mail(); |
80 | /* Possible that this destructor must not be declared virtual | 79 | /* Possible that this destructor must not be declared virtual |
81 | * 'cause it seems that it will never have some child classes. | 80 | * '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 | 81 | * in this case this object will not get a virtual table -> memory and |
83 | * speed will be a little bit better? | 82 | * speed will be a little bit better? |
84 | */ | 83 | */ |
85 | virtual ~Mail(){} | 84 | virtual ~Mail(){} |
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | 85 | void addAttachment( Attachment *att ) { attList.append( att ); } |
87 | const QList<Attachment>& getAttachments()const { return attList; } | 86 | const QList<Attachment>& getAttachments()const { return attList; } |
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 87 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
89 | const QString&getName()const { return name; } | 88 | const QString&getName()const { return name; } |
90 | void setName( QString s ) { name = s; } | 89 | void setName( QString s ) { name = s; } |
91 | const QString&getMail()const{ return mail; } | 90 | const QString&getMail()const{ return mail; } |
92 | void setMail( const QString&s ) { mail = s; } | 91 | void setMail( const QString&s ) { mail = s; } |
93 | const QString&getTo()const{ return to; } | 92 | const QString&getTo()const{ return to; } |
94 | void setTo( const QString&s ) { to = s; } | 93 | void setTo( const QString&s ) { to = s; } |
95 | const QString&getCC()const{ return cc; } | 94 | const QString&getCC()const{ return cc; } |
96 | void setCC( const QString&s ) { cc = s; } | 95 | void setCC( const QString&s ) { cc = s; } |
97 | const QString&getBCC()const { return bcc; } | 96 | const QString&getBCC()const { return bcc; } |
98 | void setBCC( const QString&s ) { bcc = s; } | 97 | void setBCC( const QString&s ) { bcc = s; } |
99 | const QString&getMessage()const { return message; } | 98 | const QString&getMessage()const { return message; } |
100 | void setMessage( const QString&s ) { message = s; } | 99 | void setMessage( const QString&s ) { message = s; } |
101 | const QString&getSubject()const { return subject; } | 100 | const QString&getSubject()const { return subject; } |
102 | void setSubject( const QString&s ) { subject = s; } | 101 | void setSubject( const QString&s ) { subject = s; } |
103 | const QString&getReply()const{ return reply; } | 102 | const QString&getReply()const{ return reply; } |
104 | void setReply( const QString&a ) { reply = a; } | 103 | void setReply( const QString&a ) { reply = a; } |
105 | 104 | ||
106 | private: | 105 | private: |
107 | QList<Attachment> attList; | 106 | QList<Attachment> attList; |
108 | QString name, mail, to, cc, bcc, reply, subject, message; | 107 | QString name, mail, to, cc, bcc, reply, subject, message; |
109 | }; | 108 | }; |
110 | 109 | ||
111 | class Folder : public QObject | 110 | class Folder : public QObject |
112 | { | 111 | { |
113 | Q_OBJECT | 112 | Q_OBJECT |
114 | 113 | ||
115 | public: | 114 | public: |
116 | Folder( const QString&init_name ); | 115 | Folder( const QString&init_name ); |
117 | const QString&getDisplayName()const { return nameDisplay; } | 116 | const QString&getDisplayName()const { return nameDisplay; } |
118 | const QString&getName()const { return name; } | 117 | const QString&getName()const { return name; } |
119 | virtual bool may_select()const{return true;}; | 118 | virtual bool may_select()const{return true;}; |
120 | 119 | ||
121 | private: | 120 | private: |
122 | QString nameDisplay, name; | 121 | QString nameDisplay, name; |
123 | 122 | ||
124 | }; | 123 | }; |
125 | 124 | ||
126 | class IMAPFolder : public Folder | 125 | class IMAPFolder : public Folder |
127 | { | 126 | { |
128 | public: | 127 | public: |
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 128 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} |
130 | virtual bool may_select()const{return m_MaySelect;} | 129 | virtual bool may_select()const{return m_MaySelect;} |
131 | private: | 130 | private: |
132 | bool m_MaySelect; | 131 | bool m_MaySelect; |
133 | }; | 132 | }; |
134 | 133 | ||
135 | class MailWrapper : public QObject | 134 | class MailWrapper : public QObject |
136 | { | 135 | { |
137 | Q_OBJECT | 136 | Q_OBJECT |
138 | 137 | ||
139 | public: | 138 | public: |
140 | MailWrapper( Settings *s ); | 139 | MailWrapper( Settings *s ); |
141 | void sendMail( Mail mail ); | 140 | void sendMail( Mail mail ); |
142 | 141 | ||
143 | private: | 142 | private: |
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 143 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
145 | mailimf_address_list *parseAddresses(const QString&addr ); | 144 | mailimf_address_list *parseAddresses(const QString&addr ); |
146 | mailimf_fields *createImfFields( Mail *mail ); | 145 | mailimf_fields *createImfFields( Mail *mail ); |
147 | mailmime *buildTxtPart( QString str ); | 146 | mailmime *buildTxtPart( QString str ); |
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | 147 | mailmime *buildFilePart( QString filename, QString mimetype ); |
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | 148 | void addFileParts( mailmime *message, QList<Attachment> files ); |
150 | mailmime *createMimeMail( Mail *mail ); | 149 | mailmime *createMimeMail( Mail *mail ); |
151 | void smtpSend( mailmime *mail ); | 150 | void smtpSend( mailmime *mail ); |
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | 151 | mailimf_field *getField( mailimf_fields *fields, int type ); |
153 | clist *createRcptList( mailimf_fields *fields ); | 152 | clist *createRcptList( mailimf_fields *fields ); |
154 | char *getFrom( mailmime *mail ); | 153 | char *getFrom( mailmime *mail ); |
155 | SMTPaccount *getAccount( QString from ); | 154 | SMTPaccount *getAccount( QString from ); |
156 | void writeToFile( QString file, mailmime *mail ); | 155 | void writeToFile( QString file, mailmime *mail ); |
157 | void readFromFile( QString file, char **data, size_t *size ); | 156 | void readFromFile( QString file, char **data, size_t *size ); |
158 | static QString mailsmtpError( int err ); | 157 | static QString mailsmtpError( int err ); |
159 | static QString getTmpFile(); | 158 | static QString getTmpFile(); |
160 | 159 | ||
161 | Settings *settings; | 160 | Settings *settings; |
162 | 161 | ||
163 | }; | 162 | }; |
164 | 163 | ||
165 | class IMAPwrapper : public QObject | ||
166 | { | ||
167 | Q_OBJECT | ||
168 | |||
169 | public: | ||
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 | |||
175 | protected: | ||
176 | RecMail*parse_list_result(mailimap_msg_att*); | ||
177 | |||
178 | private: | ||
179 | IMAPaccount *account; | ||
180 | |||
181 | }; | ||
182 | |||
183 | #endif | 164 | #endif |