-rw-r--r-- | noncore/net/mail/abstractmail.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 30 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 30 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 11 |
11 files changed, 81 insertions, 4 deletions
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index 0a1719d..62e0715 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h | |||
@@ -1,30 +1,31 @@ | |||
1 | #ifndef __abstract_mail_ | 1 | #ifndef __abstract_mail_ |
2 | #define __abstract_mail_ | 2 | #define __abstract_mail_ |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include "settings.h" | 5 | #include "settings.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | 13 | ||
14 | class AbstractMail:public QObject | 14 | class AbstractMail:public QObject |
15 | { | 15 | { |
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | public: | 17 | public: |
18 | AbstractMail(){}; | 18 | AbstractMail(){}; |
19 | virtual ~AbstractMail(){} | 19 | virtual ~AbstractMail(){} |
20 | virtual QList<Folder>* listFolders()=0; | 20 | virtual QList<Folder>* listFolders()=0; |
21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
22 | virtual RecBody fetchBody(const RecMail&mail)=0; | 22 | virtual RecBody fetchBody(const RecMail&mail)=0; |
23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; | 23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; |
24 | virtual void deleteMail(const RecMail&mail)=0; | 24 | virtual void deleteMail(const RecMail&mail)=0; |
25 | virtual void answeredMail(const RecMail&mail)=0; | ||
25 | 26 | ||
26 | static AbstractMail* getWrapper(IMAPaccount *a); | 27 | static AbstractMail* getWrapper(IMAPaccount *a); |
27 | static AbstractMail* getWrapper(POP3account *a); | 28 | static AbstractMail* getWrapper(POP3account *a); |
28 | }; | 29 | }; |
29 | 30 | ||
30 | #endif | 31 | #endif |
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 912a412..b253b49 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,741 +1,771 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if ( (bflags = list->mb_flag) ) { | 203 | if ( (bflags = list->mb_flag) ) { |
204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
206 | } | 206 | } |
207 | folders->append(new IMAPFolder(temp,selectable)); | 207 | folders->append(new IMAPFolder(temp,selectable)); |
208 | } | 208 | } |
209 | } else { | 209 | } else { |
210 | qDebug("error fetching folders %s",m_imap->imap_response); | 210 | qDebug("error fetching folders %s",m_imap->imap_response); |
211 | } | 211 | } |
212 | mailimap_list_result_free( result ); | 212 | mailimap_list_result_free( result ); |
213 | return folders; | 213 | return folders; |
214 | } | 214 | } |
215 | 215 | ||
216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
217 | { | 217 | { |
218 | RecMail * m = 0; | 218 | RecMail * m = 0; |
219 | mailimap_msg_att_item *item=0; | 219 | mailimap_msg_att_item *item=0; |
220 | clistcell *current,*c,*cf; | 220 | clistcell *current,*c,*cf; |
221 | mailimap_msg_att_dynamic*flist; | 221 | mailimap_msg_att_dynamic*flist; |
222 | mailimap_flag_fetch*cflag; | 222 | mailimap_flag_fetch*cflag; |
223 | int size; | 223 | int size; |
224 | QBitArray mFlags(7); | 224 | QBitArray mFlags(7); |
225 | QStringList addresslist; | 225 | QStringList addresslist; |
226 | 226 | ||
227 | if (!m_att) { | 227 | if (!m_att) { |
228 | return m; | 228 | return m; |
229 | } | 229 | } |
230 | m = new RecMail(); | 230 | m = new RecMail(); |
231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
232 | current = c; | 232 | current = c; |
233 | size = 0; | 233 | size = 0; |
234 | item = (mailimap_msg_att_item*)current->data; | 234 | item = (mailimap_msg_att_item*)current->data; |
235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
237 | if (!flist->att_list) { | 237 | if (!flist->att_list) { |
238 | continue; | 238 | continue; |
239 | } | 239 | } |
240 | cf = flist->att_list->first; | 240 | cf = flist->att_list->first; |
241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
242 | cflag = (mailimap_flag_fetch*)cf->data; | 242 | cflag = (mailimap_flag_fetch*)cf->data; |
243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
244 | switch (cflag->fl_flag->fl_type) { | 244 | switch (cflag->fl_flag->fl_type) { |
245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
246 | mFlags.setBit(FLAG_ANSWERED); | 246 | mFlags.setBit(FLAG_ANSWERED); |
247 | break; | 247 | break; |
248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
249 | mFlags.setBit(FLAG_FLAGGED); | 249 | mFlags.setBit(FLAG_FLAGGED); |
250 | break; | 250 | break; |
251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
252 | mFlags.setBit(FLAG_DELETED); | 252 | mFlags.setBit(FLAG_DELETED); |
253 | break; | 253 | break; |
254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
255 | mFlags.setBit(FLAG_SEEN); | 255 | mFlags.setBit(FLAG_SEEN); |
256 | break; | 256 | break; |
257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
258 | mFlags.setBit(FLAG_DRAFT); | 258 | mFlags.setBit(FLAG_DRAFT); |
259 | break; | 259 | break; |
260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
261 | break; | 261 | break; |
262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
263 | break; | 263 | break; |
264 | default: | 264 | default: |
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
268 | mFlags.setBit(FLAG_RECENT); | 268 | mFlags.setBit(FLAG_RECENT); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | continue; | 271 | continue; |
272 | } | 272 | } |
273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
275 | m->setDate(head->env_date); | 275 | m->setDate(head->env_date); |
276 | m->setSubject(head->env_subject); | 276 | m->setSubject(head->env_subject); |
277 | if (head->env_from!=NULL) { | 277 | if (head->env_from!=NULL) { |
278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
279 | if (addresslist.count()) { | 279 | if (addresslist.count()) { |
280 | m->setFrom(addresslist.first()); | 280 | m->setFrom(addresslist.first()); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | if (head->env_to!=NULL) { | 283 | if (head->env_to!=NULL) { |
284 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 284 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
285 | m->setTo(addresslist); | 285 | m->setTo(addresslist); |
286 | } | 286 | } |
287 | if (head->env_cc!=NULL) { | 287 | if (head->env_cc!=NULL) { |
288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
289 | m->setCC(addresslist); | 289 | m->setCC(addresslist); |
290 | } | 290 | } |
291 | if (head->env_bcc!=NULL) { | 291 | if (head->env_bcc!=NULL) { |
292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
293 | m->setBcc(addresslist); | 293 | m->setBcc(addresslist); |
294 | } | 294 | } |
295 | if (head->env_reply_to!=NULL) { | 295 | if (head->env_reply_to!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
297 | if (addresslist.count()) { | 297 | if (addresslist.count()) { |
298 | m->setReplyto(addresslist.first()); | 298 | m->setReplyto(addresslist.first()); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | m->setMsgid(QString(head->env_message_id)); | 301 | m->setMsgid(QString(head->env_message_id)); |
302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
304 | #if 0 | 304 | #if 0 |
305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
307 | qDebug(da.toString()); | 307 | qDebug(da.toString()); |
308 | #endif | 308 | #endif |
309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
310 | size = item->att_data.att_static->att_data.att_rfc822_size; | 310 | size = item->att_data.att_static->att_data.att_rfc822_size; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | /* msg is already deleted */ | 313 | /* msg is already deleted */ |
314 | if (mFlags.testBit(FLAG_DELETED) && m) { | 314 | if (mFlags.testBit(FLAG_DELETED) && m) { |
315 | delete m; | 315 | delete m; |
316 | m = 0; | 316 | m = 0; |
317 | } | 317 | } |
318 | if (m) { | 318 | if (m) { |
319 | m->setFlags(mFlags); | 319 | m->setFlags(mFlags); |
320 | m->setMsgsize(size); | 320 | m->setMsgsize(size); |
321 | } | 321 | } |
322 | return m; | 322 | return m; |
323 | } | 323 | } |
324 | 324 | ||
325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
326 | { | 326 | { |
327 | RecBody body; | 327 | RecBody body; |
328 | const char *mb; | 328 | const char *mb; |
329 | int err = MAILIMAP_NO_ERROR; | 329 | int err = MAILIMAP_NO_ERROR; |
330 | clist *result; | 330 | clist *result; |
331 | clistcell *current; | 331 | clistcell *current; |
332 | mailimap_fetch_att *fetchAtt; | 332 | mailimap_fetch_att *fetchAtt; |
333 | mailimap_fetch_type *fetchType; | 333 | mailimap_fetch_type *fetchType; |
334 | mailimap_set *set; | 334 | mailimap_set *set; |
335 | mailimap_body*body_desc; | 335 | mailimap_body*body_desc; |
336 | 336 | ||
337 | mb = mail.getMbox().latin1(); | 337 | mb = mail.getMbox().latin1(); |
338 | 338 | ||
339 | login(); | 339 | login(); |
340 | if (!m_imap) { | 340 | if (!m_imap) { |
341 | return body; | 341 | return body; |
342 | } | 342 | } |
343 | 343 | ||
344 | err = mailimap_select( m_imap, (char*)mb); | 344 | err = mailimap_select( m_imap, (char*)mb); |
345 | if ( err != MAILIMAP_NO_ERROR ) { | 345 | if ( err != MAILIMAP_NO_ERROR ) { |
346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
347 | return body; | 347 | return body; |
348 | } | 348 | } |
349 | 349 | ||
350 | result = clist_new(); | 350 | result = clist_new(); |
351 | /* the range has to start at 1!!! not with 0!!!! */ | 351 | /* the range has to start at 1!!! not with 0!!!! */ |
352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
356 | mailimap_set_free( set ); | 356 | mailimap_set_free( set ); |
357 | mailimap_fetch_type_free( fetchType ); | 357 | mailimap_fetch_type_free( fetchType ); |
358 | 358 | ||
359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
360 | mailimap_msg_att * msg_att; | 360 | mailimap_msg_att * msg_att; |
361 | msg_att = (mailimap_msg_att*)current->data; | 361 | msg_att = (mailimap_msg_att*)current->data; |
362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
363 | body_desc = item->att_data.att_static->att_data.att_body; | 363 | body_desc = item->att_data.att_static->att_data.att_body; |
364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
367 | qDebug("Mulitpart mail"); | 367 | qDebug("Mulitpart mail"); |
368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
369 | } | 369 | } |
370 | } else { | 370 | } else { |
371 | qDebug("error fetching body: %s",m_imap->imap_response); | 371 | qDebug("error fetching body: %s",m_imap->imap_response); |
372 | } | 372 | } |
373 | mailimap_fetch_list_free(result); | 373 | mailimap_fetch_list_free(result); |
374 | return body; | 374 | return body; |
375 | } | 375 | } |
376 | 376 | ||
377 | /* this routine is just called when the mail has only ONE part. | 377 | /* this routine is just called when the mail has only ONE part. |
378 | for filling the parts of a multi-part-message there are other | 378 | for filling the parts of a multi-part-message there are other |
379 | routines 'cause we can not simply fetch the whole body. */ | 379 | routines 'cause we can not simply fetch the whole body. */ |
380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
381 | { | 381 | { |
382 | if (!mailDescription) { | 382 | if (!mailDescription) { |
383 | return; | 383 | return; |
384 | } | 384 | } |
385 | QString sub,body_text; | 385 | QString sub,body_text; |
386 | RecPart singlePart; | 386 | RecPart singlePart; |
387 | QValueList<int> path; | 387 | QValueList<int> path; |
388 | fillSinglePart(singlePart,mailDescription); | 388 | fillSinglePart(singlePart,mailDescription); |
389 | switch (mailDescription->bd_type) { | 389 | switch (mailDescription->bd_type) { |
390 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 390 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
391 | path.append(1); | 391 | path.append(1); |
392 | body_text = fetchPart(mail,path,true); | 392 | body_text = fetchPart(mail,path,true); |
393 | target_body.setBodytext(body_text); | 393 | target_body.setBodytext(body_text); |
394 | target_body.setDescription(singlePart); | 394 | target_body.setDescription(singlePart); |
395 | break; | 395 | break; |
396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
398 | path.append(1); | 398 | path.append(1); |
399 | body_text = fetchPart(mail,path,true); | 399 | body_text = fetchPart(mail,path,true); |
400 | target_body.setBodytext(body_text); | 400 | target_body.setBodytext(body_text); |
401 | target_body.setDescription(singlePart); | 401 | target_body.setDescription(singlePart); |
402 | break; | 402 | break; |
403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
404 | qDebug("Single attachment"); | 404 | qDebug("Single attachment"); |
405 | target_body.setBodytext(""); | 405 | target_body.setBodytext(""); |
406 | target_body.addPart(singlePart); | 406 | target_body.addPart(singlePart); |
407 | break; | 407 | break; |
408 | default: | 408 | default: |
409 | break; | 409 | break; |
410 | } | 410 | } |
411 | 411 | ||
412 | return; | 412 | return; |
413 | } | 413 | } |
414 | 414 | ||
415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
416 | { | 416 | { |
417 | QStringList l; | 417 | QStringList l; |
418 | QString from; | 418 | QString from; |
419 | bool named_from; | 419 | bool named_from; |
420 | clistcell *current = NULL; | 420 | clistcell *current = NULL; |
421 | mailimap_address * current_address=NULL; | 421 | mailimap_address * current_address=NULL; |
422 | if (!list) { | 422 | if (!list) { |
423 | return l; | 423 | return l; |
424 | } | 424 | } |
425 | unsigned int count = 0; | 425 | unsigned int count = 0; |
426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
427 | from = ""; | 427 | from = ""; |
428 | named_from = false; | 428 | named_from = false; |
429 | current_address=(mailimap_address*)current->data; | 429 | current_address=(mailimap_address*)current->data; |
430 | if (current_address->ad_personal_name){ | 430 | if (current_address->ad_personal_name){ |
431 | from+=QString(current_address->ad_personal_name); | 431 | from+=QString(current_address->ad_personal_name); |
432 | from+=" "; | 432 | from+=" "; |
433 | named_from = true; | 433 | named_from = true; |
434 | } | 434 | } |
435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
436 | from+="<"; | 436 | from+="<"; |
437 | } | 437 | } |
438 | if (current_address->ad_mailbox_name) { | 438 | if (current_address->ad_mailbox_name) { |
439 | from+=QString(current_address->ad_mailbox_name); | 439 | from+=QString(current_address->ad_mailbox_name); |
440 | from+="@"; | 440 | from+="@"; |
441 | } | 441 | } |
442 | if (current_address->ad_host_name) { | 442 | if (current_address->ad_host_name) { |
443 | from+=QString(current_address->ad_host_name); | 443 | from+=QString(current_address->ad_host_name); |
444 | } | 444 | } |
445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
446 | from+=">"; | 446 | from+=">"; |
447 | } | 447 | } |
448 | l.append(QString(from)); | 448 | l.append(QString(from)); |
449 | if (++count > 99) { | 449 | if (++count > 99) { |
450 | break; | 450 | break; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | return l; | 453 | return l; |
454 | } | 454 | } |
455 | 455 | ||
456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
457 | { | 457 | { |
458 | QString body(""); | 458 | QString body(""); |
459 | const char*mb; | 459 | const char*mb; |
460 | int err; | 460 | int err; |
461 | mailimap_fetch_type *fetchType; | 461 | mailimap_fetch_type *fetchType; |
462 | mailimap_set *set; | 462 | mailimap_set *set; |
463 | clistcell*current,*cur; | 463 | clistcell*current,*cur; |
464 | 464 | ||
465 | login(); | 465 | login(); |
466 | if (!m_imap) { | 466 | if (!m_imap) { |
467 | return body; | 467 | return body; |
468 | } | 468 | } |
469 | if (!internal_call) { | 469 | if (!internal_call) { |
470 | mb = mail.getMbox().latin1(); | 470 | mb = mail.getMbox().latin1(); |
471 | err = mailimap_select( m_imap, (char*)mb); | 471 | err = mailimap_select( m_imap, (char*)mb); |
472 | if ( err != MAILIMAP_NO_ERROR ) { | 472 | if ( err != MAILIMAP_NO_ERROR ) { |
473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
474 | return body; | 474 | return body; |
475 | } | 475 | } |
476 | } | 476 | } |
477 | set = mailimap_set_new_single(mail.getNumber()); | 477 | set = mailimap_set_new_single(mail.getNumber()); |
478 | clist*id_list=clist_new(); | 478 | clist*id_list=clist_new(); |
479 | for (unsigned j=0; j < path.count();++j) { | 479 | for (unsigned j=0; j < path.count();++j) { |
480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
481 | *p_id = path[j]; | 481 | *p_id = path[j]; |
482 | clist_append(id_list,p_id); | 482 | clist_append(id_list,p_id); |
483 | } | 483 | } |
484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
486 | mailimap_section * section = mailimap_section_new(section_spec); | 486 | mailimap_section * section = mailimap_section_new(section_spec); |
487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
488 | 488 | ||
489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
490 | 490 | ||
491 | clist*result = clist_new(); | 491 | clist*result = clist_new(); |
492 | 492 | ||
493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
494 | mailimap_set_free( set ); | 494 | mailimap_set_free( set ); |
495 | mailimap_fetch_type_free( fetchType ); | 495 | mailimap_fetch_type_free( fetchType ); |
496 | 496 | ||
497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
498 | mailimap_msg_att * msg_att; | 498 | mailimap_msg_att * msg_att; |
499 | msg_att = (mailimap_msg_att*)current->data; | 499 | msg_att = (mailimap_msg_att*)current->data; |
500 | mailimap_msg_att_item*msg_att_item; | 500 | mailimap_msg_att_item*msg_att_item; |
501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
507 | if (text) { | 507 | if (text) { |
508 | body = QString(text); | 508 | body = QString(text); |
509 | free(text); | 509 | free(text); |
510 | } else { | 510 | } else { |
511 | body = ""; | 511 | body = ""; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | } else { | 517 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 519 | } |
520 | mailimap_fetch_list_free(result); | 520 | mailimap_fetch_list_free(result); |
521 | return body; | 521 | return body; |
522 | } | 522 | } |
523 | 523 | ||
524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
525 | { | 525 | { |
526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
527 | if (!mailDescription||current_recursion==10) { | 527 | if (!mailDescription||current_recursion==10) { |
528 | return; | 528 | return; |
529 | } | 529 | } |
530 | clistcell*current; | 530 | clistcell*current; |
531 | mailimap_body*current_body; | 531 | mailimap_body*current_body; |
532 | unsigned int count = 0; | 532 | unsigned int count = 0; |
533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
534 | /* the point in the message */ | 534 | /* the point in the message */ |
535 | ++count; | 535 | ++count; |
536 | current_body = (mailimap_body*)current->data; | 536 | current_body = (mailimap_body*)current->data; |
537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
538 | QValueList<int>clist = recList; | 538 | QValueList<int>clist = recList; |
539 | clist.append(count); | 539 | clist.append(count); |
540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
542 | RecPart currentPart; | 542 | RecPart currentPart; |
543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
544 | QValueList<int>clist = recList; | 544 | QValueList<int>clist = recList; |
545 | clist.append(count); | 545 | clist.append(count); |
546 | /* important: Check for is NULL 'cause a body can be empty! */ | 546 | /* important: Check for is NULL 'cause a body can be empty! */ |
547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
548 | QString body_text = fetchPart(mail,clist,true); | 548 | QString body_text = fetchPart(mail,clist,true); |
549 | target_body.setDescription(currentPart); | 549 | target_body.setDescription(currentPart); |
550 | target_body.setBodytext(body_text); | 550 | target_body.setBodytext(body_text); |
551 | } else { | 551 | } else { |
552 | QString id(""); | 552 | QString id(""); |
553 | for (unsigned int j = 0; j < clist.count();++j) { | 553 | for (unsigned int j = 0; j < clist.count();++j) { |
554 | id+=(j>0?" ":""); | 554 | id+=(j>0?" ":""); |
555 | id+=QString("%1").arg(clist[j]); | 555 | id+=QString("%1").arg(clist[j]); |
556 | } | 556 | } |
557 | qDebug("ID= %s",id.latin1()); | 557 | qDebug("ID= %s",id.latin1()); |
558 | currentPart.setIdentifier(id); | 558 | currentPart.setIdentifier(id); |
559 | currentPart.setPositionlist(clist); | 559 | currentPart.setPositionlist(clist); |
560 | target_body.addPart(currentPart); | 560 | target_body.addPart(currentPart); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | } | 564 | } |
565 | 565 | ||
566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
567 | { | 567 | { |
568 | if (!Description) { | 568 | if (!Description) { |
569 | return; | 569 | return; |
570 | } | 570 | } |
571 | switch (Description->bd_type) { | 571 | switch (Description->bd_type) { |
572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
573 | target_part.setType("text"); | 573 | target_part.setType("text"); |
574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
575 | break; | 575 | break; |
576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
578 | break; | 578 | break; |
579 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 579 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
581 | break; | 581 | break; |
582 | default: | 582 | default: |
583 | break; | 583 | break; |
584 | } | 584 | } |
585 | } | 585 | } |
586 | 586 | ||
587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
588 | { | 588 | { |
589 | if (!which) { | 589 | if (!which) { |
590 | return; | 590 | return; |
591 | } | 591 | } |
592 | QString sub; | 592 | QString sub; |
593 | sub = which->bd_media_text; | 593 | sub = which->bd_media_text; |
594 | target_part.setSubtype(sub.lower()); | 594 | target_part.setSubtype(sub.lower()); |
595 | target_part.setLines(which->bd_lines); | 595 | target_part.setLines(which->bd_lines); |
596 | fillBodyFields(target_part,which->bd_fields); | 596 | fillBodyFields(target_part,which->bd_fields); |
597 | } | 597 | } |
598 | 598 | ||
599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
600 | { | 600 | { |
601 | if (!which) { | 601 | if (!which) { |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | // QString sub; | 604 | // QString sub; |
605 | // sub = which->bd_media_text; | 605 | // sub = which->bd_media_text; |
606 | // target_part.setSubtype(sub.lower()); | 606 | // target_part.setSubtype(sub.lower()); |
607 | qDebug("Message part"); | 607 | qDebug("Message part"); |
608 | /* we set this type to text/plain */ | 608 | /* we set this type to text/plain */ |
609 | target_part.setType("text"); | 609 | target_part.setType("text"); |
610 | target_part.setSubtype("plain"); | 610 | target_part.setSubtype("plain"); |
611 | target_part.setLines(which->bd_lines); | 611 | target_part.setLines(which->bd_lines); |
612 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
613 | } | 613 | } |
614 | 614 | ||
615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
616 | { | 616 | { |
617 | if (!which) { | 617 | if (!which) { |
618 | return; | 618 | return; |
619 | } | 619 | } |
620 | QString type,sub; | 620 | QString type,sub; |
621 | switch (which->bd_media_basic->med_type) { | 621 | switch (which->bd_media_basic->med_type) { |
622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
623 | type = "application"; | 623 | type = "application"; |
624 | break; | 624 | break; |
625 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 625 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
626 | type = "audio"; | 626 | type = "audio"; |
627 | break; | 627 | break; |
628 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 628 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
629 | type = "image"; | 629 | type = "image"; |
630 | break; | 630 | break; |
631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
632 | type = "message"; | 632 | type = "message"; |
633 | break; | 633 | break; |
634 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 634 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
635 | type = "video"; | 635 | type = "video"; |
636 | break; | 636 | break; |
637 | case MAILIMAP_MEDIA_BASIC_OTHER: | 637 | case MAILIMAP_MEDIA_BASIC_OTHER: |
638 | default: | 638 | default: |
639 | if (which->bd_media_basic->med_basic_type) { | 639 | if (which->bd_media_basic->med_basic_type) { |
640 | type = which->bd_media_basic->med_basic_type; | 640 | type = which->bd_media_basic->med_basic_type; |
641 | } else { | 641 | } else { |
642 | type = ""; | 642 | type = ""; |
643 | } | 643 | } |
644 | break; | 644 | break; |
645 | } | 645 | } |
646 | if (which->bd_media_basic->med_subtype) { | 646 | if (which->bd_media_basic->med_subtype) { |
647 | sub = which->bd_media_basic->med_subtype; | 647 | sub = which->bd_media_basic->med_subtype; |
648 | } else { | 648 | } else { |
649 | sub = ""; | 649 | sub = ""; |
650 | } | 650 | } |
651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
652 | target_part.setType(type.lower()); | 652 | target_part.setType(type.lower()); |
653 | target_part.setSubtype(sub.lower()); | 653 | target_part.setSubtype(sub.lower()); |
654 | fillBodyFields(target_part,which->bd_fields); | 654 | fillBodyFields(target_part,which->bd_fields); |
655 | } | 655 | } |
656 | 656 | ||
657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
658 | { | 658 | { |
659 | if (!which) return; | 659 | if (!which) return; |
660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
661 | clistcell*cur; | 661 | clistcell*cur; |
662 | mailimap_single_body_fld_param*param=0; | 662 | mailimap_single_body_fld_param*param=0; |
663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
664 | param = (mailimap_single_body_fld_param*)cur->data; | 664 | param = (mailimap_single_body_fld_param*)cur->data; |
665 | if (param) { | 665 | if (param) { |
666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | } | 669 | } |
670 | mailimap_body_fld_enc*enc = which->bd_encoding; | 670 | mailimap_body_fld_enc*enc = which->bd_encoding; |
671 | QString encoding(""); | 671 | QString encoding(""); |
672 | switch (enc->enc_type) { | 672 | switch (enc->enc_type) { |
673 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 673 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
674 | encoding = "7bit"; | 674 | encoding = "7bit"; |
675 | break; | 675 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 676 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
677 | encoding = "8bit"; | 677 | encoding = "8bit"; |
678 | break; | 678 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 679 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
680 | encoding="binary"; | 680 | encoding="binary"; |
681 | break; | 681 | break; |
682 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 682 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
683 | encoding="base64"; | 683 | encoding="base64"; |
684 | break; | 684 | break; |
685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
686 | encoding="quoted-printable"; | 686 | encoding="quoted-printable"; |
687 | break; | 687 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 688 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
689 | default: | 689 | default: |
690 | if (enc->enc_value) { | 690 | if (enc->enc_value) { |
691 | char*t=enc->enc_value; | 691 | char*t=enc->enc_value; |
692 | encoding=QString(enc->enc_value); | 692 | encoding=QString(enc->enc_value); |
693 | enc->enc_value=0L; | 693 | enc->enc_value=0L; |
694 | free(t); | 694 | free(t); |
695 | } | 695 | } |
696 | } | 696 | } |
697 | target_part.setEncoding(encoding); | 697 | target_part.setEncoding(encoding); |
698 | target_part.setSize(which->bd_size); | 698 | target_part.setSize(which->bd_size); |
699 | } | 699 | } |
700 | 700 | ||
701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
702 | { | 702 | { |
703 | return fetchPart(mail,part.Positionlist(),false); | 703 | return fetchPart(mail,part.Positionlist(),false); |
704 | } | 704 | } |
705 | 705 | ||
706 | void IMAPwrapper::deleteMail(const RecMail&mail) | 706 | void IMAPwrapper::deleteMail(const RecMail&mail) |
707 | { | 707 | { |
708 | mailimap_flag_list*flist; | 708 | mailimap_flag_list*flist; |
709 | mailimap_set *set; | 709 | mailimap_set *set; |
710 | mailimap_store_att_flags * store_flags; | 710 | mailimap_store_att_flags * store_flags; |
711 | int err; | 711 | int err; |
712 | login(); | 712 | login(); |
713 | if (!m_imap) { | 713 | if (!m_imap) { |
714 | return; | 714 | return; |
715 | } | 715 | } |
716 | const char *mb = mail.getMbox().latin1(); | 716 | const char *mb = mail.getMbox().latin1(); |
717 | err = mailimap_select( m_imap, (char*)mb); | 717 | err = mailimap_select( m_imap, (char*)mb); |
718 | if ( err != MAILIMAP_NO_ERROR ) { | 718 | if ( err != MAILIMAP_NO_ERROR ) { |
719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
720 | return; | 720 | return; |
721 | } | 721 | } |
722 | flist = mailimap_flag_list_new_empty(); | 722 | flist = mailimap_flag_list_new_empty(); |
723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
725 | set = mailimap_set_new_single(mail.getNumber()); | 725 | set = mailimap_set_new_single(mail.getNumber()); |
726 | err = mailimap_store(m_imap,set,store_flags); | 726 | err = mailimap_store(m_imap,set,store_flags); |
727 | mailimap_set_free( set ); | 727 | mailimap_set_free( set ); |
728 | mailimap_store_att_flags_free(store_flags); | 728 | mailimap_store_att_flags_free(store_flags); |
729 | 729 | ||
730 | if (err != MAILIMAP_NO_ERROR) { | 730 | if (err != MAILIMAP_NO_ERROR) { |
731 | qDebug("error deleting mail: %s",m_imap->imap_response); | 731 | qDebug("error deleting mail: %s",m_imap->imap_response); |
732 | return; | 732 | return; |
733 | } | 733 | } |
734 | qDebug("deleting mail: %s",m_imap->imap_response); | 734 | qDebug("deleting mail: %s",m_imap->imap_response); |
735 | /* should we realy do that at this moment? */ | 735 | /* should we realy do that at this moment? */ |
736 | err = mailimap_expunge(m_imap); | 736 | err = mailimap_expunge(m_imap); |
737 | if (err != MAILIMAP_NO_ERROR) { | 737 | if (err != MAILIMAP_NO_ERROR) { |
738 | qDebug("error deleting mail: %s",m_imap->imap_response); | 738 | qDebug("error deleting mail: %s",m_imap->imap_response); |
739 | } | 739 | } |
740 | qDebug("Delete successfull %s",m_imap->imap_response); | 740 | qDebug("Delete successfull %s",m_imap->imap_response); |
741 | } | 741 | } |
742 | |||
743 | void IMAPwrapper::answeredMail(const RecMail&mail) | ||
744 | { | ||
745 | mailimap_flag_list*flist; | ||
746 | mailimap_set *set; | ||
747 | mailimap_store_att_flags * store_flags; | ||
748 | int err; | ||
749 | login(); | ||
750 | if (!m_imap) { | ||
751 | return; | ||
752 | } | ||
753 | const char *mb = mail.getMbox().latin1(); | ||
754 | err = mailimap_select( m_imap, (char*)mb); | ||
755 | if ( err != MAILIMAP_NO_ERROR ) { | ||
756 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | ||
757 | return; | ||
758 | } | ||
759 | flist = mailimap_flag_list_new_empty(); | ||
760 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | ||
761 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
762 | set = mailimap_set_new_single(mail.getNumber()); | ||
763 | err = mailimap_store(m_imap,set,store_flags); | ||
764 | mailimap_set_free( set ); | ||
765 | mailimap_store_att_flags_free(store_flags); | ||
766 | |||
767 | if (err != MAILIMAP_NO_ERROR) { | ||
768 | qDebug("error marking mail: %s",m_imap->imap_response); | ||
769 | return; | ||
770 | } | ||
771 | } | ||
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 4f4d575..700d512 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -1,55 +1,56 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | 7 | ||
8 | struct mailimap; | 8 | struct mailimap; |
9 | struct mailimap_body_type_1part; | 9 | struct mailimap_body_type_1part; |
10 | struct mailimap_body_type_text; | 10 | struct mailimap_body_type_text; |
11 | struct mailimap_body_type_basic; | 11 | struct mailimap_body_type_basic; |
12 | struct mailimap_body_type_msg; | 12 | struct mailimap_body_type_msg; |
13 | struct mailimap_body_type_mpart; | 13 | struct mailimap_body_type_mpart; |
14 | struct mailimap_body_fields; | 14 | struct mailimap_body_fields; |
15 | struct mailimap_msg_att; | 15 | struct mailimap_msg_att; |
16 | 16 | ||
17 | class IMAPwrapper : public AbstractMail | 17 | class IMAPwrapper : public AbstractMail |
18 | { | 18 | { |
19 | Q_OBJECT | 19 | Q_OBJECT |
20 | public: | 20 | public: |
21 | IMAPwrapper( IMAPaccount *a ); | 21 | IMAPwrapper( IMAPaccount *a ); |
22 | virtual ~IMAPwrapper(); | 22 | virtual ~IMAPwrapper(); |
23 | virtual QList<Folder>* listFolders(); | 23 | virtual QList<Folder>* listFolders(); |
24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
25 | virtual RecBody fetchBody(const RecMail&mail); | 25 | virtual RecBody fetchBody(const RecMail&mail); |
26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); |
27 | virtual void deleteMail(const RecMail&mail); | 27 | virtual void deleteMail(const RecMail&mail); |
28 | virtual void answeredMail(const RecMail&mail); | ||
28 | 29 | ||
29 | static void imap_progress( size_t current, size_t maximum ); | 30 | static void imap_progress( size_t current, size_t maximum ); |
30 | 31 | ||
31 | protected: | 32 | protected: |
32 | RecMail*parse_list_result(mailimap_msg_att*); | 33 | RecMail*parse_list_result(mailimap_msg_att*); |
33 | void login(); | 34 | void login(); |
34 | void logout(); | 35 | void logout(); |
35 | 36 | ||
36 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); | 37 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); |
37 | 38 | ||
38 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 39 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
39 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 40 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
40 | 41 | ||
41 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 42 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
42 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 43 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
43 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 44 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
44 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 45 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
45 | 46 | ||
46 | /* just helpers */ | 47 | /* just helpers */ |
47 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 48 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
48 | static QStringList address_list_to_stringlist(clist*list); | 49 | static QStringList address_list_to_stringlist(clist*list); |
49 | 50 | ||
50 | private: | 51 | private: |
51 | IMAPaccount *account; | 52 | IMAPaccount *account; |
52 | mailimap *m_imap; | 53 | mailimap *m_imap; |
53 | }; | 54 | }; |
54 | 55 | ||
55 | #endif | 56 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 0a1719d..62e0715 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -1,30 +1,31 @@ | |||
1 | #ifndef __abstract_mail_ | 1 | #ifndef __abstract_mail_ |
2 | #define __abstract_mail_ | 2 | #define __abstract_mail_ |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include "settings.h" | 5 | #include "settings.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | 13 | ||
14 | class AbstractMail:public QObject | 14 | class AbstractMail:public QObject |
15 | { | 15 | { |
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | public: | 17 | public: |
18 | AbstractMail(){}; | 18 | AbstractMail(){}; |
19 | virtual ~AbstractMail(){} | 19 | virtual ~AbstractMail(){} |
20 | virtual QList<Folder>* listFolders()=0; | 20 | virtual QList<Folder>* listFolders()=0; |
21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
22 | virtual RecBody fetchBody(const RecMail&mail)=0; | 22 | virtual RecBody fetchBody(const RecMail&mail)=0; |
23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; | 23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; |
24 | virtual void deleteMail(const RecMail&mail)=0; | 24 | virtual void deleteMail(const RecMail&mail)=0; |
25 | virtual void answeredMail(const RecMail&mail)=0; | ||
25 | 26 | ||
26 | static AbstractMail* getWrapper(IMAPaccount *a); | 27 | static AbstractMail* getWrapper(IMAPaccount *a); |
27 | static AbstractMail* getWrapper(POP3account *a); | 28 | static AbstractMail* getWrapper(POP3account *a); |
28 | }; | 29 | }; |
29 | 30 | ||
30 | #endif | 31 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 912a412..b253b49 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,741 +1,771 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if ( (bflags = list->mb_flag) ) { | 203 | if ( (bflags = list->mb_flag) ) { |
204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
206 | } | 206 | } |
207 | folders->append(new IMAPFolder(temp,selectable)); | 207 | folders->append(new IMAPFolder(temp,selectable)); |
208 | } | 208 | } |
209 | } else { | 209 | } else { |
210 | qDebug("error fetching folders %s",m_imap->imap_response); | 210 | qDebug("error fetching folders %s",m_imap->imap_response); |
211 | } | 211 | } |
212 | mailimap_list_result_free( result ); | 212 | mailimap_list_result_free( result ); |
213 | return folders; | 213 | return folders; |
214 | } | 214 | } |
215 | 215 | ||
216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
217 | { | 217 | { |
218 | RecMail * m = 0; | 218 | RecMail * m = 0; |
219 | mailimap_msg_att_item *item=0; | 219 | mailimap_msg_att_item *item=0; |
220 | clistcell *current,*c,*cf; | 220 | clistcell *current,*c,*cf; |
221 | mailimap_msg_att_dynamic*flist; | 221 | mailimap_msg_att_dynamic*flist; |
222 | mailimap_flag_fetch*cflag; | 222 | mailimap_flag_fetch*cflag; |
223 | int size; | 223 | int size; |
224 | QBitArray mFlags(7); | 224 | QBitArray mFlags(7); |
225 | QStringList addresslist; | 225 | QStringList addresslist; |
226 | 226 | ||
227 | if (!m_att) { | 227 | if (!m_att) { |
228 | return m; | 228 | return m; |
229 | } | 229 | } |
230 | m = new RecMail(); | 230 | m = new RecMail(); |
231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
232 | current = c; | 232 | current = c; |
233 | size = 0; | 233 | size = 0; |
234 | item = (mailimap_msg_att_item*)current->data; | 234 | item = (mailimap_msg_att_item*)current->data; |
235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
237 | if (!flist->att_list) { | 237 | if (!flist->att_list) { |
238 | continue; | 238 | continue; |
239 | } | 239 | } |
240 | cf = flist->att_list->first; | 240 | cf = flist->att_list->first; |
241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
242 | cflag = (mailimap_flag_fetch*)cf->data; | 242 | cflag = (mailimap_flag_fetch*)cf->data; |
243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
244 | switch (cflag->fl_flag->fl_type) { | 244 | switch (cflag->fl_flag->fl_type) { |
245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
246 | mFlags.setBit(FLAG_ANSWERED); | 246 | mFlags.setBit(FLAG_ANSWERED); |
247 | break; | 247 | break; |
248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
249 | mFlags.setBit(FLAG_FLAGGED); | 249 | mFlags.setBit(FLAG_FLAGGED); |
250 | break; | 250 | break; |
251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
252 | mFlags.setBit(FLAG_DELETED); | 252 | mFlags.setBit(FLAG_DELETED); |
253 | break; | 253 | break; |
254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
255 | mFlags.setBit(FLAG_SEEN); | 255 | mFlags.setBit(FLAG_SEEN); |
256 | break; | 256 | break; |
257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
258 | mFlags.setBit(FLAG_DRAFT); | 258 | mFlags.setBit(FLAG_DRAFT); |
259 | break; | 259 | break; |
260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
261 | break; | 261 | break; |
262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
263 | break; | 263 | break; |
264 | default: | 264 | default: |
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
268 | mFlags.setBit(FLAG_RECENT); | 268 | mFlags.setBit(FLAG_RECENT); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | continue; | 271 | continue; |
272 | } | 272 | } |
273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
275 | m->setDate(head->env_date); | 275 | m->setDate(head->env_date); |
276 | m->setSubject(head->env_subject); | 276 | m->setSubject(head->env_subject); |
277 | if (head->env_from!=NULL) { | 277 | if (head->env_from!=NULL) { |
278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
279 | if (addresslist.count()) { | 279 | if (addresslist.count()) { |
280 | m->setFrom(addresslist.first()); | 280 | m->setFrom(addresslist.first()); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | if (head->env_to!=NULL) { | 283 | if (head->env_to!=NULL) { |
284 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 284 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
285 | m->setTo(addresslist); | 285 | m->setTo(addresslist); |
286 | } | 286 | } |
287 | if (head->env_cc!=NULL) { | 287 | if (head->env_cc!=NULL) { |
288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
289 | m->setCC(addresslist); | 289 | m->setCC(addresslist); |
290 | } | 290 | } |
291 | if (head->env_bcc!=NULL) { | 291 | if (head->env_bcc!=NULL) { |
292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
293 | m->setBcc(addresslist); | 293 | m->setBcc(addresslist); |
294 | } | 294 | } |
295 | if (head->env_reply_to!=NULL) { | 295 | if (head->env_reply_to!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
297 | if (addresslist.count()) { | 297 | if (addresslist.count()) { |
298 | m->setReplyto(addresslist.first()); | 298 | m->setReplyto(addresslist.first()); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | m->setMsgid(QString(head->env_message_id)); | 301 | m->setMsgid(QString(head->env_message_id)); |
302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
304 | #if 0 | 304 | #if 0 |
305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
307 | qDebug(da.toString()); | 307 | qDebug(da.toString()); |
308 | #endif | 308 | #endif |
309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
310 | size = item->att_data.att_static->att_data.att_rfc822_size; | 310 | size = item->att_data.att_static->att_data.att_rfc822_size; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | /* msg is already deleted */ | 313 | /* msg is already deleted */ |
314 | if (mFlags.testBit(FLAG_DELETED) && m) { | 314 | if (mFlags.testBit(FLAG_DELETED) && m) { |
315 | delete m; | 315 | delete m; |
316 | m = 0; | 316 | m = 0; |
317 | } | 317 | } |
318 | if (m) { | 318 | if (m) { |
319 | m->setFlags(mFlags); | 319 | m->setFlags(mFlags); |
320 | m->setMsgsize(size); | 320 | m->setMsgsize(size); |
321 | } | 321 | } |
322 | return m; | 322 | return m; |
323 | } | 323 | } |
324 | 324 | ||
325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
326 | { | 326 | { |
327 | RecBody body; | 327 | RecBody body; |
328 | const char *mb; | 328 | const char *mb; |
329 | int err = MAILIMAP_NO_ERROR; | 329 | int err = MAILIMAP_NO_ERROR; |
330 | clist *result; | 330 | clist *result; |
331 | clistcell *current; | 331 | clistcell *current; |
332 | mailimap_fetch_att *fetchAtt; | 332 | mailimap_fetch_att *fetchAtt; |
333 | mailimap_fetch_type *fetchType; | 333 | mailimap_fetch_type *fetchType; |
334 | mailimap_set *set; | 334 | mailimap_set *set; |
335 | mailimap_body*body_desc; | 335 | mailimap_body*body_desc; |
336 | 336 | ||
337 | mb = mail.getMbox().latin1(); | 337 | mb = mail.getMbox().latin1(); |
338 | 338 | ||
339 | login(); | 339 | login(); |
340 | if (!m_imap) { | 340 | if (!m_imap) { |
341 | return body; | 341 | return body; |
342 | } | 342 | } |
343 | 343 | ||
344 | err = mailimap_select( m_imap, (char*)mb); | 344 | err = mailimap_select( m_imap, (char*)mb); |
345 | if ( err != MAILIMAP_NO_ERROR ) { | 345 | if ( err != MAILIMAP_NO_ERROR ) { |
346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
347 | return body; | 347 | return body; |
348 | } | 348 | } |
349 | 349 | ||
350 | result = clist_new(); | 350 | result = clist_new(); |
351 | /* the range has to start at 1!!! not with 0!!!! */ | 351 | /* the range has to start at 1!!! not with 0!!!! */ |
352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
356 | mailimap_set_free( set ); | 356 | mailimap_set_free( set ); |
357 | mailimap_fetch_type_free( fetchType ); | 357 | mailimap_fetch_type_free( fetchType ); |
358 | 358 | ||
359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
360 | mailimap_msg_att * msg_att; | 360 | mailimap_msg_att * msg_att; |
361 | msg_att = (mailimap_msg_att*)current->data; | 361 | msg_att = (mailimap_msg_att*)current->data; |
362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
363 | body_desc = item->att_data.att_static->att_data.att_body; | 363 | body_desc = item->att_data.att_static->att_data.att_body; |
364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
367 | qDebug("Mulitpart mail"); | 367 | qDebug("Mulitpart mail"); |
368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
369 | } | 369 | } |
370 | } else { | 370 | } else { |
371 | qDebug("error fetching body: %s",m_imap->imap_response); | 371 | qDebug("error fetching body: %s",m_imap->imap_response); |
372 | } | 372 | } |
373 | mailimap_fetch_list_free(result); | 373 | mailimap_fetch_list_free(result); |
374 | return body; | 374 | return body; |
375 | } | 375 | } |
376 | 376 | ||
377 | /* this routine is just called when the mail has only ONE part. | 377 | /* this routine is just called when the mail has only ONE part. |
378 | for filling the parts of a multi-part-message there are other | 378 | for filling the parts of a multi-part-message there are other |
379 | routines 'cause we can not simply fetch the whole body. */ | 379 | routines 'cause we can not simply fetch the whole body. */ |
380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
381 | { | 381 | { |
382 | if (!mailDescription) { | 382 | if (!mailDescription) { |
383 | return; | 383 | return; |
384 | } | 384 | } |
385 | QString sub,body_text; | 385 | QString sub,body_text; |
386 | RecPart singlePart; | 386 | RecPart singlePart; |
387 | QValueList<int> path; | 387 | QValueList<int> path; |
388 | fillSinglePart(singlePart,mailDescription); | 388 | fillSinglePart(singlePart,mailDescription); |
389 | switch (mailDescription->bd_type) { | 389 | switch (mailDescription->bd_type) { |
390 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 390 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
391 | path.append(1); | 391 | path.append(1); |
392 | body_text = fetchPart(mail,path,true); | 392 | body_text = fetchPart(mail,path,true); |
393 | target_body.setBodytext(body_text); | 393 | target_body.setBodytext(body_text); |
394 | target_body.setDescription(singlePart); | 394 | target_body.setDescription(singlePart); |
395 | break; | 395 | break; |
396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
398 | path.append(1); | 398 | path.append(1); |
399 | body_text = fetchPart(mail,path,true); | 399 | body_text = fetchPart(mail,path,true); |
400 | target_body.setBodytext(body_text); | 400 | target_body.setBodytext(body_text); |
401 | target_body.setDescription(singlePart); | 401 | target_body.setDescription(singlePart); |
402 | break; | 402 | break; |
403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
404 | qDebug("Single attachment"); | 404 | qDebug("Single attachment"); |
405 | target_body.setBodytext(""); | 405 | target_body.setBodytext(""); |
406 | target_body.addPart(singlePart); | 406 | target_body.addPart(singlePart); |
407 | break; | 407 | break; |
408 | default: | 408 | default: |
409 | break; | 409 | break; |
410 | } | 410 | } |
411 | 411 | ||
412 | return; | 412 | return; |
413 | } | 413 | } |
414 | 414 | ||
415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
416 | { | 416 | { |
417 | QStringList l; | 417 | QStringList l; |
418 | QString from; | 418 | QString from; |
419 | bool named_from; | 419 | bool named_from; |
420 | clistcell *current = NULL; | 420 | clistcell *current = NULL; |
421 | mailimap_address * current_address=NULL; | 421 | mailimap_address * current_address=NULL; |
422 | if (!list) { | 422 | if (!list) { |
423 | return l; | 423 | return l; |
424 | } | 424 | } |
425 | unsigned int count = 0; | 425 | unsigned int count = 0; |
426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
427 | from = ""; | 427 | from = ""; |
428 | named_from = false; | 428 | named_from = false; |
429 | current_address=(mailimap_address*)current->data; | 429 | current_address=(mailimap_address*)current->data; |
430 | if (current_address->ad_personal_name){ | 430 | if (current_address->ad_personal_name){ |
431 | from+=QString(current_address->ad_personal_name); | 431 | from+=QString(current_address->ad_personal_name); |
432 | from+=" "; | 432 | from+=" "; |
433 | named_from = true; | 433 | named_from = true; |
434 | } | 434 | } |
435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
436 | from+="<"; | 436 | from+="<"; |
437 | } | 437 | } |
438 | if (current_address->ad_mailbox_name) { | 438 | if (current_address->ad_mailbox_name) { |
439 | from+=QString(current_address->ad_mailbox_name); | 439 | from+=QString(current_address->ad_mailbox_name); |
440 | from+="@"; | 440 | from+="@"; |
441 | } | 441 | } |
442 | if (current_address->ad_host_name) { | 442 | if (current_address->ad_host_name) { |
443 | from+=QString(current_address->ad_host_name); | 443 | from+=QString(current_address->ad_host_name); |
444 | } | 444 | } |
445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
446 | from+=">"; | 446 | from+=">"; |
447 | } | 447 | } |
448 | l.append(QString(from)); | 448 | l.append(QString(from)); |
449 | if (++count > 99) { | 449 | if (++count > 99) { |
450 | break; | 450 | break; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | return l; | 453 | return l; |
454 | } | 454 | } |
455 | 455 | ||
456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
457 | { | 457 | { |
458 | QString body(""); | 458 | QString body(""); |
459 | const char*mb; | 459 | const char*mb; |
460 | int err; | 460 | int err; |
461 | mailimap_fetch_type *fetchType; | 461 | mailimap_fetch_type *fetchType; |
462 | mailimap_set *set; | 462 | mailimap_set *set; |
463 | clistcell*current,*cur; | 463 | clistcell*current,*cur; |
464 | 464 | ||
465 | login(); | 465 | login(); |
466 | if (!m_imap) { | 466 | if (!m_imap) { |
467 | return body; | 467 | return body; |
468 | } | 468 | } |
469 | if (!internal_call) { | 469 | if (!internal_call) { |
470 | mb = mail.getMbox().latin1(); | 470 | mb = mail.getMbox().latin1(); |
471 | err = mailimap_select( m_imap, (char*)mb); | 471 | err = mailimap_select( m_imap, (char*)mb); |
472 | if ( err != MAILIMAP_NO_ERROR ) { | 472 | if ( err != MAILIMAP_NO_ERROR ) { |
473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
474 | return body; | 474 | return body; |
475 | } | 475 | } |
476 | } | 476 | } |
477 | set = mailimap_set_new_single(mail.getNumber()); | 477 | set = mailimap_set_new_single(mail.getNumber()); |
478 | clist*id_list=clist_new(); | 478 | clist*id_list=clist_new(); |
479 | for (unsigned j=0; j < path.count();++j) { | 479 | for (unsigned j=0; j < path.count();++j) { |
480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
481 | *p_id = path[j]; | 481 | *p_id = path[j]; |
482 | clist_append(id_list,p_id); | 482 | clist_append(id_list,p_id); |
483 | } | 483 | } |
484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
486 | mailimap_section * section = mailimap_section_new(section_spec); | 486 | mailimap_section * section = mailimap_section_new(section_spec); |
487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
488 | 488 | ||
489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
490 | 490 | ||
491 | clist*result = clist_new(); | 491 | clist*result = clist_new(); |
492 | 492 | ||
493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
494 | mailimap_set_free( set ); | 494 | mailimap_set_free( set ); |
495 | mailimap_fetch_type_free( fetchType ); | 495 | mailimap_fetch_type_free( fetchType ); |
496 | 496 | ||
497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
498 | mailimap_msg_att * msg_att; | 498 | mailimap_msg_att * msg_att; |
499 | msg_att = (mailimap_msg_att*)current->data; | 499 | msg_att = (mailimap_msg_att*)current->data; |
500 | mailimap_msg_att_item*msg_att_item; | 500 | mailimap_msg_att_item*msg_att_item; |
501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
507 | if (text) { | 507 | if (text) { |
508 | body = QString(text); | 508 | body = QString(text); |
509 | free(text); | 509 | free(text); |
510 | } else { | 510 | } else { |
511 | body = ""; | 511 | body = ""; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | } else { | 517 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 519 | } |
520 | mailimap_fetch_list_free(result); | 520 | mailimap_fetch_list_free(result); |
521 | return body; | 521 | return body; |
522 | } | 522 | } |
523 | 523 | ||
524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
525 | { | 525 | { |
526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
527 | if (!mailDescription||current_recursion==10) { | 527 | if (!mailDescription||current_recursion==10) { |
528 | return; | 528 | return; |
529 | } | 529 | } |
530 | clistcell*current; | 530 | clistcell*current; |
531 | mailimap_body*current_body; | 531 | mailimap_body*current_body; |
532 | unsigned int count = 0; | 532 | unsigned int count = 0; |
533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
534 | /* the point in the message */ | 534 | /* the point in the message */ |
535 | ++count; | 535 | ++count; |
536 | current_body = (mailimap_body*)current->data; | 536 | current_body = (mailimap_body*)current->data; |
537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
538 | QValueList<int>clist = recList; | 538 | QValueList<int>clist = recList; |
539 | clist.append(count); | 539 | clist.append(count); |
540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
542 | RecPart currentPart; | 542 | RecPart currentPart; |
543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
544 | QValueList<int>clist = recList; | 544 | QValueList<int>clist = recList; |
545 | clist.append(count); | 545 | clist.append(count); |
546 | /* important: Check for is NULL 'cause a body can be empty! */ | 546 | /* important: Check for is NULL 'cause a body can be empty! */ |
547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
548 | QString body_text = fetchPart(mail,clist,true); | 548 | QString body_text = fetchPart(mail,clist,true); |
549 | target_body.setDescription(currentPart); | 549 | target_body.setDescription(currentPart); |
550 | target_body.setBodytext(body_text); | 550 | target_body.setBodytext(body_text); |
551 | } else { | 551 | } else { |
552 | QString id(""); | 552 | QString id(""); |
553 | for (unsigned int j = 0; j < clist.count();++j) { | 553 | for (unsigned int j = 0; j < clist.count();++j) { |
554 | id+=(j>0?" ":""); | 554 | id+=(j>0?" ":""); |
555 | id+=QString("%1").arg(clist[j]); | 555 | id+=QString("%1").arg(clist[j]); |
556 | } | 556 | } |
557 | qDebug("ID= %s",id.latin1()); | 557 | qDebug("ID= %s",id.latin1()); |
558 | currentPart.setIdentifier(id); | 558 | currentPart.setIdentifier(id); |
559 | currentPart.setPositionlist(clist); | 559 | currentPart.setPositionlist(clist); |
560 | target_body.addPart(currentPart); | 560 | target_body.addPart(currentPart); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | } | 564 | } |
565 | 565 | ||
566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
567 | { | 567 | { |
568 | if (!Description) { | 568 | if (!Description) { |
569 | return; | 569 | return; |
570 | } | 570 | } |
571 | switch (Description->bd_type) { | 571 | switch (Description->bd_type) { |
572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
573 | target_part.setType("text"); | 573 | target_part.setType("text"); |
574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
575 | break; | 575 | break; |
576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
578 | break; | 578 | break; |
579 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 579 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
581 | break; | 581 | break; |
582 | default: | 582 | default: |
583 | break; | 583 | break; |
584 | } | 584 | } |
585 | } | 585 | } |
586 | 586 | ||
587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
588 | { | 588 | { |
589 | if (!which) { | 589 | if (!which) { |
590 | return; | 590 | return; |
591 | } | 591 | } |
592 | QString sub; | 592 | QString sub; |
593 | sub = which->bd_media_text; | 593 | sub = which->bd_media_text; |
594 | target_part.setSubtype(sub.lower()); | 594 | target_part.setSubtype(sub.lower()); |
595 | target_part.setLines(which->bd_lines); | 595 | target_part.setLines(which->bd_lines); |
596 | fillBodyFields(target_part,which->bd_fields); | 596 | fillBodyFields(target_part,which->bd_fields); |
597 | } | 597 | } |
598 | 598 | ||
599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
600 | { | 600 | { |
601 | if (!which) { | 601 | if (!which) { |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | // QString sub; | 604 | // QString sub; |
605 | // sub = which->bd_media_text; | 605 | // sub = which->bd_media_text; |
606 | // target_part.setSubtype(sub.lower()); | 606 | // target_part.setSubtype(sub.lower()); |
607 | qDebug("Message part"); | 607 | qDebug("Message part"); |
608 | /* we set this type to text/plain */ | 608 | /* we set this type to text/plain */ |
609 | target_part.setType("text"); | 609 | target_part.setType("text"); |
610 | target_part.setSubtype("plain"); | 610 | target_part.setSubtype("plain"); |
611 | target_part.setLines(which->bd_lines); | 611 | target_part.setLines(which->bd_lines); |
612 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
613 | } | 613 | } |
614 | 614 | ||
615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
616 | { | 616 | { |
617 | if (!which) { | 617 | if (!which) { |
618 | return; | 618 | return; |
619 | } | 619 | } |
620 | QString type,sub; | 620 | QString type,sub; |
621 | switch (which->bd_media_basic->med_type) { | 621 | switch (which->bd_media_basic->med_type) { |
622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
623 | type = "application"; | 623 | type = "application"; |
624 | break; | 624 | break; |
625 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 625 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
626 | type = "audio"; | 626 | type = "audio"; |
627 | break; | 627 | break; |
628 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 628 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
629 | type = "image"; | 629 | type = "image"; |
630 | break; | 630 | break; |
631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
632 | type = "message"; | 632 | type = "message"; |
633 | break; | 633 | break; |
634 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 634 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
635 | type = "video"; | 635 | type = "video"; |
636 | break; | 636 | break; |
637 | case MAILIMAP_MEDIA_BASIC_OTHER: | 637 | case MAILIMAP_MEDIA_BASIC_OTHER: |
638 | default: | 638 | default: |
639 | if (which->bd_media_basic->med_basic_type) { | 639 | if (which->bd_media_basic->med_basic_type) { |
640 | type = which->bd_media_basic->med_basic_type; | 640 | type = which->bd_media_basic->med_basic_type; |
641 | } else { | 641 | } else { |
642 | type = ""; | 642 | type = ""; |
643 | } | 643 | } |
644 | break; | 644 | break; |
645 | } | 645 | } |
646 | if (which->bd_media_basic->med_subtype) { | 646 | if (which->bd_media_basic->med_subtype) { |
647 | sub = which->bd_media_basic->med_subtype; | 647 | sub = which->bd_media_basic->med_subtype; |
648 | } else { | 648 | } else { |
649 | sub = ""; | 649 | sub = ""; |
650 | } | 650 | } |
651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
652 | target_part.setType(type.lower()); | 652 | target_part.setType(type.lower()); |
653 | target_part.setSubtype(sub.lower()); | 653 | target_part.setSubtype(sub.lower()); |
654 | fillBodyFields(target_part,which->bd_fields); | 654 | fillBodyFields(target_part,which->bd_fields); |
655 | } | 655 | } |
656 | 656 | ||
657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
658 | { | 658 | { |
659 | if (!which) return; | 659 | if (!which) return; |
660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
661 | clistcell*cur; | 661 | clistcell*cur; |
662 | mailimap_single_body_fld_param*param=0; | 662 | mailimap_single_body_fld_param*param=0; |
663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
664 | param = (mailimap_single_body_fld_param*)cur->data; | 664 | param = (mailimap_single_body_fld_param*)cur->data; |
665 | if (param) { | 665 | if (param) { |
666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | } | 669 | } |
670 | mailimap_body_fld_enc*enc = which->bd_encoding; | 670 | mailimap_body_fld_enc*enc = which->bd_encoding; |
671 | QString encoding(""); | 671 | QString encoding(""); |
672 | switch (enc->enc_type) { | 672 | switch (enc->enc_type) { |
673 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 673 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
674 | encoding = "7bit"; | 674 | encoding = "7bit"; |
675 | break; | 675 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 676 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
677 | encoding = "8bit"; | 677 | encoding = "8bit"; |
678 | break; | 678 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 679 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
680 | encoding="binary"; | 680 | encoding="binary"; |
681 | break; | 681 | break; |
682 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 682 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
683 | encoding="base64"; | 683 | encoding="base64"; |
684 | break; | 684 | break; |
685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
686 | encoding="quoted-printable"; | 686 | encoding="quoted-printable"; |
687 | break; | 687 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 688 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
689 | default: | 689 | default: |
690 | if (enc->enc_value) { | 690 | if (enc->enc_value) { |
691 | char*t=enc->enc_value; | 691 | char*t=enc->enc_value; |
692 | encoding=QString(enc->enc_value); | 692 | encoding=QString(enc->enc_value); |
693 | enc->enc_value=0L; | 693 | enc->enc_value=0L; |
694 | free(t); | 694 | free(t); |
695 | } | 695 | } |
696 | } | 696 | } |
697 | target_part.setEncoding(encoding); | 697 | target_part.setEncoding(encoding); |
698 | target_part.setSize(which->bd_size); | 698 | target_part.setSize(which->bd_size); |
699 | } | 699 | } |
700 | 700 | ||
701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
702 | { | 702 | { |
703 | return fetchPart(mail,part.Positionlist(),false); | 703 | return fetchPart(mail,part.Positionlist(),false); |
704 | } | 704 | } |
705 | 705 | ||
706 | void IMAPwrapper::deleteMail(const RecMail&mail) | 706 | void IMAPwrapper::deleteMail(const RecMail&mail) |
707 | { | 707 | { |
708 | mailimap_flag_list*flist; | 708 | mailimap_flag_list*flist; |
709 | mailimap_set *set; | 709 | mailimap_set *set; |
710 | mailimap_store_att_flags * store_flags; | 710 | mailimap_store_att_flags * store_flags; |
711 | int err; | 711 | int err; |
712 | login(); | 712 | login(); |
713 | if (!m_imap) { | 713 | if (!m_imap) { |
714 | return; | 714 | return; |
715 | } | 715 | } |
716 | const char *mb = mail.getMbox().latin1(); | 716 | const char *mb = mail.getMbox().latin1(); |
717 | err = mailimap_select( m_imap, (char*)mb); | 717 | err = mailimap_select( m_imap, (char*)mb); |
718 | if ( err != MAILIMAP_NO_ERROR ) { | 718 | if ( err != MAILIMAP_NO_ERROR ) { |
719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
720 | return; | 720 | return; |
721 | } | 721 | } |
722 | flist = mailimap_flag_list_new_empty(); | 722 | flist = mailimap_flag_list_new_empty(); |
723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
725 | set = mailimap_set_new_single(mail.getNumber()); | 725 | set = mailimap_set_new_single(mail.getNumber()); |
726 | err = mailimap_store(m_imap,set,store_flags); | 726 | err = mailimap_store(m_imap,set,store_flags); |
727 | mailimap_set_free( set ); | 727 | mailimap_set_free( set ); |
728 | mailimap_store_att_flags_free(store_flags); | 728 | mailimap_store_att_flags_free(store_flags); |
729 | 729 | ||
730 | if (err != MAILIMAP_NO_ERROR) { | 730 | if (err != MAILIMAP_NO_ERROR) { |
731 | qDebug("error deleting mail: %s",m_imap->imap_response); | 731 | qDebug("error deleting mail: %s",m_imap->imap_response); |
732 | return; | 732 | return; |
733 | } | 733 | } |
734 | qDebug("deleting mail: %s",m_imap->imap_response); | 734 | qDebug("deleting mail: %s",m_imap->imap_response); |
735 | /* should we realy do that at this moment? */ | 735 | /* should we realy do that at this moment? */ |
736 | err = mailimap_expunge(m_imap); | 736 | err = mailimap_expunge(m_imap); |
737 | if (err != MAILIMAP_NO_ERROR) { | 737 | if (err != MAILIMAP_NO_ERROR) { |
738 | qDebug("error deleting mail: %s",m_imap->imap_response); | 738 | qDebug("error deleting mail: %s",m_imap->imap_response); |
739 | } | 739 | } |
740 | qDebug("Delete successfull %s",m_imap->imap_response); | 740 | qDebug("Delete successfull %s",m_imap->imap_response); |
741 | } | 741 | } |
742 | |||
743 | void IMAPwrapper::answeredMail(const RecMail&mail) | ||
744 | { | ||
745 | mailimap_flag_list*flist; | ||
746 | mailimap_set *set; | ||
747 | mailimap_store_att_flags * store_flags; | ||
748 | int err; | ||
749 | login(); | ||
750 | if (!m_imap) { | ||
751 | return; | ||
752 | } | ||
753 | const char *mb = mail.getMbox().latin1(); | ||
754 | err = mailimap_select( m_imap, (char*)mb); | ||
755 | if ( err != MAILIMAP_NO_ERROR ) { | ||
756 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | ||
757 | return; | ||
758 | } | ||
759 | flist = mailimap_flag_list_new_empty(); | ||
760 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | ||
761 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
762 | set = mailimap_set_new_single(mail.getNumber()); | ||
763 | err = mailimap_store(m_imap,set,store_flags); | ||
764 | mailimap_set_free( set ); | ||
765 | mailimap_store_att_flags_free(store_flags); | ||
766 | |||
767 | if (err != MAILIMAP_NO_ERROR) { | ||
768 | qDebug("error marking mail: %s",m_imap->imap_response); | ||
769 | return; | ||
770 | } | ||
771 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 4f4d575..700d512 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,55 +1,56 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | 7 | ||
8 | struct mailimap; | 8 | struct mailimap; |
9 | struct mailimap_body_type_1part; | 9 | struct mailimap_body_type_1part; |
10 | struct mailimap_body_type_text; | 10 | struct mailimap_body_type_text; |
11 | struct mailimap_body_type_basic; | 11 | struct mailimap_body_type_basic; |
12 | struct mailimap_body_type_msg; | 12 | struct mailimap_body_type_msg; |
13 | struct mailimap_body_type_mpart; | 13 | struct mailimap_body_type_mpart; |
14 | struct mailimap_body_fields; | 14 | struct mailimap_body_fields; |
15 | struct mailimap_msg_att; | 15 | struct mailimap_msg_att; |
16 | 16 | ||
17 | class IMAPwrapper : public AbstractMail | 17 | class IMAPwrapper : public AbstractMail |
18 | { | 18 | { |
19 | Q_OBJECT | 19 | Q_OBJECT |
20 | public: | 20 | public: |
21 | IMAPwrapper( IMAPaccount *a ); | 21 | IMAPwrapper( IMAPaccount *a ); |
22 | virtual ~IMAPwrapper(); | 22 | virtual ~IMAPwrapper(); |
23 | virtual QList<Folder>* listFolders(); | 23 | virtual QList<Folder>* listFolders(); |
24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
25 | virtual RecBody fetchBody(const RecMail&mail); | 25 | virtual RecBody fetchBody(const RecMail&mail); |
26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); |
27 | virtual void deleteMail(const RecMail&mail); | 27 | virtual void deleteMail(const RecMail&mail); |
28 | virtual void answeredMail(const RecMail&mail); | ||
28 | 29 | ||
29 | static void imap_progress( size_t current, size_t maximum ); | 30 | static void imap_progress( size_t current, size_t maximum ); |
30 | 31 | ||
31 | protected: | 32 | protected: |
32 | RecMail*parse_list_result(mailimap_msg_att*); | 33 | RecMail*parse_list_result(mailimap_msg_att*); |
33 | void login(); | 34 | void login(); |
34 | void logout(); | 35 | void logout(); |
35 | 36 | ||
36 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); | 37 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); |
37 | 38 | ||
38 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 39 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
39 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 40 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
40 | 41 | ||
41 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 42 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
42 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 43 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
43 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 44 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
44 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 45 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
45 | 46 | ||
46 | /* just helpers */ | 47 | /* just helpers */ |
47 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 48 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
48 | static QStringList address_list_to_stringlist(clist*list); | 49 | static QStringList address_list_to_stringlist(clist*list); |
49 | 50 | ||
50 | private: | 51 | private: |
51 | IMAPaccount *account; | 52 | IMAPaccount *account; |
52 | mailimap *m_imap; | 53 | mailimap *m_imap; |
53 | }; | 54 | }; |
54 | 55 | ||
55 | #endif | 56 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 5065d29..46c854b 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,289 +1,293 @@ | |||
1 | 1 | ||
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 18 | { |
19 | qDebug( "POP3: %i of %i", current, maximum ); | 19 | qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 20 | } |
21 | 21 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 25 | char *message; |
26 | size_t length; | 26 | size_t length; |
27 | 27 | ||
28 | login(); | 28 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 29 | if ( !m_pop3 ) return RecBody(); |
30 | 30 | ||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
32 | if ( err != MAILPOP3_NO_ERROR ) { | 32 | if ( err != MAILPOP3_NO_ERROR ) { |
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
34 | logout(); | 34 | logout(); |
35 | return RecBody(); | 35 | return RecBody(); |
36 | } | 36 | } |
37 | 37 | ||
38 | logout(); | 38 | logout(); |
39 | 39 | ||
40 | return parseBody( message ); | 40 | return parseBody( message ); |
41 | } | 41 | } |
42 | 42 | ||
43 | RecBody POP3wrapper::parseBody( const char *message ) | 43 | RecBody POP3wrapper::parseBody( const char *message ) |
44 | { | 44 | { |
45 | int err = MAILIMF_NO_ERROR; | 45 | int err = MAILIMF_NO_ERROR; |
46 | size_t curTok; | 46 | size_t curTok; |
47 | mailimf_message *result; | 47 | mailimf_message *result; |
48 | RecBody body; | 48 | RecBody body; |
49 | 49 | ||
50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
51 | if ( err != MAILIMF_NO_ERROR ) return body; | 51 | if ( err != MAILIMF_NO_ERROR ) return body; |
52 | 52 | ||
53 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 53 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
54 | qDebug( "POP3: bodytext found" ); | 54 | qDebug( "POP3: bodytext found" ); |
55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. | 55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. |
56 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 56 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
57 | } | 57 | } |
58 | 58 | ||
59 | return body; | 59 | return body; |
60 | } | 60 | } |
61 | 61 | ||
62 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 62 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
63 | { | 63 | { |
64 | int err = MAILPOP3_NO_ERROR; | 64 | int err = MAILPOP3_NO_ERROR; |
65 | char *header; | 65 | char *header; |
66 | size_t length; | 66 | size_t length; |
67 | carray *messages; | 67 | carray *messages; |
68 | 68 | ||
69 | login(); | 69 | login(); |
70 | if (!m_pop3) return; | 70 | if (!m_pop3) return; |
71 | mailpop3_list( m_pop3, &messages ); | 71 | mailpop3_list( m_pop3, &messages ); |
72 | 72 | ||
73 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 73 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
75 | 75 | ||
76 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 76 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
77 | if ( err != MAILPOP3_NO_ERROR ) { | 77 | if ( err != MAILPOP3_NO_ERROR ) { |
78 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 78 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
79 | logout(); | 79 | logout(); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | RecMail *mail = parseHeader( header ); | 82 | RecMail *mail = parseHeader( header ); |
83 | mail->setNumber( info->msg_index ); | 83 | mail->setNumber( info->msg_index ); |
84 | mail->setWrapper(this); | 84 | mail->setWrapper(this); |
85 | target.append( mail ); | 85 | target.append( mail ); |
86 | } | 86 | } |
87 | 87 | ||
88 | logout(); | 88 | logout(); |
89 | } | 89 | } |
90 | 90 | ||
91 | RecMail *POP3wrapper::parseHeader( const char *header ) | 91 | RecMail *POP3wrapper::parseHeader( const char *header ) |
92 | { | 92 | { |
93 | int err = MAILIMF_NO_ERROR; | 93 | int err = MAILIMF_NO_ERROR; |
94 | size_t curTok; | 94 | size_t curTok; |
95 | RecMail *mail = new RecMail(); | 95 | RecMail *mail = new RecMail(); |
96 | mailimf_fields *fields; | 96 | mailimf_fields *fields; |
97 | 97 | ||
98 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 98 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
99 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 99 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
100 | mailimf_field *field = (mailimf_field *) current->data; | 100 | mailimf_field *field = (mailimf_field *) current->data; |
101 | switch ( field->fld_type ) { | 101 | switch ( field->fld_type ) { |
102 | case MAILIMF_FIELD_FROM: | 102 | case MAILIMF_FIELD_FROM: |
103 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 103 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
104 | break; | 104 | break; |
105 | case MAILIMF_FIELD_TO: | 105 | case MAILIMF_FIELD_TO: |
106 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 106 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
107 | break; | 107 | break; |
108 | case MAILIMF_FIELD_CC: | 108 | case MAILIMF_FIELD_CC: |
109 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 109 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
110 | break; | 110 | break; |
111 | case MAILIMF_FIELD_BCC: | 111 | case MAILIMF_FIELD_BCC: |
112 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 112 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
113 | break; | 113 | break; |
114 | case MAILIMF_FIELD_SUBJECT: | 114 | case MAILIMF_FIELD_SUBJECT: |
115 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 115 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
116 | break; | 116 | break; |
117 | case MAILIMF_FIELD_ORIG_DATE: | 117 | case MAILIMF_FIELD_ORIG_DATE: |
118 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 118 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
119 | break; | 119 | break; |
120 | default: | 120 | default: |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | return mail; | 125 | return mail; |
126 | } | 126 | } |
127 | 127 | ||
128 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 128 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
129 | { | 129 | { |
130 | char tmp[23]; | 130 | char tmp[23]; |
131 | 131 | ||
132 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 132 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
133 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 133 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
134 | 134 | ||
135 | return QString( tmp ); | 135 | return QString( tmp ); |
136 | } | 136 | } |
137 | 137 | ||
138 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 138 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
139 | { | 139 | { |
140 | QString result( "" ); | 140 | QString result( "" ); |
141 | 141 | ||
142 | bool first = true; | 142 | bool first = true; |
143 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 143 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
144 | mailimf_address *addr = (mailimf_address *) current->data; | 144 | mailimf_address *addr = (mailimf_address *) current->data; |
145 | 145 | ||
146 | if ( !first ) { | 146 | if ( !first ) { |
147 | result.append( "," ); | 147 | result.append( "," ); |
148 | } else { | 148 | } else { |
149 | first = false; | 149 | first = false; |
150 | } | 150 | } |
151 | 151 | ||
152 | switch ( addr->ad_type ) { | 152 | switch ( addr->ad_type ) { |
153 | case MAILIMF_ADDRESS_MAILBOX: | 153 | case MAILIMF_ADDRESS_MAILBOX: |
154 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 154 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
155 | break; | 155 | break; |
156 | case MAILIMF_ADDRESS_GROUP: | 156 | case MAILIMF_ADDRESS_GROUP: |
157 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 157 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
158 | break; | 158 | break; |
159 | default: | 159 | default: |
160 | qDebug( "POP3: unkown mailimf address type" ); | 160 | qDebug( "POP3: unkown mailimf address type" ); |
161 | break; | 161 | break; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | return result; | 165 | return result; |
166 | } | 166 | } |
167 | 167 | ||
168 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 168 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
169 | { | 169 | { |
170 | QString result( "" ); | 170 | QString result( "" ); |
171 | 171 | ||
172 | result.append( group->grp_display_name ); | 172 | result.append( group->grp_display_name ); |
173 | result.append( ": " ); | 173 | result.append( ": " ); |
174 | 174 | ||
175 | if ( group->grp_mb_list != NULL ) { | 175 | if ( group->grp_mb_list != NULL ) { |
176 | result.append( parseMailboxList( group->grp_mb_list ) ); | 176 | result.append( parseMailboxList( group->grp_mb_list ) ); |
177 | } | 177 | } |
178 | 178 | ||
179 | result.append( ";" ); | 179 | result.append( ";" ); |
180 | 180 | ||
181 | return result; | 181 | return result; |
182 | } | 182 | } |
183 | 183 | ||
184 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 184 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
185 | { | 185 | { |
186 | QString result( "" ); | 186 | QString result( "" ); |
187 | 187 | ||
188 | if ( box->mb_display_name == NULL ) { | 188 | if ( box->mb_display_name == NULL ) { |
189 | result.append( box->mb_addr_spec ); | 189 | result.append( box->mb_addr_spec ); |
190 | } else { | 190 | } else { |
191 | result.append( box->mb_display_name ); | 191 | result.append( box->mb_display_name ); |
192 | result.append( " <" ); | 192 | result.append( " <" ); |
193 | result.append( box->mb_addr_spec ); | 193 | result.append( box->mb_addr_spec ); |
194 | result.append( ">" ); | 194 | result.append( ">" ); |
195 | } | 195 | } |
196 | 196 | ||
197 | return result; | 197 | return result; |
198 | } | 198 | } |
199 | 199 | ||
200 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 200 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
201 | { | 201 | { |
202 | QString result( "" ); | 202 | QString result( "" ); |
203 | 203 | ||
204 | bool first = true; | 204 | bool first = true; |
205 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 205 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
206 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 206 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
207 | 207 | ||
208 | if ( !first ) { | 208 | if ( !first ) { |
209 | result.append( "," ); | 209 | result.append( "," ); |
210 | } else { | 210 | } else { |
211 | first = false; | 211 | first = false; |
212 | } | 212 | } |
213 | 213 | ||
214 | result.append( parseMailbox( box ) ); | 214 | result.append( parseMailbox( box ) ); |
215 | } | 215 | } |
216 | 216 | ||
217 | return result; | 217 | return result; |
218 | } | 218 | } |
219 | 219 | ||
220 | void POP3wrapper::login() | 220 | void POP3wrapper::login() |
221 | { | 221 | { |
222 | if ( m_pop3 != NULL ) logout(); | 222 | if ( m_pop3 != NULL ) logout(); |
223 | 223 | ||
224 | const char *server, *user, *pass; | 224 | const char *server, *user, *pass; |
225 | uint16_t port; | 225 | uint16_t port; |
226 | int err = MAILPOP3_NO_ERROR; | 226 | int err = MAILPOP3_NO_ERROR; |
227 | 227 | ||
228 | server = account->getServer().latin1(); | 228 | server = account->getServer().latin1(); |
229 | port = account->getPort().toUInt(); | 229 | port = account->getPort().toUInt(); |
230 | user = account->getUser().latin1(); | 230 | user = account->getUser().latin1(); |
231 | pass = account->getPassword().latin1(); | 231 | pass = account->getPassword().latin1(); |
232 | 232 | ||
233 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 233 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
234 | 234 | ||
235 | // connect | 235 | // connect |
236 | if (account->getSSL()) { | 236 | if (account->getSSL()) { |
237 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 237 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
238 | } else { | 238 | } else { |
239 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 239 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
240 | } | 240 | } |
241 | 241 | ||
242 | if ( err != MAILPOP3_NO_ERROR ) { | 242 | if ( err != MAILPOP3_NO_ERROR ) { |
243 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 243 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
244 | m_pop3->pop3_response ); | 244 | m_pop3->pop3_response ); |
245 | mailpop3_free( m_pop3 ); | 245 | mailpop3_free( m_pop3 ); |
246 | m_pop3 = NULL; | 246 | m_pop3 = NULL; |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | qDebug( "POP3: connected!" ); | 249 | qDebug( "POP3: connected!" ); |
250 | 250 | ||
251 | // login | 251 | // login |
252 | // TODO: decide if apop or plain login should be used | 252 | // TODO: decide if apop or plain login should be used |
253 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 253 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
254 | if ( err != MAILPOP3_NO_ERROR ) { | 254 | if ( err != MAILPOP3_NO_ERROR ) { |
255 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 255 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
256 | logout(); | 256 | logout(); |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | 259 | ||
260 | qDebug( "POP3: logged in!" ); | 260 | qDebug( "POP3: logged in!" ); |
261 | } | 261 | } |
262 | 262 | ||
263 | void POP3wrapper::logout() | 263 | void POP3wrapper::logout() |
264 | { | 264 | { |
265 | int err = MAILPOP3_NO_ERROR; | 265 | int err = MAILPOP3_NO_ERROR; |
266 | if ( m_pop3 == NULL ) return; | 266 | if ( m_pop3 == NULL ) return; |
267 | err = mailpop3_quit( m_pop3 ); | 267 | err = mailpop3_quit( m_pop3 ); |
268 | mailpop3_free( m_pop3 ); | 268 | mailpop3_free( m_pop3 ); |
269 | m_pop3 = NULL; | 269 | m_pop3 = NULL; |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | QList<Folder>* POP3wrapper::listFolders() | 273 | QList<Folder>* POP3wrapper::listFolders() |
274 | { | 274 | { |
275 | QList<Folder> * folders = new QList<Folder>(); | 275 | QList<Folder> * folders = new QList<Folder>(); |
276 | folders->setAutoDelete( false ); | 276 | folders->setAutoDelete( false ); |
277 | Folder*inb=new Folder("INBOX"); | 277 | Folder*inb=new Folder("INBOX"); |
278 | folders->append(inb); | 278 | folders->append(inb); |
279 | return folders; | 279 | return folders; |
280 | } | 280 | } |
281 | 281 | ||
282 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) | 282 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) |
283 | { | 283 | { |
284 | return ""; | 284 | return ""; |
285 | } | 285 | } |
286 | 286 | ||
287 | void POP3wrapper::deleteMail(const RecMail&) | 287 | void POP3wrapper::deleteMail(const RecMail&) |
288 | { | 288 | { |
289 | } | 289 | } |
290 | |||
291 | void POP3wrapper::answeredMail(const RecMail&) | ||
292 | { | ||
293 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index ef972c8..6ff8d62 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,43 +1,44 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | struct mailpop3; | 9 | struct mailpop3; |
10 | 10 | ||
11 | class POP3wrapper : public AbstractMail | 11 | class POP3wrapper : public AbstractMail |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | POP3wrapper( POP3account *a ); | 16 | POP3wrapper( POP3account *a ); |
17 | virtual ~POP3wrapper(); | 17 | virtual ~POP3wrapper(); |
18 | /* mailbox will be ignored */ | 18 | /* mailbox will be ignored */ |
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 20 | virtual QList<Folder>* listFolders(); |
21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); |
22 | virtual void deleteMail(const RecMail&mail); | 22 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | ||
23 | 24 | ||
24 | RecBody fetchBody( const RecMail &mail ); | 25 | RecBody fetchBody( const RecMail &mail ); |
25 | static void pop3_progress( size_t current, size_t maximum ); | 26 | static void pop3_progress( size_t current, size_t maximum ); |
26 | 27 | ||
27 | protected: | 28 | protected: |
28 | void login(); | 29 | void login(); |
29 | void logout(); | 30 | void logout(); |
30 | 31 | ||
31 | private: | 32 | private: |
32 | RecMail *parseHeader( const char *header ); | 33 | RecMail *parseHeader( const char *header ); |
33 | RecBody parseBody( const char *message ); | 34 | RecBody parseBody( const char *message ); |
34 | QString parseMailboxList( mailimf_mailbox_list *list ); | 35 | QString parseMailboxList( mailimf_mailbox_list *list ); |
35 | QString parseMailbox( mailimf_mailbox *box ); | 36 | QString parseMailbox( mailimf_mailbox *box ); |
36 | QString parseGroup( mailimf_group *group ); | 37 | QString parseGroup( mailimf_group *group ); |
37 | QString parseAddressList( mailimf_address_list *list ); | 38 | QString parseAddressList( mailimf_address_list *list ); |
38 | QString parseDateTime( mailimf_date_time *date ); | 39 | QString parseDateTime( mailimf_date_time *date ); |
39 | POP3account *account; | 40 | POP3account *account; |
40 | mailpop3 *m_pop3; | 41 | mailpop3 *m_pop3; |
41 | }; | 42 | }; |
42 | 43 | ||
43 | #endif | 44 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 5065d29..46c854b 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,289 +1,293 @@ | |||
1 | 1 | ||
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 18 | { |
19 | qDebug( "POP3: %i of %i", current, maximum ); | 19 | qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 20 | } |
21 | 21 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 25 | char *message; |
26 | size_t length; | 26 | size_t length; |
27 | 27 | ||
28 | login(); | 28 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 29 | if ( !m_pop3 ) return RecBody(); |
30 | 30 | ||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
32 | if ( err != MAILPOP3_NO_ERROR ) { | 32 | if ( err != MAILPOP3_NO_ERROR ) { |
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
34 | logout(); | 34 | logout(); |
35 | return RecBody(); | 35 | return RecBody(); |
36 | } | 36 | } |
37 | 37 | ||
38 | logout(); | 38 | logout(); |
39 | 39 | ||
40 | return parseBody( message ); | 40 | return parseBody( message ); |
41 | } | 41 | } |
42 | 42 | ||
43 | RecBody POP3wrapper::parseBody( const char *message ) | 43 | RecBody POP3wrapper::parseBody( const char *message ) |
44 | { | 44 | { |
45 | int err = MAILIMF_NO_ERROR; | 45 | int err = MAILIMF_NO_ERROR; |
46 | size_t curTok; | 46 | size_t curTok; |
47 | mailimf_message *result; | 47 | mailimf_message *result; |
48 | RecBody body; | 48 | RecBody body; |
49 | 49 | ||
50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 50 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
51 | if ( err != MAILIMF_NO_ERROR ) return body; | 51 | if ( err != MAILIMF_NO_ERROR ) return body; |
52 | 52 | ||
53 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 53 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
54 | qDebug( "POP3: bodytext found" ); | 54 | qDebug( "POP3: bodytext found" ); |
55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. | 55 | // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. |
56 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 56 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
57 | } | 57 | } |
58 | 58 | ||
59 | return body; | 59 | return body; |
60 | } | 60 | } |
61 | 61 | ||
62 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 62 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
63 | { | 63 | { |
64 | int err = MAILPOP3_NO_ERROR; | 64 | int err = MAILPOP3_NO_ERROR; |
65 | char *header; | 65 | char *header; |
66 | size_t length; | 66 | size_t length; |
67 | carray *messages; | 67 | carray *messages; |
68 | 68 | ||
69 | login(); | 69 | login(); |
70 | if (!m_pop3) return; | 70 | if (!m_pop3) return; |
71 | mailpop3_list( m_pop3, &messages ); | 71 | mailpop3_list( m_pop3, &messages ); |
72 | 72 | ||
73 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 73 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 74 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
75 | 75 | ||
76 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 76 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
77 | if ( err != MAILPOP3_NO_ERROR ) { | 77 | if ( err != MAILPOP3_NO_ERROR ) { |
78 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 78 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
79 | logout(); | 79 | logout(); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | RecMail *mail = parseHeader( header ); | 82 | RecMail *mail = parseHeader( header ); |
83 | mail->setNumber( info->msg_index ); | 83 | mail->setNumber( info->msg_index ); |
84 | mail->setWrapper(this); | 84 | mail->setWrapper(this); |
85 | target.append( mail ); | 85 | target.append( mail ); |
86 | } | 86 | } |
87 | 87 | ||
88 | logout(); | 88 | logout(); |
89 | } | 89 | } |
90 | 90 | ||
91 | RecMail *POP3wrapper::parseHeader( const char *header ) | 91 | RecMail *POP3wrapper::parseHeader( const char *header ) |
92 | { | 92 | { |
93 | int err = MAILIMF_NO_ERROR; | 93 | int err = MAILIMF_NO_ERROR; |
94 | size_t curTok; | 94 | size_t curTok; |
95 | RecMail *mail = new RecMail(); | 95 | RecMail *mail = new RecMail(); |
96 | mailimf_fields *fields; | 96 | mailimf_fields *fields; |
97 | 97 | ||
98 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 98 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
99 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 99 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
100 | mailimf_field *field = (mailimf_field *) current->data; | 100 | mailimf_field *field = (mailimf_field *) current->data; |
101 | switch ( field->fld_type ) { | 101 | switch ( field->fld_type ) { |
102 | case MAILIMF_FIELD_FROM: | 102 | case MAILIMF_FIELD_FROM: |
103 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 103 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
104 | break; | 104 | break; |
105 | case MAILIMF_FIELD_TO: | 105 | case MAILIMF_FIELD_TO: |
106 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 106 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
107 | break; | 107 | break; |
108 | case MAILIMF_FIELD_CC: | 108 | case MAILIMF_FIELD_CC: |
109 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 109 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
110 | break; | 110 | break; |
111 | case MAILIMF_FIELD_BCC: | 111 | case MAILIMF_FIELD_BCC: |
112 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 112 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
113 | break; | 113 | break; |
114 | case MAILIMF_FIELD_SUBJECT: | 114 | case MAILIMF_FIELD_SUBJECT: |
115 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 115 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
116 | break; | 116 | break; |
117 | case MAILIMF_FIELD_ORIG_DATE: | 117 | case MAILIMF_FIELD_ORIG_DATE: |
118 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 118 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
119 | break; | 119 | break; |
120 | default: | 120 | default: |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | return mail; | 125 | return mail; |
126 | } | 126 | } |
127 | 127 | ||
128 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 128 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
129 | { | 129 | { |
130 | char tmp[23]; | 130 | char tmp[23]; |
131 | 131 | ||
132 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 132 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
133 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 133 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
134 | 134 | ||
135 | return QString( tmp ); | 135 | return QString( tmp ); |
136 | } | 136 | } |
137 | 137 | ||
138 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 138 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
139 | { | 139 | { |
140 | QString result( "" ); | 140 | QString result( "" ); |
141 | 141 | ||
142 | bool first = true; | 142 | bool first = true; |
143 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 143 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
144 | mailimf_address *addr = (mailimf_address *) current->data; | 144 | mailimf_address *addr = (mailimf_address *) current->data; |
145 | 145 | ||
146 | if ( !first ) { | 146 | if ( !first ) { |
147 | result.append( "," ); | 147 | result.append( "," ); |
148 | } else { | 148 | } else { |
149 | first = false; | 149 | first = false; |
150 | } | 150 | } |
151 | 151 | ||
152 | switch ( addr->ad_type ) { | 152 | switch ( addr->ad_type ) { |
153 | case MAILIMF_ADDRESS_MAILBOX: | 153 | case MAILIMF_ADDRESS_MAILBOX: |
154 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 154 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
155 | break; | 155 | break; |
156 | case MAILIMF_ADDRESS_GROUP: | 156 | case MAILIMF_ADDRESS_GROUP: |
157 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 157 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
158 | break; | 158 | break; |
159 | default: | 159 | default: |
160 | qDebug( "POP3: unkown mailimf address type" ); | 160 | qDebug( "POP3: unkown mailimf address type" ); |
161 | break; | 161 | break; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | return result; | 165 | return result; |
166 | } | 166 | } |
167 | 167 | ||
168 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 168 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
169 | { | 169 | { |
170 | QString result( "" ); | 170 | QString result( "" ); |
171 | 171 | ||
172 | result.append( group->grp_display_name ); | 172 | result.append( group->grp_display_name ); |
173 | result.append( ": " ); | 173 | result.append( ": " ); |
174 | 174 | ||
175 | if ( group->grp_mb_list != NULL ) { | 175 | if ( group->grp_mb_list != NULL ) { |
176 | result.append( parseMailboxList( group->grp_mb_list ) ); | 176 | result.append( parseMailboxList( group->grp_mb_list ) ); |
177 | } | 177 | } |
178 | 178 | ||
179 | result.append( ";" ); | 179 | result.append( ";" ); |
180 | 180 | ||
181 | return result; | 181 | return result; |
182 | } | 182 | } |
183 | 183 | ||
184 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 184 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
185 | { | 185 | { |
186 | QString result( "" ); | 186 | QString result( "" ); |
187 | 187 | ||
188 | if ( box->mb_display_name == NULL ) { | 188 | if ( box->mb_display_name == NULL ) { |
189 | result.append( box->mb_addr_spec ); | 189 | result.append( box->mb_addr_spec ); |
190 | } else { | 190 | } else { |
191 | result.append( box->mb_display_name ); | 191 | result.append( box->mb_display_name ); |
192 | result.append( " <" ); | 192 | result.append( " <" ); |
193 | result.append( box->mb_addr_spec ); | 193 | result.append( box->mb_addr_spec ); |
194 | result.append( ">" ); | 194 | result.append( ">" ); |
195 | } | 195 | } |
196 | 196 | ||
197 | return result; | 197 | return result; |
198 | } | 198 | } |
199 | 199 | ||
200 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 200 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
201 | { | 201 | { |
202 | QString result( "" ); | 202 | QString result( "" ); |
203 | 203 | ||
204 | bool first = true; | 204 | bool first = true; |
205 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 205 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
206 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 206 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
207 | 207 | ||
208 | if ( !first ) { | 208 | if ( !first ) { |
209 | result.append( "," ); | 209 | result.append( "," ); |
210 | } else { | 210 | } else { |
211 | first = false; | 211 | first = false; |
212 | } | 212 | } |
213 | 213 | ||
214 | result.append( parseMailbox( box ) ); | 214 | result.append( parseMailbox( box ) ); |
215 | } | 215 | } |
216 | 216 | ||
217 | return result; | 217 | return result; |
218 | } | 218 | } |
219 | 219 | ||
220 | void POP3wrapper::login() | 220 | void POP3wrapper::login() |
221 | { | 221 | { |
222 | if ( m_pop3 != NULL ) logout(); | 222 | if ( m_pop3 != NULL ) logout(); |
223 | 223 | ||
224 | const char *server, *user, *pass; | 224 | const char *server, *user, *pass; |
225 | uint16_t port; | 225 | uint16_t port; |
226 | int err = MAILPOP3_NO_ERROR; | 226 | int err = MAILPOP3_NO_ERROR; |
227 | 227 | ||
228 | server = account->getServer().latin1(); | 228 | server = account->getServer().latin1(); |
229 | port = account->getPort().toUInt(); | 229 | port = account->getPort().toUInt(); |
230 | user = account->getUser().latin1(); | 230 | user = account->getUser().latin1(); |
231 | pass = account->getPassword().latin1(); | 231 | pass = account->getPassword().latin1(); |
232 | 232 | ||
233 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 233 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
234 | 234 | ||
235 | // connect | 235 | // connect |
236 | if (account->getSSL()) { | 236 | if (account->getSSL()) { |
237 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 237 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
238 | } else { | 238 | } else { |
239 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 239 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
240 | } | 240 | } |
241 | 241 | ||
242 | if ( err != MAILPOP3_NO_ERROR ) { | 242 | if ( err != MAILPOP3_NO_ERROR ) { |
243 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 243 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
244 | m_pop3->pop3_response ); | 244 | m_pop3->pop3_response ); |
245 | mailpop3_free( m_pop3 ); | 245 | mailpop3_free( m_pop3 ); |
246 | m_pop3 = NULL; | 246 | m_pop3 = NULL; |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | qDebug( "POP3: connected!" ); | 249 | qDebug( "POP3: connected!" ); |
250 | 250 | ||
251 | // login | 251 | // login |
252 | // TODO: decide if apop or plain login should be used | 252 | // TODO: decide if apop or plain login should be used |
253 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 253 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
254 | if ( err != MAILPOP3_NO_ERROR ) { | 254 | if ( err != MAILPOP3_NO_ERROR ) { |
255 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 255 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
256 | logout(); | 256 | logout(); |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | 259 | ||
260 | qDebug( "POP3: logged in!" ); | 260 | qDebug( "POP3: logged in!" ); |
261 | } | 261 | } |
262 | 262 | ||
263 | void POP3wrapper::logout() | 263 | void POP3wrapper::logout() |
264 | { | 264 | { |
265 | int err = MAILPOP3_NO_ERROR; | 265 | int err = MAILPOP3_NO_ERROR; |
266 | if ( m_pop3 == NULL ) return; | 266 | if ( m_pop3 == NULL ) return; |
267 | err = mailpop3_quit( m_pop3 ); | 267 | err = mailpop3_quit( m_pop3 ); |
268 | mailpop3_free( m_pop3 ); | 268 | mailpop3_free( m_pop3 ); |
269 | m_pop3 = NULL; | 269 | m_pop3 = NULL; |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | QList<Folder>* POP3wrapper::listFolders() | 273 | QList<Folder>* POP3wrapper::listFolders() |
274 | { | 274 | { |
275 | QList<Folder> * folders = new QList<Folder>(); | 275 | QList<Folder> * folders = new QList<Folder>(); |
276 | folders->setAutoDelete( false ); | 276 | folders->setAutoDelete( false ); |
277 | Folder*inb=new Folder("INBOX"); | 277 | Folder*inb=new Folder("INBOX"); |
278 | folders->append(inb); | 278 | folders->append(inb); |
279 | return folders; | 279 | return folders; |
280 | } | 280 | } |
281 | 281 | ||
282 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) | 282 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) |
283 | { | 283 | { |
284 | return ""; | 284 | return ""; |
285 | } | 285 | } |
286 | 286 | ||
287 | void POP3wrapper::deleteMail(const RecMail&) | 287 | void POP3wrapper::deleteMail(const RecMail&) |
288 | { | 288 | { |
289 | } | 289 | } |
290 | |||
291 | void POP3wrapper::answeredMail(const RecMail&) | ||
292 | { | ||
293 | } | ||
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index ef972c8..6ff8d62 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,43 +1,44 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | struct mailpop3; | 9 | struct mailpop3; |
10 | 10 | ||
11 | class POP3wrapper : public AbstractMail | 11 | class POP3wrapper : public AbstractMail |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | POP3wrapper( POP3account *a ); | 16 | POP3wrapper( POP3account *a ); |
17 | virtual ~POP3wrapper(); | 17 | virtual ~POP3wrapper(); |
18 | /* mailbox will be ignored */ | 18 | /* mailbox will be ignored */ |
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 20 | virtual QList<Folder>* listFolders(); |
21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); |
22 | virtual void deleteMail(const RecMail&mail); | 22 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | ||
23 | 24 | ||
24 | RecBody fetchBody( const RecMail &mail ); | 25 | RecBody fetchBody( const RecMail &mail ); |
25 | static void pop3_progress( size_t current, size_t maximum ); | 26 | static void pop3_progress( size_t current, size_t maximum ); |
26 | 27 | ||
27 | protected: | 28 | protected: |
28 | void login(); | 29 | void login(); |
29 | void logout(); | 30 | void logout(); |
30 | 31 | ||
31 | private: | 32 | private: |
32 | RecMail *parseHeader( const char *header ); | 33 | RecMail *parseHeader( const char *header ); |
33 | RecBody parseBody( const char *message ); | 34 | RecBody parseBody( const char *message ); |
34 | QString parseMailboxList( mailimf_mailbox_list *list ); | 35 | QString parseMailboxList( mailimf_mailbox_list *list ); |
35 | QString parseMailbox( mailimf_mailbox *box ); | 36 | QString parseMailbox( mailimf_mailbox *box ); |
36 | QString parseGroup( mailimf_group *group ); | 37 | QString parseGroup( mailimf_group *group ); |
37 | QString parseAddressList( mailimf_address_list *list ); | 38 | QString parseAddressList( mailimf_address_list *list ); |
38 | QString parseDateTime( mailimf_date_time *date ); | 39 | QString parseDateTime( mailimf_date_time *date ); |
39 | POP3account *account; | 40 | POP3account *account; |
40 | mailpop3 *m_pop3; | 41 | mailpop3 *m_pop3; |
41 | }; | 42 | }; |
42 | 43 | ||
43 | #endif | 44 | #endif |
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index e53f4a3..68d3c51 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,327 +1,330 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qaction.h> | 4 | #include <qaction.h> |
5 | #include <qpopupmenu.h> | 5 | #include <qpopupmenu.h> |
6 | #include <qapplication.h> | 6 | #include <qapplication.h> |
7 | 7 | ||
8 | #include <opie/ofiledialog.h> | 8 | #include <opie/ofiledialog.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | #include "composemail.h" | 11 | #include "composemail.h" |
12 | #include "viewmail.h" | 12 | #include "viewmail.h" |
13 | #include "abstractmail.h" | 13 | #include "abstractmail.h" |
14 | #include "accountview.h" | 14 | #include "accountview.h" |
15 | 15 | ||
16 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) | 16 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) |
17 | : QListViewItem(parent,after),_partNum(num) | 17 | : QListViewItem(parent,after),_partNum(num) |
18 | { | 18 | { |
19 | setText(0, mime); | 19 | setText(0, mime); |
20 | setText(1, file); | 20 | setText(1, file); |
21 | setText(2, desc); | 21 | setText(2, desc); |
22 | } | 22 | } |
23 | 23 | ||
24 | void ViewMail::setBody( RecBody body ) { | 24 | void ViewMail::setBody( RecBody body ) { |
25 | 25 | ||
26 | m_body = body; | 26 | m_body = body; |
27 | m_mail[2] = body.Bodytext(); | 27 | m_mail[2] = body.Bodytext(); |
28 | attachbutton->setEnabled(body.Parts().count()>0); | 28 | attachbutton->setEnabled(body.Parts().count()>0); |
29 | attachments->setEnabled(body.Parts().count()>0); | 29 | attachments->setEnabled(body.Parts().count()>0); |
30 | if (body.Parts().count()==0) { | 30 | if (body.Parts().count()==0) { |
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | AttachItem * curItem=0; | 33 | AttachItem * curItem=0; |
34 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 34 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
35 | QString desc; | 35 | QString desc; |
36 | double s = body.Description().Size(); | 36 | double s = body.Description().Size(); |
37 | int w; | 37 | int w; |
38 | w=0; | 38 | w=0; |
39 | 39 | ||
40 | while (s>1024) { | 40 | while (s>1024) { |
41 | s/=1024; | 41 | s/=1024; |
42 | ++w; | 42 | ++w; |
43 | if (w>=2) break; | 43 | if (w>=2) break; |
44 | } | 44 | } |
45 | 45 | ||
46 | QString q=""; | 46 | QString q=""; |
47 | switch(w) { | 47 | switch(w) { |
48 | case 1: | 48 | case 1: |
49 | q="k"; | 49 | q="k"; |
50 | break; | 50 | break; |
51 | case 2: | 51 | case 2: |
52 | q="M"; | 52 | q="M"; |
53 | break; | 53 | break; |
54 | default: | 54 | default: |
55 | break; | 55 | break; |
56 | } | 56 | } |
57 | 57 | ||
58 | { | 58 | { |
59 | /* I did not found a method to make a CONTENT reset on a QTextStream | 59 | /* I did not found a method to make a CONTENT reset on a QTextStream |
60 | so I use this construct that the stream will re-constructed in each | 60 | so I use this construct that the stream will re-constructed in each |
61 | loop. To let it work, the textstream is packed into a own area of | 61 | loop. To let it work, the textstream is packed into a own area of |
62 | code is it will be destructed after finishing its small job. | 62 | code is it will be destructed after finishing its small job. |
63 | */ | 63 | */ |
64 | QTextOStream o(&desc); | 64 | QTextOStream o(&desc); |
65 | if (w>0) o.precision(2); else o.precision(0); | 65 | if (w>0) o.precision(2); else o.precision(0); |
66 | o.setf(QTextStream::fixed); | 66 | o.setf(QTextStream::fixed); |
67 | o << s << " " << q << "Byte"; | 67 | o << s << " " << q << "Byte"; |
68 | } | 68 | } |
69 | 69 | ||
70 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); | 70 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); |
71 | QString filename = ""; | 71 | QString filename = ""; |
72 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 72 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
73 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 73 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
74 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 74 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
75 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 75 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
76 | if (it.key().lower()=="name") { | 76 | if (it.key().lower()=="name") { |
77 | filename=it.data(); | 77 | filename=it.data(); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | s = body.Parts()[i].Size(); | 80 | s = body.Parts()[i].Size(); |
81 | w = 0; | 81 | w = 0; |
82 | while (s>1024) { | 82 | while (s>1024) { |
83 | s/=1024; | 83 | s/=1024; |
84 | ++w; | 84 | ++w; |
85 | if (w>=2) break; | 85 | if (w>=2) break; |
86 | } | 86 | } |
87 | switch(w) { | 87 | switch(w) { |
88 | case 1: | 88 | case 1: |
89 | q="k"; | 89 | q="k"; |
90 | break; | 90 | break; |
91 | case 2: | 91 | case 2: |
92 | q="M"; | 92 | q="M"; |
93 | break; | 93 | break; |
94 | default: | 94 | default: |
95 | q=""; | 95 | q=""; |
96 | break; | 96 | break; |
97 | } | 97 | } |
98 | QTextOStream o(&desc); | 98 | QTextOStream o(&desc); |
99 | if (w>0) o.precision(2); else o.precision(0); | 99 | if (w>0) o.precision(2); else o.precision(0); |
100 | o.setf(QTextStream::fixed); | 100 | o.setf(QTextStream::fixed); |
101 | o << s << " " << q << "Byte"; | 101 | o << s << " " << q << "Byte"; |
102 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); | 102 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int c ) { | 106 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int c ) { |
107 | if (!item ) | 107 | if (!item ) |
108 | return; | 108 | return; |
109 | 109 | ||
110 | QPopupMenu *menu = new QPopupMenu(); | 110 | QPopupMenu *menu = new QPopupMenu(); |
111 | int ret=0; | 111 | int ret=0; |
112 | 112 | ||
113 | if ( item->text( 0 ).left( 4 ) == "text" ) { | 113 | if ( item->text( 0 ).left( 4 ) == "text" ) { |
114 | menu->insertItem( tr( "Show Text" ), 1 ); | 114 | menu->insertItem( tr( "Show Text" ), 1 ); |
115 | } | 115 | } |
116 | menu->insertItem( tr( "Save Attachment" ), 0 ); | 116 | menu->insertItem( tr( "Save Attachment" ), 0 ); |
117 | menu->insertSeparator(1); | 117 | menu->insertSeparator(1); |
118 | 118 | ||
119 | ret = menu->exec( point, 0 ); | 119 | ret = menu->exec( point, 0 ); |
120 | 120 | ||
121 | switch(ret) { | 121 | switch(ret) { |
122 | case 0: | 122 | case 0: |
123 | { MimeTypes types; | 123 | { MimeTypes types; |
124 | types.insert( "all", "*" ); | 124 | types.insert( "all", "*" ); |
125 | QString str = OFileDialog::getSaveFileName( 1, | 125 | QString str = OFileDialog::getSaveFileName( 1, |
126 | "/", item->text( 1 ) , types, 0 ); | 126 | "/", item->text( 1 ) , types, 0 ); |
127 | 127 | ||
128 | if( !str.isEmpty() ) { | 128 | if( !str.isEmpty() ) { |
129 | qDebug( "first we will need a MIME wrapper" ); | 129 | qDebug( "first we will need a MIME wrapper" ); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | break ; | 132 | break ; |
133 | 133 | ||
134 | case 1: | 134 | case 1: |
135 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 135 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
136 | setText(); | 136 | setText(); |
137 | } else { | 137 | } else { |
138 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions | 138 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions |
139 | browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 139 | browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | break; | 142 | break; |
143 | } | 143 | } |
144 | delete menu; | 144 | delete menu; |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void ViewMail::setMail( RecMail mail ) { | 148 | void ViewMail::setMail( RecMail mail ) { |
149 | 149 | ||
150 | m_recMail = mail; | 150 | m_recMail = mail; |
151 | 151 | ||
152 | m_mail[0] = mail.getFrom(); | 152 | m_mail[0] = mail.getFrom(); |
153 | m_mail[1] = mail.getSubject(); | 153 | m_mail[1] = mail.getSubject(); |
154 | m_mail[3] = mail.getDate(); | 154 | m_mail[3] = mail.getDate(); |
155 | m_mail[4] = mail.Msgid(); | 155 | m_mail[4] = mail.Msgid(); |
156 | 156 | ||
157 | m_mail2[0] = mail.To(); | 157 | m_mail2[0] = mail.To(); |
158 | m_mail2[1] = mail.CC(); | 158 | m_mail2[1] = mail.CC(); |
159 | m_mail2[2] = mail.Bcc(); | 159 | m_mail2[2] = mail.Bcc(); |
160 | 160 | ||
161 | setText(); | 161 | setText(); |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | 165 | ||
166 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 166 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
167 | : ViewMailBase(parent, name, fl), _inLoop(false) | 167 | : ViewMailBase(parent, name, fl), _inLoop(false) |
168 | { | 168 | { |
169 | m_gotBody = false; | 169 | m_gotBody = false; |
170 | 170 | ||
171 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); | 171 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); |
172 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); | 172 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); |
173 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); | 173 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); |
174 | 174 | ||
175 | attachments->setEnabled(m_gotBody); | 175 | attachments->setEnabled(m_gotBody); |
176 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); | 176 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); |
177 | 177 | ||
178 | } | 178 | } |
179 | 179 | ||
180 | void ViewMail::setText() | 180 | void ViewMail::setText() |
181 | { | 181 | { |
182 | 182 | ||
183 | QString toString; | 183 | QString toString; |
184 | QString ccString; | 184 | QString ccString; |
185 | QString bccString; | 185 | QString bccString; |
186 | 186 | ||
187 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 187 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { |
188 | toString += (*it); | 188 | toString += (*it); |
189 | } | 189 | } |
190 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 190 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { |
191 | ccString += (*it); | 191 | ccString += (*it); |
192 | } | 192 | } |
193 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 193 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { |
194 | bccString += (*it); | 194 | bccString += (*it); |
195 | } | 195 | } |
196 | 196 | ||
197 | setCaption( caption().arg( m_mail[0] ) ); | 197 | setCaption( caption().arg( m_mail[0] ) ); |
198 | 198 | ||
199 | m_mailHtml = "<html><body>" | 199 | m_mailHtml = "<html><body>" |
200 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 200 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
201 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 201 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
202 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 202 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
203 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 203 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
204 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 204 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
205 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 205 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
206 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 206 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
207 | "</td></tr></table><font face=fixed>"; | 207 | "</td></tr></table><font face=fixed>"; |
208 | 208 | ||
209 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 209 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
210 | // remove later in favor of a real handling | 210 | // remove later in favor of a real handling |
211 | m_gotBody = true; | 211 | m_gotBody = true; |
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | ViewMail::~ViewMail() | 215 | ViewMail::~ViewMail() |
216 | { | 216 | { |
217 | hide(); | 217 | hide(); |
218 | } | 218 | } |
219 | 219 | ||
220 | void ViewMail::hide() | 220 | void ViewMail::hide() |
221 | { | 221 | { |
222 | QWidget::hide(); | 222 | QWidget::hide(); |
223 | 223 | ||
224 | if (_inLoop) { | 224 | if (_inLoop) { |
225 | _inLoop = false; | 225 | _inLoop = false; |
226 | qApp->exit_loop(); | 226 | qApp->exit_loop(); |
227 | 227 | ||
228 | } | 228 | } |
229 | 229 | ||
230 | } | 230 | } |
231 | 231 | ||
232 | void ViewMail::exec() | 232 | void ViewMail::exec() |
233 | { | 233 | { |
234 | show(); | 234 | show(); |
235 | 235 | ||
236 | if (!_inLoop) { | 236 | if (!_inLoop) { |
237 | _inLoop = true; | 237 | _inLoop = true; |
238 | qApp->enter_loop(); | 238 | qApp->enter_loop(); |
239 | } | 239 | } |
240 | 240 | ||
241 | } | 241 | } |
242 | 242 | ||
243 | QString ViewMail::deHtml(const QString &string) | 243 | QString ViewMail::deHtml(const QString &string) |
244 | { | 244 | { |
245 | QString string_ = string; | 245 | QString string_ = string; |
246 | string_.replace(QRegExp("&"), "&"); | 246 | string_.replace(QRegExp("&"), "&"); |
247 | string_.replace(QRegExp("<"), "<"); | 247 | string_.replace(QRegExp("<"), "<"); |
248 | string_.replace(QRegExp(">"), ">"); | 248 | string_.replace(QRegExp(">"), ">"); |
249 | string_.replace(QRegExp("\\n"), "<br>"); | 249 | string_.replace(QRegExp("\\n"), "<br>"); |
250 | return string_; | 250 | return string_; |
251 | } | 251 | } |
252 | 252 | ||
253 | void ViewMail::slotReply() | 253 | void ViewMail::slotReply() |
254 | { | 254 | { |
255 | if (!m_gotBody) { | 255 | if (!m_gotBody) { |
256 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 256 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | 259 | ||
260 | QString rtext; | 260 | QString rtext; |
261 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 261 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
262 | .arg( m_mail[1] ) | 262 | .arg( m_mail[0] ) |
263 | .arg( m_mail[3] ); | 263 | .arg( m_mail[3] ); |
264 | 264 | ||
265 | QString text = m_mail[2]; | 265 | QString text = m_mail[2]; |
266 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 266 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
267 | QStringList::Iterator it; | 267 | QStringList::Iterator it; |
268 | for (it = lines.begin(); it != lines.end(); it++) { | 268 | for (it = lines.begin(); it != lines.end(); it++) { |
269 | rtext += "> " + *it + "\n"; | 269 | rtext += "> " + *it + "\n"; |
270 | } | 270 | } |
271 | rtext += "\n"; | 271 | rtext += "\n"; |
272 | 272 | ||
273 | QString prefix; | 273 | QString prefix; |
274 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; | 274 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; |
275 | else prefix = "Re: "; // no i18n on purpose | 275 | else prefix = "Re: "; // no i18n on purpose |
276 | 276 | ||
277 | Settings *settings = new Settings(); | 277 | Settings *settings = new Settings(); |
278 | ComposeMail composer( settings ,this, 0, true); | 278 | ComposeMail composer( settings ,this, 0, true); |
279 | composer.setTo( m_mail[0] ); | 279 | composer.setTo( m_mail[0] ); |
280 | composer.setSubject( "Re: " + m_mail[1] ); | 280 | composer.setSubject( "Re: " + m_mail[1] ); |
281 | composer.setMessage( rtext ); | 281 | composer.setMessage( rtext ); |
282 | composer.showMaximized(); | 282 | composer.showMaximized(); |
283 | composer.exec(); | 283 | if ( QDialog::Accepted==composer.exec()) { |
284 | 284 | m_recMail.Wrapper()->answeredMail(m_recMail); | |
285 | } | ||
285 | } | 286 | } |
286 | 287 | ||
287 | void ViewMail::slotForward() | 288 | void ViewMail::slotForward() |
288 | { | 289 | { |
289 | if (!m_gotBody) { | 290 | if (!m_gotBody) { |
290 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 291 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
291 | return; | 292 | return; |
292 | } | 293 | } |
293 | 294 | ||
294 | QString ftext; | 295 | QString ftext; |
295 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 296 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
296 | .arg( m_mail[0] ); | 297 | .arg( m_mail[0] ); |
297 | if (!m_mail[3].isNull()) | 298 | if (!m_mail[3].isNull()) |
298 | ftext += QString("Date: %1\n") | 299 | ftext += QString("Date: %1\n") |
299 | .arg( m_mail[3] ); | 300 | .arg( m_mail[3] ); |
300 | if (!m_mail[0].isNull()) | 301 | if (!m_mail[0].isNull()) |
301 | ftext += QString("From: %1\n") | 302 | ftext += QString("From: %1\n") |
302 | .arg( m_mail[0] ); | 303 | .arg( m_mail[0] ); |
303 | if (!m_mail[1].isNull()) | 304 | if (!m_mail[1].isNull()) |
304 | ftext += QString("Subject: %1\n") | 305 | ftext += QString("Subject: %1\n") |
305 | .arg( m_mail[1] ); | 306 | .arg( m_mail[1] ); |
306 | 307 | ||
307 | ftext += QString("\n%1\n") | 308 | ftext += QString("\n%1\n") |
308 | .arg( m_mail[2]); | 309 | .arg( m_mail[2]); |
309 | 310 | ||
310 | ftext += QString("----- End forwarded message -----\n"); | 311 | ftext += QString("----- End forwarded message -----\n"); |
311 | 312 | ||
312 | Settings *settings = new Settings(); | 313 | Settings *settings = new Settings(); |
313 | ComposeMail composer( settings ,this, 0, true); | 314 | ComposeMail composer( settings ,this, 0, true); |
314 | composer.setSubject( "Fwd: " + m_mail[1] ); | 315 | composer.setSubject( "Fwd: " + m_mail[1] ); |
315 | composer.setMessage( ftext ); | 316 | composer.setMessage( ftext ); |
316 | composer.showMaximized(); | 317 | composer.showMaximized(); |
317 | composer.exec(); | 318 | if ( QDialog::Accepted==composer.exec()) { |
319 | |||
320 | } | ||
318 | } | 321 | } |
319 | 322 | ||
320 | void ViewMail::slotDeleteMail( ) | 323 | void ViewMail::slotDeleteMail( ) |
321 | { | 324 | { |
322 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 325 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
323 | m_recMail.Wrapper()->deleteMail( m_recMail ); | 326 | m_recMail.Wrapper()->deleteMail( m_recMail ); |
324 | hide(); | 327 | hide(); |
325 | deleted = true; | 328 | deleted = true; |
326 | } | 329 | } |
327 | } | 330 | } |