author | alwin <alwin> | 2004-01-10 03:19:09 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-10 03:19:09 (UTC) |
commit | dcfd6e5e2e2021bc5ed0bcf42b1b0a7002c59a17 (patch) (unidiff) | |
tree | 26f1eb9a79dfadd985e83618c70a116c91a8f810 | |
parent | 76cf4990cb4171a747ac31e9832f4ee694ced2cc (diff) | |
download | opie-dcfd6e5e2e2021bc5ed0bcf42b1b0a7002c59a17.zip opie-dcfd6e5e2e2021bc5ed0bcf42b1b0a7002c59a17.tar.gz opie-dcfd6e5e2e2021bc5ed0bcf42b1b0a7002c59a17.tar.bz2 |
when header displayed print just the count of messages not having
the \deleted flag set.
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 1c22c26..098dbdc 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,1098 +1,1098 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | 4 | ||
5 | #include "imapwrapper.h" | 5 | #include "imapwrapper.h" |
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | #include "logindialog.h" | 7 | #include "logindialog.h" |
8 | 8 | ||
9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
10 | : AbstractMail() | 10 | : AbstractMail() |
11 | { | 11 | { |
12 | account = a; | 12 | account = a; |
13 | m_imap = 0; | 13 | m_imap = 0; |
14 | m_Lastmbox = ""; | 14 | m_Lastmbox = ""; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | /* to avoid to often select statements in loops etc. | 22 | /* to avoid to often select statements in loops etc. |
23 | we trust that we are logged in and connection is established!*/ | 23 | we trust that we are logged in and connection is established!*/ |
24 | int IMAPwrapper::selectMbox(const QString&mbox) | 24 | int IMAPwrapper::selectMbox(const QString&mbox) |
25 | { | 25 | { |
26 | if (mbox == m_Lastmbox) { | 26 | if (mbox == m_Lastmbox) { |
27 | return MAILIMAP_NO_ERROR; | 27 | return MAILIMAP_NO_ERROR; |
28 | } | 28 | } |
29 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 29 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
30 | if ( err != MAILIMAP_NO_ERROR ) { | 30 | if ( err != MAILIMAP_NO_ERROR ) { |
31 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 31 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
32 | m_Lastmbox = ""; | 32 | m_Lastmbox = ""; |
33 | return err; | 33 | return err; |
34 | } | 34 | } |
35 | m_Lastmbox = mbox; | 35 | m_Lastmbox = mbox; |
36 | return err; | 36 | return err; |
37 | } | 37 | } |
38 | 38 | ||
39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
40 | { | 40 | { |
41 | qDebug( "IMAP: %i of %i", current, maximum ); | 41 | qDebug( "IMAP: %i of %i", current, maximum ); |
42 | } | 42 | } |
43 | 43 | ||
44 | void IMAPwrapper::login() | 44 | void IMAPwrapper::login() |
45 | { | 45 | { |
46 | const char *server, *user, *pass; | 46 | const char *server, *user, *pass; |
47 | uint16_t port; | 47 | uint16_t port; |
48 | int err = MAILIMAP_NO_ERROR; | 48 | int err = MAILIMAP_NO_ERROR; |
49 | 49 | ||
50 | if (account->getOffline()) return; | 50 | if (account->getOffline()) return; |
51 | /* we are connected this moment */ | 51 | /* we are connected this moment */ |
52 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 52 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
53 | if (m_imap) { | 53 | if (m_imap) { |
54 | err = mailimap_noop(m_imap); | 54 | err = mailimap_noop(m_imap); |
55 | if (err!=MAILIMAP_NO_ERROR) { | 55 | if (err!=MAILIMAP_NO_ERROR) { |
56 | logout(); | 56 | logout(); |
57 | } else { | 57 | } else { |
58 | mailstream_flush(m_imap->imap_stream); | 58 | mailstream_flush(m_imap->imap_stream); |
59 | return; | 59 | return; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | server = account->getServer().latin1(); | 62 | server = account->getServer().latin1(); |
63 | port = account->getPort().toUInt(); | 63 | port = account->getPort().toUInt(); |
64 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 64 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
65 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 65 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
66 | login.show(); | 66 | login.show(); |
67 | if ( QDialog::Accepted == login.exec() ) { | 67 | if ( QDialog::Accepted == login.exec() ) { |
68 | // ok | 68 | // ok |
69 | user = login.getUser().latin1(); | 69 | user = login.getUser().latin1(); |
70 | pass = login.getPassword().latin1(); | 70 | pass = login.getPassword().latin1(); |
71 | } else { | 71 | } else { |
72 | // cancel | 72 | // cancel |
73 | qDebug( "IMAP: Login canceled" ); | 73 | qDebug( "IMAP: Login canceled" ); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | } else { | 76 | } else { |
77 | user = account->getUser().latin1(); | 77 | user = account->getUser().latin1(); |
78 | pass = account->getPassword().latin1(); | 78 | pass = account->getPassword().latin1(); |
79 | } | 79 | } |
80 | 80 | ||
81 | m_imap = mailimap_new( 20, &imap_progress ); | 81 | m_imap = mailimap_new( 20, &imap_progress ); |
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | /* connect */ | 85 | /* connect */ |
86 | 86 | ||
87 | bool ssl = false; | 87 | bool ssl = false; |
88 | 88 | ||
89 | if ( account->ConnectionType() == 2 ) { | 89 | if ( account->ConnectionType() == 2 ) { |
90 | ssl = true; | 90 | ssl = true; |
91 | } | 91 | } |
92 | 92 | ||
93 | if ( ssl ) { | 93 | if ( ssl ) { |
94 | qDebug( "using ssl" ); | 94 | qDebug( "using ssl" ); |
95 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 95 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
96 | } else { | 96 | } else { |
97 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 97 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
98 | } | 98 | } |
99 | 99 | ||
100 | if ( err != MAILIMAP_NO_ERROR && | 100 | if ( err != MAILIMAP_NO_ERROR && |
101 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 101 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
102 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 102 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
103 | QString failure = ""; | 103 | QString failure = ""; |
104 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 104 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
105 | failure="Connection refused"; | 105 | failure="Connection refused"; |
106 | } else { | 106 | } else { |
107 | failure="Unknown failure"; | 107 | failure="Unknown failure"; |
108 | } | 108 | } |
109 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 109 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
110 | mailimap_free( m_imap ); | 110 | mailimap_free( m_imap ); |
111 | m_imap = 0; | 111 | m_imap = 0; |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
115 | /* login */ | 115 | /* login */ |
116 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 116 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
117 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
118 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 118 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
119 | err = mailimap_close( m_imap ); | 119 | err = mailimap_close( m_imap ); |
120 | mailimap_free( m_imap ); | 120 | mailimap_free( m_imap ); |
121 | m_imap = 0; | 121 | m_imap = 0; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | void IMAPwrapper::logout() | 125 | void IMAPwrapper::logout() |
126 | { | 126 | { |
127 | int err = MAILIMAP_NO_ERROR; | 127 | int err = MAILIMAP_NO_ERROR; |
128 | if (!m_imap) return; | 128 | if (!m_imap) return; |
129 | err = mailimap_logout( m_imap ); | 129 | err = mailimap_logout( m_imap ); |
130 | err = mailimap_close( m_imap ); | 130 | err = mailimap_close( m_imap ); |
131 | mailimap_free( m_imap ); | 131 | mailimap_free( m_imap ); |
132 | m_imap = 0; | 132 | m_imap = 0; |
133 | m_Lastmbox = ""; | 133 | m_Lastmbox = ""; |
134 | } | 134 | } |
135 | 135 | ||
136 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 136 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
137 | { | 137 | { |
138 | int err = MAILIMAP_NO_ERROR; | 138 | int err = MAILIMAP_NO_ERROR; |
139 | clist *result = 0; | 139 | clist *result = 0; |
140 | clistcell *current; | 140 | clistcell *current; |
141 | mailimap_fetch_type *fetchType = 0; | 141 | mailimap_fetch_type *fetchType = 0; |
142 | mailimap_set *set = 0; | 142 | mailimap_set *set = 0; |
143 | 143 | ||
144 | login(); | 144 | login(); |
145 | if (!m_imap) { | 145 | if (!m_imap) { |
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | /* select mailbox READONLY for operations */ | 148 | /* select mailbox READONLY for operations */ |
149 | err = selectMbox(mailbox); | 149 | err = selectMbox(mailbox); |
150 | if ( err != MAILIMAP_NO_ERROR ) { | 150 | if ( err != MAILIMAP_NO_ERROR ) { |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | 153 | ||
154 | int last = m_imap->imap_selection_info->sel_exists; | 154 | int last = m_imap->imap_selection_info->sel_exists; |
155 | 155 | ||
156 | if (last == 0) { | 156 | if (last == 0) { |
157 | Global::statusMessage(tr("Mailbox has no mails")); | 157 | Global::statusMessage(tr("Mailbox has no mails")); |
158 | return; | 158 | return; |
159 | } else { | 159 | } else { |
160 | Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); | ||
161 | } | 160 | } |
162 | 161 | ||
163 | /* the range has to start at 1!!! not with 0!!!! */ | 162 | /* the range has to start at 1!!! not with 0!!!! */ |
164 | set = mailimap_set_new_interval( 1, last ); | 163 | set = mailimap_set_new_interval( 1, last ); |
165 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 164 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
166 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 165 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
167 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 166 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
168 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 167 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
169 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 168 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
170 | 169 | ||
171 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 170 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
172 | mailimap_set_free( set ); | 171 | mailimap_set_free( set ); |
173 | mailimap_fetch_type_free( fetchType ); | 172 | mailimap_fetch_type_free( fetchType ); |
174 | 173 | ||
175 | QString date,subject,from; | 174 | QString date,subject,from; |
176 | 175 | ||
177 | if ( err == MAILIMAP_NO_ERROR ) { | 176 | if ( err == MAILIMAP_NO_ERROR ) { |
178 | mailimap_msg_att * msg_att; | 177 | mailimap_msg_att * msg_att; |
179 | int i = 0; | 178 | int i = 0; |
180 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 179 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
181 | ++i; | 180 | ++i; |
182 | msg_att = (mailimap_msg_att*)current->data; | 181 | msg_att = (mailimap_msg_att*)current->data; |
183 | RecMail*m = parse_list_result(msg_att); | 182 | RecMail*m = parse_list_result(msg_att); |
184 | if (m) { | 183 | if (m) { |
185 | m->setNumber(i); | 184 | m->setNumber(i); |
186 | m->setMbox(mailbox); | 185 | m->setMbox(mailbox); |
187 | m->setWrapper(this); | 186 | m->setWrapper(this); |
188 | target.append(m); | 187 | target.append(m); |
189 | } | 188 | } |
190 | } | 189 | } |
190 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | ||
191 | } else { | 191 | } else { |
192 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 192 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
193 | } | 193 | } |
194 | if (result) mailimap_fetch_list_free(result); | 194 | if (result) mailimap_fetch_list_free(result); |
195 | } | 195 | } |
196 | 196 | ||
197 | QList<Folder>* IMAPwrapper::listFolders() | 197 | QList<Folder>* IMAPwrapper::listFolders() |
198 | { | 198 | { |
199 | const char *path, *mask; | 199 | const char *path, *mask; |
200 | int err = MAILIMAP_NO_ERROR; | 200 | int err = MAILIMAP_NO_ERROR; |
201 | clist *result = 0; | 201 | clist *result = 0; |
202 | clistcell *current = 0; | 202 | clistcell *current = 0; |
203 | clistcell*cur_flag = 0; | 203 | clistcell*cur_flag = 0; |
204 | mailimap_mbx_list_flags*bflags = 0; | 204 | mailimap_mbx_list_flags*bflags = 0; |
205 | 205 | ||
206 | QList<Folder> * folders = new QList<Folder>(); | 206 | QList<Folder> * folders = new QList<Folder>(); |
207 | folders->setAutoDelete( false ); | 207 | folders->setAutoDelete( false ); |
208 | login(); | 208 | login(); |
209 | if (!m_imap) { | 209 | if (!m_imap) { |
210 | return folders; | 210 | return folders; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* | 213 | /* |
214 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 214 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
215 | * We must not forget to filter them out in next loop! | 215 | * We must not forget to filter them out in next loop! |
216 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 216 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
217 | */ | 217 | */ |
218 | QString temp; | 218 | QString temp; |
219 | mask = "INBOX" ; | 219 | mask = "INBOX" ; |
220 | mailimap_mailbox_list *list; | 220 | mailimap_mailbox_list *list; |
221 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 221 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
222 | QString del; | 222 | QString del; |
223 | bool selectable = true; | 223 | bool selectable = true; |
224 | bool no_inferiors = false; | 224 | bool no_inferiors = false; |
225 | if ( err == MAILIMAP_NO_ERROR ) { | 225 | if ( err == MAILIMAP_NO_ERROR ) { |
226 | current = result->first; | 226 | current = result->first; |
227 | for ( int i = result->count; i > 0; i-- ) { | 227 | for ( int i = result->count; i > 0; i-- ) { |
228 | list = (mailimap_mailbox_list *) current->data; | 228 | list = (mailimap_mailbox_list *) current->data; |
229 | // it is better use the deep copy mechanism of qt itself | 229 | // it is better use the deep copy mechanism of qt itself |
230 | // instead of using strdup! | 230 | // instead of using strdup! |
231 | temp = list->mb_name; | 231 | temp = list->mb_name; |
232 | del = list->mb_delimiter; | 232 | del = list->mb_delimiter; |
233 | current = current->next; | 233 | current = current->next; |
234 | if ( (bflags = list->mb_flag) ) { | 234 | if ( (bflags = list->mb_flag) ) { |
235 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 235 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
236 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 236 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
237 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 237 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
238 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 238 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
239 | no_inferiors = true; | 239 | no_inferiors = true; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | } | 242 | } |
243 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 243 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
244 | } | 244 | } |
245 | } else { | 245 | } else { |
246 | qDebug("error fetching folders: %s",m_imap->imap_response); | 246 | qDebug("error fetching folders: %s",m_imap->imap_response); |
247 | } | 247 | } |
248 | mailimap_list_result_free( result ); | 248 | mailimap_list_result_free( result ); |
249 | 249 | ||
250 | /* | 250 | /* |
251 | * second stage - get the other then inbox folders | 251 | * second stage - get the other then inbox folders |
252 | */ | 252 | */ |
253 | mask = "*" ; | 253 | mask = "*" ; |
254 | path = account->getPrefix().latin1(); | 254 | path = account->getPrefix().latin1(); |
255 | if (!path) path = ""; | 255 | if (!path) path = ""; |
256 | qDebug(path); | 256 | qDebug(path); |
257 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 257 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
258 | if ( err == MAILIMAP_NO_ERROR ) { | 258 | if ( err == MAILIMAP_NO_ERROR ) { |
259 | current = result->first; | 259 | current = result->first; |
260 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 260 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
261 | no_inferiors = false; | 261 | no_inferiors = false; |
262 | list = (mailimap_mailbox_list *) current->data; | 262 | list = (mailimap_mailbox_list *) current->data; |
263 | // it is better use the deep copy mechanism of qt itself | 263 | // it is better use the deep copy mechanism of qt itself |
264 | // instead of using strdup! | 264 | // instead of using strdup! |
265 | temp = list->mb_name; | 265 | temp = list->mb_name; |
266 | if (temp.lower()=="inbox") | 266 | if (temp.lower()=="inbox") |
267 | continue; | 267 | continue; |
268 | if (temp.lower()==account->getPrefix().lower()) | 268 | if (temp.lower()==account->getPrefix().lower()) |
269 | continue; | 269 | continue; |
270 | if ( (bflags = list->mb_flag) ) { | 270 | if ( (bflags = list->mb_flag) ) { |
271 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 271 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
272 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 272 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
273 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 273 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
274 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 274 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
275 | no_inferiors = true; | 275 | no_inferiors = true; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | del = list->mb_delimiter; | 279 | del = list->mb_delimiter; |
280 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 280 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
281 | } | 281 | } |
282 | } else { | 282 | } else { |
283 | qDebug("error fetching folders %s",m_imap->imap_response); | 283 | qDebug("error fetching folders %s",m_imap->imap_response); |
284 | } | 284 | } |
285 | if (result) mailimap_list_result_free( result ); | 285 | if (result) mailimap_list_result_free( result ); |
286 | return folders; | 286 | return folders; |
287 | } | 287 | } |
288 | 288 | ||
289 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 289 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
290 | { | 290 | { |
291 | RecMail * m = 0; | 291 | RecMail * m = 0; |
292 | mailimap_msg_att_item *item=0; | 292 | mailimap_msg_att_item *item=0; |
293 | clistcell *current,*c,*cf; | 293 | clistcell *current,*c,*cf; |
294 | mailimap_msg_att_dynamic*flist; | 294 | mailimap_msg_att_dynamic*flist; |
295 | mailimap_flag_fetch*cflag; | 295 | mailimap_flag_fetch*cflag; |
296 | int size; | 296 | int size; |
297 | QBitArray mFlags(7); | 297 | QBitArray mFlags(7); |
298 | QStringList addresslist; | 298 | QStringList addresslist; |
299 | 299 | ||
300 | if (!m_att) { | 300 | if (!m_att) { |
301 | return m; | 301 | return m; |
302 | } | 302 | } |
303 | m = new RecMail(); | 303 | m = new RecMail(); |
304 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 304 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
305 | current = c; | 305 | current = c; |
306 | size = 0; | 306 | size = 0; |
307 | item = (mailimap_msg_att_item*)current->data; | 307 | item = (mailimap_msg_att_item*)current->data; |
308 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 308 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
309 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 309 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
310 | if (!flist->att_list) { | 310 | if (!flist->att_list) { |
311 | continue; | 311 | continue; |
312 | } | 312 | } |
313 | cf = flist->att_list->first; | 313 | cf = flist->att_list->first; |
314 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 314 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
315 | cflag = (mailimap_flag_fetch*)cf->data; | 315 | cflag = (mailimap_flag_fetch*)cf->data; |
316 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 316 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
317 | switch (cflag->fl_flag->fl_type) { | 317 | switch (cflag->fl_flag->fl_type) { |
318 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 318 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
319 | mFlags.setBit(FLAG_ANSWERED); | 319 | mFlags.setBit(FLAG_ANSWERED); |
320 | break; | 320 | break; |
321 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 321 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
322 | mFlags.setBit(FLAG_FLAGGED); | 322 | mFlags.setBit(FLAG_FLAGGED); |
323 | break; | 323 | break; |
324 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 324 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
325 | mFlags.setBit(FLAG_DELETED); | 325 | mFlags.setBit(FLAG_DELETED); |
326 | break; | 326 | break; |
327 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 327 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
328 | mFlags.setBit(FLAG_SEEN); | 328 | mFlags.setBit(FLAG_SEEN); |
329 | break; | 329 | break; |
330 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 330 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
331 | mFlags.setBit(FLAG_DRAFT); | 331 | mFlags.setBit(FLAG_DRAFT); |
332 | break; | 332 | break; |
333 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 333 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
334 | break; | 334 | break; |
335 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 335 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
336 | break; | 336 | break; |
337 | default: | 337 | default: |
338 | break; | 338 | break; |
339 | } | 339 | } |
340 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 340 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
341 | mFlags.setBit(FLAG_RECENT); | 341 | mFlags.setBit(FLAG_RECENT); |
342 | } | 342 | } |
343 | } | 343 | } |
344 | continue; | 344 | continue; |
345 | } | 345 | } |
346 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 346 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
347 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 347 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
348 | m->setDate(head->env_date); | 348 | m->setDate(head->env_date); |
349 | m->setSubject(convert_String((const char*)head->env_subject)); | 349 | m->setSubject(convert_String((const char*)head->env_subject)); |
350 | //m->setSubject(head->env_subject); | 350 | //m->setSubject(head->env_subject); |
351 | if (head->env_from!=NULL) { | 351 | if (head->env_from!=NULL) { |
352 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 352 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
353 | if (addresslist.count()) { | 353 | if (addresslist.count()) { |
354 | m->setFrom(addresslist.first()); | 354 | m->setFrom(addresslist.first()); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | if (head->env_to!=NULL) { | 357 | if (head->env_to!=NULL) { |
358 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 358 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
359 | m->setTo(addresslist); | 359 | m->setTo(addresslist); |
360 | } | 360 | } |
361 | if (head->env_cc!=NULL) { | 361 | if (head->env_cc!=NULL) { |
362 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 362 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
363 | m->setCC(addresslist); | 363 | m->setCC(addresslist); |
364 | } | 364 | } |
365 | if (head->env_bcc!=NULL) { | 365 | if (head->env_bcc!=NULL) { |
366 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 366 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
367 | m->setBcc(addresslist); | 367 | m->setBcc(addresslist); |
368 | } | 368 | } |
369 | if (head->env_reply_to!=NULL) { | 369 | if (head->env_reply_to!=NULL) { |
370 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 370 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
371 | if (addresslist.count()) { | 371 | if (addresslist.count()) { |
372 | m->setReplyto(addresslist.first()); | 372 | m->setReplyto(addresslist.first()); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | m->setMsgid(QString(head->env_message_id)); | 375 | m->setMsgid(QString(head->env_message_id)); |
376 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 376 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
377 | #if 0 | 377 | #if 0 |
378 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 378 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
379 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 379 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
380 | 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); | 380 | 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); |
381 | qDebug(da.toString()); | 381 | qDebug(da.toString()); |
382 | #endif | 382 | #endif |
383 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 383 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
384 | size = item->att_data.att_static->att_data.att_rfc822_size; | 384 | size = item->att_data.att_static->att_data.att_rfc822_size; |
385 | } | 385 | } |
386 | } | 386 | } |
387 | /* msg is already deleted */ | 387 | /* msg is already deleted */ |
388 | if (mFlags.testBit(FLAG_DELETED) && m) { | 388 | if (mFlags.testBit(FLAG_DELETED) && m) { |
389 | delete m; | 389 | delete m; |
390 | m = 0; | 390 | m = 0; |
391 | } | 391 | } |
392 | if (m) { | 392 | if (m) { |
393 | m->setFlags(mFlags); | 393 | m->setFlags(mFlags); |
394 | m->setMsgsize(size); | 394 | m->setMsgsize(size); |
395 | } | 395 | } |
396 | return m; | 396 | return m; |
397 | } | 397 | } |
398 | 398 | ||
399 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 399 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
400 | { | 400 | { |
401 | RecBody body; | 401 | RecBody body; |
402 | const char *mb; | 402 | const char *mb; |
403 | int err = MAILIMAP_NO_ERROR; | 403 | int err = MAILIMAP_NO_ERROR; |
404 | clist *result = 0; | 404 | clist *result = 0; |
405 | clistcell *current; | 405 | clistcell *current; |
406 | mailimap_fetch_att *fetchAtt = 0; | 406 | mailimap_fetch_att *fetchAtt = 0; |
407 | mailimap_fetch_type *fetchType = 0; | 407 | mailimap_fetch_type *fetchType = 0; |
408 | mailimap_set *set = 0; | 408 | mailimap_set *set = 0; |
409 | mailimap_body*body_desc = 0; | 409 | mailimap_body*body_desc = 0; |
410 | 410 | ||
411 | mb = mail.getMbox().latin1(); | 411 | mb = mail.getMbox().latin1(); |
412 | 412 | ||
413 | login(); | 413 | login(); |
414 | if (!m_imap) { | 414 | if (!m_imap) { |
415 | return body; | 415 | return body; |
416 | } | 416 | } |
417 | err = selectMbox(mail.getMbox()); | 417 | err = selectMbox(mail.getMbox()); |
418 | if ( err != MAILIMAP_NO_ERROR ) { | 418 | if ( err != MAILIMAP_NO_ERROR ) { |
419 | return body; | 419 | return body; |
420 | } | 420 | } |
421 | 421 | ||
422 | /* the range has to start at 1!!! not with 0!!!! */ | 422 | /* the range has to start at 1!!! not with 0!!!! */ |
423 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 423 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
424 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 424 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
425 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 425 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
426 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 426 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
427 | mailimap_set_free( set ); | 427 | mailimap_set_free( set ); |
428 | mailimap_fetch_type_free( fetchType ); | 428 | mailimap_fetch_type_free( fetchType ); |
429 | 429 | ||
430 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 430 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
431 | mailimap_msg_att * msg_att; | 431 | mailimap_msg_att * msg_att; |
432 | msg_att = (mailimap_msg_att*)current->data; | 432 | msg_att = (mailimap_msg_att*)current->data; |
433 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 433 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
434 | QValueList<int> path; | 434 | QValueList<int> path; |
435 | body_desc = item->att_data.att_static->att_data.att_body; | 435 | body_desc = item->att_data.att_static->att_data.att_body; |
436 | traverseBody(mail,body_desc,body,0,path); | 436 | traverseBody(mail,body_desc,body,0,path); |
437 | } else { | 437 | } else { |
438 | qDebug("error fetching body: %s",m_imap->imap_response); | 438 | qDebug("error fetching body: %s",m_imap->imap_response); |
439 | } | 439 | } |
440 | if (result) mailimap_fetch_list_free(result); | 440 | if (result) mailimap_fetch_list_free(result); |
441 | return body; | 441 | return body; |
442 | } | 442 | } |
443 | 443 | ||
444 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 444 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
445 | { | 445 | { |
446 | QStringList l; | 446 | QStringList l; |
447 | QString from; | 447 | QString from; |
448 | bool named_from; | 448 | bool named_from; |
449 | clistcell *current = NULL; | 449 | clistcell *current = NULL; |
450 | mailimap_address * current_address=NULL; | 450 | mailimap_address * current_address=NULL; |
451 | if (!list) { | 451 | if (!list) { |
452 | return l; | 452 | return l; |
453 | } | 453 | } |
454 | unsigned int count = 0; | 454 | unsigned int count = 0; |
455 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 455 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
456 | from = ""; | 456 | from = ""; |
457 | named_from = false; | 457 | named_from = false; |
458 | current_address=(mailimap_address*)current->data; | 458 | current_address=(mailimap_address*)current->data; |
459 | if (current_address->ad_personal_name){ | 459 | if (current_address->ad_personal_name){ |
460 | from+=convert_String((const char*)current_address->ad_personal_name); | 460 | from+=convert_String((const char*)current_address->ad_personal_name); |
461 | from+=" "; | 461 | from+=" "; |
462 | named_from = true; | 462 | named_from = true; |
463 | } | 463 | } |
464 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 464 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
465 | from+="<"; | 465 | from+="<"; |
466 | } | 466 | } |
467 | if (current_address->ad_mailbox_name) { | 467 | if (current_address->ad_mailbox_name) { |
468 | from+=QString(current_address->ad_mailbox_name); | 468 | from+=QString(current_address->ad_mailbox_name); |
469 | from+="@"; | 469 | from+="@"; |
470 | } | 470 | } |
471 | if (current_address->ad_host_name) { | 471 | if (current_address->ad_host_name) { |
472 | from+=QString(current_address->ad_host_name); | 472 | from+=QString(current_address->ad_host_name); |
473 | } | 473 | } |
474 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 474 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
475 | from+=">"; | 475 | from+=">"; |
476 | } | 476 | } |
477 | l.append(QString(from)); | 477 | l.append(QString(from)); |
478 | if (++count > 99) { | 478 | if (++count > 99) { |
479 | break; | 479 | break; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | return l; | 482 | return l; |
483 | } | 483 | } |
484 | 484 | ||
485 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 485 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
486 | { | 486 | { |
487 | encodedString*res=new encodedString; | 487 | encodedString*res=new encodedString; |
488 | int err; | 488 | int err; |
489 | mailimap_fetch_type *fetchType; | 489 | mailimap_fetch_type *fetchType; |
490 | mailimap_set *set; | 490 | mailimap_set *set; |
491 | clistcell*current,*cur; | 491 | clistcell*current,*cur; |
492 | mailimap_section_part * section_part = 0; | 492 | mailimap_section_part * section_part = 0; |
493 | mailimap_section_spec * section_spec = 0; | 493 | mailimap_section_spec * section_spec = 0; |
494 | mailimap_section * section = 0; | 494 | mailimap_section * section = 0; |
495 | mailimap_fetch_att * fetch_att = 0; | 495 | mailimap_fetch_att * fetch_att = 0; |
496 | 496 | ||
497 | login(); | 497 | login(); |
498 | if (!m_imap) { | 498 | if (!m_imap) { |
499 | return res; | 499 | return res; |
500 | } | 500 | } |
501 | if (!internal_call) { | 501 | if (!internal_call) { |
502 | err = selectMbox(mail.getMbox()); | 502 | err = selectMbox(mail.getMbox()); |
503 | if ( err != MAILIMAP_NO_ERROR ) { | 503 | if ( err != MAILIMAP_NO_ERROR ) { |
504 | return res; | 504 | return res; |
505 | } | 505 | } |
506 | } | 506 | } |
507 | set = mailimap_set_new_single(mail.getNumber()); | 507 | set = mailimap_set_new_single(mail.getNumber()); |
508 | 508 | ||
509 | clist*id_list = 0; | 509 | clist*id_list = 0; |
510 | 510 | ||
511 | /* if path == empty then its a request for the whole rfc822 mail and generates | 511 | /* if path == empty then its a request for the whole rfc822 mail and generates |
512 | a "fetch <id> (body[])" statement on imap server */ | 512 | a "fetch <id> (body[])" statement on imap server */ |
513 | if (path.count()>0 ) { | 513 | if (path.count()>0 ) { |
514 | id_list = clist_new(); | 514 | id_list = clist_new(); |
515 | for (unsigned j=0; j < path.count();++j) { | 515 | for (unsigned j=0; j < path.count();++j) { |
516 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 516 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
517 | *p_id = path[j]; | 517 | *p_id = path[j]; |
518 | clist_append(id_list,p_id); | 518 | clist_append(id_list,p_id); |
519 | } | 519 | } |
520 | section_part = mailimap_section_part_new(id_list); | 520 | section_part = mailimap_section_part_new(id_list); |
521 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 521 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
522 | } | 522 | } |
523 | 523 | ||
524 | section = mailimap_section_new(section_spec); | 524 | section = mailimap_section_new(section_spec); |
525 | fetch_att = mailimap_fetch_att_new_body_section(section); | 525 | fetch_att = mailimap_fetch_att_new_body_section(section); |
526 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 526 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
527 | 527 | ||
528 | clist*result = 0; | 528 | clist*result = 0; |
529 | 529 | ||
530 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 530 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
531 | mailimap_set_free( set ); | 531 | mailimap_set_free( set ); |
532 | mailimap_fetch_type_free( fetchType ); | 532 | mailimap_fetch_type_free( fetchType ); |
533 | 533 | ||
534 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 534 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
535 | mailimap_msg_att * msg_att; | 535 | mailimap_msg_att * msg_att; |
536 | msg_att = (mailimap_msg_att*)current->data; | 536 | msg_att = (mailimap_msg_att*)current->data; |
537 | mailimap_msg_att_item*msg_att_item; | 537 | mailimap_msg_att_item*msg_att_item; |
538 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 538 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
539 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 539 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
540 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 540 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
541 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 541 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
542 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 542 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
543 | /* detach - we take over the content */ | 543 | /* detach - we take over the content */ |
544 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 544 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
545 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 545 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } | 548 | } |
549 | } else { | 549 | } else { |
550 | qDebug("error fetching text: %s",m_imap->imap_response); | 550 | qDebug("error fetching text: %s",m_imap->imap_response); |
551 | } | 551 | } |
552 | if (result) mailimap_fetch_list_free(result); | 552 | if (result) mailimap_fetch_list_free(result); |
553 | return res; | 553 | return res; |
554 | } | 554 | } |
555 | 555 | ||
556 | /* current_recursion is for recursive calls. | 556 | /* current_recursion is for recursive calls. |
557 | current_count means the position inside the internal loop! */ | 557 | current_count means the position inside the internal loop! */ |
558 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | 558 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, |
559 | int current_recursion,QValueList<int>recList,int current_count) | 559 | int current_recursion,QValueList<int>recList,int current_count) |
560 | { | 560 | { |
561 | if (!body || current_recursion>=10) { | 561 | if (!body || current_recursion>=10) { |
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | switch (body->bd_type) { | 564 | switch (body->bd_type) { |
565 | case MAILIMAP_BODY_1PART: | 565 | case MAILIMAP_BODY_1PART: |
566 | { | 566 | { |
567 | QValueList<int>countlist = recList; | 567 | QValueList<int>countlist = recList; |
568 | countlist.append(current_count); | 568 | countlist.append(current_count); |
569 | RecPart currentPart; | 569 | RecPart currentPart; |
570 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 570 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
571 | QString id(""); | 571 | QString id(""); |
572 | currentPart.setPositionlist(countlist); | 572 | currentPart.setPositionlist(countlist); |
573 | for (unsigned int j = 0; j < countlist.count();++j) { | 573 | for (unsigned int j = 0; j < countlist.count();++j) { |
574 | id+=(j>0?" ":""); | 574 | id+=(j>0?" ":""); |
575 | id+=QString("%1").arg(countlist[j]); | 575 | id+=QString("%1").arg(countlist[j]); |
576 | } | 576 | } |
577 | qDebug("ID = %s",id.latin1()); | 577 | qDebug("ID = %s",id.latin1()); |
578 | currentPart.setIdentifier(id); | 578 | currentPart.setIdentifier(id); |
579 | fillSinglePart(currentPart,part1); | 579 | fillSinglePart(currentPart,part1); |
580 | /* important: Check for is NULL 'cause a body can be empty! | 580 | /* important: Check for is NULL 'cause a body can be empty! |
581 | And we put it only into the mail if it is the FIRST part */ | 581 | And we put it only into the mail if it is the FIRST part */ |
582 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { | 582 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
583 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 583 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
584 | target_body.setDescription(currentPart); | 584 | target_body.setDescription(currentPart); |
585 | target_body.setBodytext(body_text); | 585 | target_body.setBodytext(body_text); |
586 | if (countlist.count()>1) { | 586 | if (countlist.count()>1) { |
587 | target_body.addPart(currentPart); | 587 | target_body.addPart(currentPart); |
588 | } | 588 | } |
589 | } else { | 589 | } else { |
590 | target_body.addPart(currentPart); | 590 | target_body.addPart(currentPart); |
591 | } | 591 | } |
592 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 592 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
593 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 593 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
594 | } | 594 | } |
595 | } | 595 | } |
596 | break; | 596 | break; |
597 | case MAILIMAP_BODY_MPART: | 597 | case MAILIMAP_BODY_MPART: |
598 | { | 598 | { |
599 | QValueList<int>countlist = recList; | 599 | QValueList<int>countlist = recList; |
600 | clistcell*current=0; | 600 | clistcell*current=0; |
601 | mailimap_body*current_body=0; | 601 | mailimap_body*current_body=0; |
602 | unsigned int ccount = 1; | 602 | unsigned int ccount = 1; |
603 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 603 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
604 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 604 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
605 | current_body = (mailimap_body*)current->data; | 605 | current_body = (mailimap_body*)current->data; |
606 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 606 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
607 | RecPart targetPart; | 607 | RecPart targetPart; |
608 | targetPart.setType("multipart"); | 608 | targetPart.setType("multipart"); |
609 | fillMultiPart(targetPart,mailDescription); | 609 | fillMultiPart(targetPart,mailDescription); |
610 | countlist.append(current_count); | 610 | countlist.append(current_count); |
611 | targetPart.setPositionlist(countlist); | 611 | targetPart.setPositionlist(countlist); |
612 | target_body.addPart(targetPart); | 612 | target_body.addPart(targetPart); |
613 | QString id(""); | 613 | QString id(""); |
614 | for (unsigned int j = 0; j < countlist.count();++j) { | 614 | for (unsigned int j = 0; j < countlist.count();++j) { |
615 | id+=(j>0?" ":""); | 615 | id+=(j>0?" ":""); |
616 | id+=QString("%1").arg(countlist[j]); | 616 | id+=QString("%1").arg(countlist[j]); |
617 | } | 617 | } |
618 | qDebug("ID(mpart) = %s",id.latin1()); | 618 | qDebug("ID(mpart) = %s",id.latin1()); |
619 | } | 619 | } |
620 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 620 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
621 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 621 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
622 | countlist = recList; | 622 | countlist = recList; |
623 | } | 623 | } |
624 | ++ccount; | 624 | ++ccount; |
625 | } | 625 | } |
626 | } | 626 | } |
627 | break; | 627 | break; |
628 | default: | 628 | default: |
629 | break; | 629 | break; |
630 | } | 630 | } |
631 | } | 631 | } |
632 | 632 | ||
633 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 633 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
634 | { | 634 | { |
635 | if (!Description) { | 635 | if (!Description) { |
636 | return; | 636 | return; |
637 | } | 637 | } |
638 | switch (Description->bd_type) { | 638 | switch (Description->bd_type) { |
639 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 639 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
640 | target_part.setType("text"); | 640 | target_part.setType("text"); |
641 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 641 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
642 | break; | 642 | break; |
643 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 643 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
644 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 644 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
645 | break; | 645 | break; |
646 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 646 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
647 | target_part.setType("message"); | 647 | target_part.setType("message"); |
648 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 648 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
649 | break; | 649 | break; |
650 | default: | 650 | default: |
651 | break; | 651 | break; |
652 | } | 652 | } |
653 | } | 653 | } |
654 | 654 | ||
655 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 655 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
656 | { | 656 | { |
657 | if (!which) { | 657 | if (!which) { |
658 | return; | 658 | return; |
659 | } | 659 | } |
660 | QString sub; | 660 | QString sub; |
661 | sub = which->bd_media_text; | 661 | sub = which->bd_media_text; |
662 | qDebug("Type= text/%s",which->bd_media_text); | 662 | qDebug("Type= text/%s",which->bd_media_text); |
663 | target_part.setSubtype(sub.lower()); | 663 | target_part.setSubtype(sub.lower()); |
664 | target_part.setLines(which->bd_lines); | 664 | target_part.setLines(which->bd_lines); |
665 | fillBodyFields(target_part,which->bd_fields); | 665 | fillBodyFields(target_part,which->bd_fields); |
666 | } | 666 | } |
667 | 667 | ||
668 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 668 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
669 | { | 669 | { |
670 | if (!which) { | 670 | if (!which) { |
671 | return; | 671 | return; |
672 | } | 672 | } |
673 | target_part.setSubtype("rfc822"); | 673 | target_part.setSubtype("rfc822"); |
674 | qDebug("Message part"); | 674 | qDebug("Message part"); |
675 | /* we set this type to text/plain */ | 675 | /* we set this type to text/plain */ |
676 | target_part.setLines(which->bd_lines); | 676 | target_part.setLines(which->bd_lines); |
677 | fillBodyFields(target_part,which->bd_fields); | 677 | fillBodyFields(target_part,which->bd_fields); |
678 | } | 678 | } |
679 | 679 | ||
680 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 680 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) |
681 | { | 681 | { |
682 | if (!which) return; | 682 | if (!which) return; |
683 | QString sub = which->bd_media_subtype; | 683 | QString sub = which->bd_media_subtype; |
684 | target_part.setSubtype(sub.lower()); | 684 | target_part.setSubtype(sub.lower()); |
685 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 685 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
686 | clistcell*cur = 0; | 686 | clistcell*cur = 0; |
687 | mailimap_single_body_fld_param*param=0; | 687 | mailimap_single_body_fld_param*param=0; |
688 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 688 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
689 | param = (mailimap_single_body_fld_param*)cur->data; | 689 | param = (mailimap_single_body_fld_param*)cur->data; |
690 | if (param) { | 690 | if (param) { |
691 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 691 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | } | 694 | } |
695 | } | 695 | } |
696 | 696 | ||
697 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 697 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
698 | { | 698 | { |
699 | if (!which) { | 699 | if (!which) { |
700 | return; | 700 | return; |
701 | } | 701 | } |
702 | QString type,sub; | 702 | QString type,sub; |
703 | switch (which->bd_media_basic->med_type) { | 703 | switch (which->bd_media_basic->med_type) { |
704 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 704 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
705 | type = "application"; | 705 | type = "application"; |
706 | break; | 706 | break; |
707 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 707 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
708 | type = "audio"; | 708 | type = "audio"; |
709 | break; | 709 | break; |
710 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 710 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
711 | type = "image"; | 711 | type = "image"; |
712 | break; | 712 | break; |
713 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 713 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
714 | type = "message"; | 714 | type = "message"; |
715 | break; | 715 | break; |
716 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 716 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
717 | type = "video"; | 717 | type = "video"; |
718 | break; | 718 | break; |
719 | case MAILIMAP_MEDIA_BASIC_OTHER: | 719 | case MAILIMAP_MEDIA_BASIC_OTHER: |
720 | default: | 720 | default: |
721 | if (which->bd_media_basic->med_basic_type) { | 721 | if (which->bd_media_basic->med_basic_type) { |
722 | type = which->bd_media_basic->med_basic_type; | 722 | type = which->bd_media_basic->med_basic_type; |
723 | } else { | 723 | } else { |
724 | type = ""; | 724 | type = ""; |
725 | } | 725 | } |
726 | break; | 726 | break; |
727 | } | 727 | } |
728 | if (which->bd_media_basic->med_subtype) { | 728 | if (which->bd_media_basic->med_subtype) { |
729 | sub = which->bd_media_basic->med_subtype; | 729 | sub = which->bd_media_basic->med_subtype; |
730 | } else { | 730 | } else { |
731 | sub = ""; | 731 | sub = ""; |
732 | } | 732 | } |
733 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 733 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
734 | target_part.setType(type.lower()); | 734 | target_part.setType(type.lower()); |
735 | target_part.setSubtype(sub.lower()); | 735 | target_part.setSubtype(sub.lower()); |
736 | fillBodyFields(target_part,which->bd_fields); | 736 | fillBodyFields(target_part,which->bd_fields); |
737 | } | 737 | } |
738 | 738 | ||
739 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 739 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
740 | { | 740 | { |
741 | if (!which) return; | 741 | if (!which) return; |
742 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 742 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
743 | clistcell*cur; | 743 | clistcell*cur; |
744 | mailimap_single_body_fld_param*param=0; | 744 | mailimap_single_body_fld_param*param=0; |
745 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 745 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
746 | param = (mailimap_single_body_fld_param*)cur->data; | 746 | param = (mailimap_single_body_fld_param*)cur->data; |
747 | if (param) { | 747 | if (param) { |
748 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 748 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
749 | } | 749 | } |
750 | } | 750 | } |
751 | } | 751 | } |
752 | mailimap_body_fld_enc*enc = which->bd_encoding; | 752 | mailimap_body_fld_enc*enc = which->bd_encoding; |
753 | QString encoding(""); | 753 | QString encoding(""); |
754 | switch (enc->enc_type) { | 754 | switch (enc->enc_type) { |
755 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 755 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
756 | encoding = "7bit"; | 756 | encoding = "7bit"; |
757 | break; | 757 | break; |
758 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 758 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
759 | encoding = "8bit"; | 759 | encoding = "8bit"; |
760 | break; | 760 | break; |
761 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 761 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
762 | encoding="binary"; | 762 | encoding="binary"; |
763 | break; | 763 | break; |
764 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 764 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
765 | encoding="base64"; | 765 | encoding="base64"; |
766 | break; | 766 | break; |
767 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 767 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
768 | encoding="quoted-printable"; | 768 | encoding="quoted-printable"; |
769 | break; | 769 | break; |
770 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 770 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
771 | default: | 771 | default: |
772 | if (enc->enc_value) { | 772 | if (enc->enc_value) { |
773 | char*t=enc->enc_value; | 773 | char*t=enc->enc_value; |
774 | encoding=QString(enc->enc_value); | 774 | encoding=QString(enc->enc_value); |
775 | enc->enc_value=0L; | 775 | enc->enc_value=0L; |
776 | free(t); | 776 | free(t); |
777 | } | 777 | } |
778 | } | 778 | } |
779 | if (which->bd_description) { | 779 | if (which->bd_description) { |
780 | target_part.setDescription(QString(which->bd_description)); | 780 | target_part.setDescription(QString(which->bd_description)); |
781 | } | 781 | } |
782 | target_part.setEncoding(encoding); | 782 | target_part.setEncoding(encoding); |
783 | target_part.setSize(which->bd_size); | 783 | target_part.setSize(which->bd_size); |
784 | } | 784 | } |
785 | 785 | ||
786 | void IMAPwrapper::deleteMail(const RecMail&mail) | 786 | void IMAPwrapper::deleteMail(const RecMail&mail) |
787 | { | 787 | { |
788 | mailimap_flag_list*flist; | 788 | mailimap_flag_list*flist; |
789 | mailimap_set *set; | 789 | mailimap_set *set; |
790 | mailimap_store_att_flags * store_flags; | 790 | mailimap_store_att_flags * store_flags; |
791 | int err; | 791 | int err; |
792 | login(); | 792 | login(); |
793 | if (!m_imap) { | 793 | if (!m_imap) { |
794 | return; | 794 | return; |
795 | } | 795 | } |
796 | err = selectMbox(mail.getMbox()); | 796 | err = selectMbox(mail.getMbox()); |
797 | if ( err != MAILIMAP_NO_ERROR ) { | 797 | if ( err != MAILIMAP_NO_ERROR ) { |
798 | return; | 798 | return; |
799 | } | 799 | } |
800 | flist = mailimap_flag_list_new_empty(); | 800 | flist = mailimap_flag_list_new_empty(); |
801 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 801 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
802 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 802 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
803 | set = mailimap_set_new_single(mail.getNumber()); | 803 | set = mailimap_set_new_single(mail.getNumber()); |
804 | err = mailimap_store(m_imap,set,store_flags); | 804 | err = mailimap_store(m_imap,set,store_flags); |
805 | mailimap_set_free( set ); | 805 | mailimap_set_free( set ); |
806 | mailimap_store_att_flags_free(store_flags); | 806 | mailimap_store_att_flags_free(store_flags); |
807 | 807 | ||
808 | if (err != MAILIMAP_NO_ERROR) { | 808 | if (err != MAILIMAP_NO_ERROR) { |
809 | qDebug("error deleting mail: %s",m_imap->imap_response); | 809 | qDebug("error deleting mail: %s",m_imap->imap_response); |
810 | return; | 810 | return; |
811 | } | 811 | } |
812 | qDebug("deleting mail: %s",m_imap->imap_response); | 812 | qDebug("deleting mail: %s",m_imap->imap_response); |
813 | /* should we realy do that at this moment? */ | 813 | /* should we realy do that at this moment? */ |
814 | err = mailimap_expunge(m_imap); | 814 | err = mailimap_expunge(m_imap); |
815 | if (err != MAILIMAP_NO_ERROR) { | 815 | if (err != MAILIMAP_NO_ERROR) { |
816 | qDebug("error deleting mail: %s",m_imap->imap_response); | 816 | qDebug("error deleting mail: %s",m_imap->imap_response); |
817 | } | 817 | } |
818 | qDebug("Delete successfull %s",m_imap->imap_response); | 818 | qDebug("Delete successfull %s",m_imap->imap_response); |
819 | } | 819 | } |
820 | 820 | ||
821 | void IMAPwrapper::answeredMail(const RecMail&mail) | 821 | void IMAPwrapper::answeredMail(const RecMail&mail) |
822 | { | 822 | { |
823 | mailimap_flag_list*flist; | 823 | mailimap_flag_list*flist; |
824 | mailimap_set *set; | 824 | mailimap_set *set; |
825 | mailimap_store_att_flags * store_flags; | 825 | mailimap_store_att_flags * store_flags; |
826 | int err; | 826 | int err; |
827 | login(); | 827 | login(); |
828 | if (!m_imap) { | 828 | if (!m_imap) { |
829 | return; | 829 | return; |
830 | } | 830 | } |
831 | err = selectMbox(mail.getMbox()); | 831 | err = selectMbox(mail.getMbox()); |
832 | if ( err != MAILIMAP_NO_ERROR ) { | 832 | if ( err != MAILIMAP_NO_ERROR ) { |
833 | return; | 833 | return; |
834 | } | 834 | } |
835 | flist = mailimap_flag_list_new_empty(); | 835 | flist = mailimap_flag_list_new_empty(); |
836 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 836 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
837 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 837 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
838 | set = mailimap_set_new_single(mail.getNumber()); | 838 | set = mailimap_set_new_single(mail.getNumber()); |
839 | err = mailimap_store(m_imap,set,store_flags); | 839 | err = mailimap_store(m_imap,set,store_flags); |
840 | mailimap_set_free( set ); | 840 | mailimap_set_free( set ); |
841 | mailimap_store_att_flags_free(store_flags); | 841 | mailimap_store_att_flags_free(store_flags); |
842 | 842 | ||
843 | if (err != MAILIMAP_NO_ERROR) { | 843 | if (err != MAILIMAP_NO_ERROR) { |
844 | qDebug("error marking mail: %s",m_imap->imap_response); | 844 | qDebug("error marking mail: %s",m_imap->imap_response); |
845 | return; | 845 | return; |
846 | } | 846 | } |
847 | } | 847 | } |
848 | 848 | ||
849 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 849 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
850 | { | 850 | { |
851 | QString body(""); | 851 | QString body(""); |
852 | encodedString*res = fetchRawPart(mail,path,internal_call); | 852 | encodedString*res = fetchRawPart(mail,path,internal_call); |
853 | encodedString*r = decode_String(res,enc); | 853 | encodedString*r = decode_String(res,enc); |
854 | delete res; | 854 | delete res; |
855 | if (r) { | 855 | if (r) { |
856 | if (r->Length()>0) { | 856 | if (r->Length()>0) { |
857 | body = r->Content(); | 857 | body = r->Content(); |
858 | } | 858 | } |
859 | delete r; | 859 | delete r; |
860 | } | 860 | } |
861 | return body; | 861 | return body; |
862 | } | 862 | } |
863 | 863 | ||
864 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 864 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
865 | { | 865 | { |
866 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 866 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
867 | } | 867 | } |
868 | 868 | ||
869 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 869 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
870 | { | 870 | { |
871 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 871 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
872 | encodedString*r = decode_String(res,part.Encoding()); | 872 | encodedString*r = decode_String(res,part.Encoding()); |
873 | delete res; | 873 | delete res; |
874 | return r; | 874 | return r; |
875 | } | 875 | } |
876 | 876 | ||
877 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 877 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
878 | { | 878 | { |
879 | return fetchRawPart(mail,part.Positionlist(),false); | 879 | return fetchRawPart(mail,part.Positionlist(),false); |
880 | } | 880 | } |
881 | 881 | ||
882 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 882 | int IMAPwrapper::deleteAllMail(const Folder*folder) |
883 | { | 883 | { |
884 | login(); | 884 | login(); |
885 | if (!m_imap) { | 885 | if (!m_imap) { |
886 | return 0; | 886 | return 0; |
887 | } | 887 | } |
888 | mailimap_flag_list*flist; | 888 | mailimap_flag_list*flist; |
889 | mailimap_set *set; | 889 | mailimap_set *set; |
890 | mailimap_store_att_flags * store_flags; | 890 | mailimap_store_att_flags * store_flags; |
891 | int err = selectMbox(folder->getName()); | 891 | int err = selectMbox(folder->getName()); |
892 | if ( err != MAILIMAP_NO_ERROR ) { | 892 | if ( err != MAILIMAP_NO_ERROR ) { |
893 | return 0; | 893 | return 0; |
894 | } | 894 | } |
895 | 895 | ||
896 | int last = m_imap->imap_selection_info->sel_exists; | 896 | int last = m_imap->imap_selection_info->sel_exists; |
897 | if (last == 0) { | 897 | if (last == 0) { |
898 | Global::statusMessage(tr("Mailbox has no mails!")); | 898 | Global::statusMessage(tr("Mailbox has no mails!")); |
899 | return 0; | 899 | return 0; |
900 | } | 900 | } |
901 | flist = mailimap_flag_list_new_empty(); | 901 | flist = mailimap_flag_list_new_empty(); |
902 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 902 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
903 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 903 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
904 | set = mailimap_set_new_interval( 1, last ); | 904 | set = mailimap_set_new_interval( 1, last ); |
905 | err = mailimap_store(m_imap,set,store_flags); | 905 | err = mailimap_store(m_imap,set,store_flags); |
906 | mailimap_set_free( set ); | 906 | mailimap_set_free( set ); |
907 | mailimap_store_att_flags_free(store_flags); | 907 | mailimap_store_att_flags_free(store_flags); |
908 | if (err != MAILIMAP_NO_ERROR) { | 908 | if (err != MAILIMAP_NO_ERROR) { |
909 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 909 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
910 | return 0; | 910 | return 0; |
911 | } | 911 | } |
912 | qDebug("deleting mail: %s",m_imap->imap_response); | 912 | qDebug("deleting mail: %s",m_imap->imap_response); |
913 | /* should we realy do that at this moment? */ | 913 | /* should we realy do that at this moment? */ |
914 | err = mailimap_expunge(m_imap); | 914 | err = mailimap_expunge(m_imap); |
915 | if (err != MAILIMAP_NO_ERROR) { | 915 | if (err != MAILIMAP_NO_ERROR) { |
916 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 916 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
917 | return 0; | 917 | return 0; |
918 | } | 918 | } |
919 | qDebug("Delete successfull %s",m_imap->imap_response); | 919 | qDebug("Delete successfull %s",m_imap->imap_response); |
920 | return 1; | 920 | return 1; |
921 | } | 921 | } |
922 | 922 | ||
923 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 923 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) |
924 | { | 924 | { |
925 | if (folder.length()==0) return 0; | 925 | if (folder.length()==0) return 0; |
926 | login(); | 926 | login(); |
927 | if (!m_imap) {return 0;} | 927 | if (!m_imap) {return 0;} |
928 | QString pre = account->getPrefix(); | 928 | QString pre = account->getPrefix(); |
929 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 929 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
930 | pre+=delemiter; | 930 | pre+=delemiter; |
931 | } | 931 | } |
932 | if (parentfolder) { | 932 | if (parentfolder) { |
933 | pre += parentfolder->getDisplayName()+delemiter; | 933 | pre += parentfolder->getDisplayName()+delemiter; |
934 | } | 934 | } |
935 | pre+=folder; | 935 | pre+=folder; |
936 | if (getsubfolder) { | 936 | if (getsubfolder) { |
937 | if (delemiter.length()>0) { | 937 | if (delemiter.length()>0) { |
938 | pre+=delemiter; | 938 | pre+=delemiter; |
939 | } else { | 939 | } else { |
940 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 940 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
941 | return 0; | 941 | return 0; |
942 | } | 942 | } |
943 | } | 943 | } |
944 | qDebug("Creating %s",pre.latin1()); | 944 | qDebug("Creating %s",pre.latin1()); |
945 | int res = mailimap_create(m_imap,pre.latin1()); | 945 | int res = mailimap_create(m_imap,pre.latin1()); |
946 | if (res != MAILIMAP_NO_ERROR) { | 946 | if (res != MAILIMAP_NO_ERROR) { |
947 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 947 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
948 | return 0; | 948 | return 0; |
949 | } | 949 | } |
950 | return 1; | 950 | return 1; |
951 | } | 951 | } |
952 | 952 | ||
953 | int IMAPwrapper::deleteMbox(const Folder*folder) | 953 | int IMAPwrapper::deleteMbox(const Folder*folder) |
954 | { | 954 | { |
955 | if (!folder) return 0; | 955 | if (!folder) return 0; |
956 | login(); | 956 | login(); |
957 | if (!m_imap) {return 0;} | 957 | if (!m_imap) {return 0;} |
958 | int res = mailimap_delete(m_imap,folder->getName()); | 958 | int res = mailimap_delete(m_imap,folder->getName()); |
959 | if (res != MAILIMAP_NO_ERROR) { | 959 | if (res != MAILIMAP_NO_ERROR) { |
960 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 960 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
961 | return 0; | 961 | return 0; |
962 | } | 962 | } |
963 | return 1; | 963 | return 1; |
964 | } | 964 | } |
965 | 965 | ||
966 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 966 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
967 | { | 967 | { |
968 | mailimap_status_att_list * att_list =0; | 968 | mailimap_status_att_list * att_list =0; |
969 | mailimap_mailbox_data_status * status=0; | 969 | mailimap_mailbox_data_status * status=0; |
970 | clistiter * cur = 0; | 970 | clistiter * cur = 0; |
971 | int r = 0; | 971 | int r = 0; |
972 | int res = 0; | 972 | int res = 0; |
973 | target_stat.message_count = 0; | 973 | target_stat.message_count = 0; |
974 | target_stat.message_unseen = 0; | 974 | target_stat.message_unseen = 0; |
975 | target_stat.message_recent = 0; | 975 | target_stat.message_recent = 0; |
976 | login(); | 976 | login(); |
977 | if (!m_imap) { | 977 | if (!m_imap) { |
978 | return; | 978 | return; |
979 | } | 979 | } |
980 | att_list = mailimap_status_att_list_new_empty(); | 980 | att_list = mailimap_status_att_list_new_empty(); |
981 | if (!att_list) return; | 981 | if (!att_list) return; |
982 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 982 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
983 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 983 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
984 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 984 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
985 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 985 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
986 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 986 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
987 | for (cur = clist_begin(status->st_info_list); | 987 | for (cur = clist_begin(status->st_info_list); |
988 | cur != NULL ; cur = clist_next(cur)) { | 988 | cur != NULL ; cur = clist_next(cur)) { |
989 | mailimap_status_info * status_info; | 989 | mailimap_status_info * status_info; |
990 | status_info = (mailimap_status_info *)clist_content(cur); | 990 | status_info = (mailimap_status_info *)clist_content(cur); |
991 | switch (status_info->st_att) { | 991 | switch (status_info->st_att) { |
992 | case MAILIMAP_STATUS_ATT_MESSAGES: | 992 | case MAILIMAP_STATUS_ATT_MESSAGES: |
993 | target_stat.message_count = status_info->st_value; | 993 | target_stat.message_count = status_info->st_value; |
994 | break; | 994 | break; |
995 | case MAILIMAP_STATUS_ATT_RECENT: | 995 | case MAILIMAP_STATUS_ATT_RECENT: |
996 | target_stat.message_recent = status_info->st_value; | 996 | target_stat.message_recent = status_info->st_value; |
997 | break; | 997 | break; |
998 | case MAILIMAP_STATUS_ATT_UNSEEN: | 998 | case MAILIMAP_STATUS_ATT_UNSEEN: |
999 | target_stat.message_unseen = status_info->st_value; | 999 | target_stat.message_unseen = status_info->st_value; |
1000 | break; | 1000 | break; |
1001 | } | 1001 | } |
1002 | } | 1002 | } |
1003 | } else { | 1003 | } else { |
1004 | qDebug("Error retrieving status"); | 1004 | qDebug("Error retrieving status"); |
1005 | } | 1005 | } |
1006 | if (status) mailimap_mailbox_data_status_free(status); | 1006 | if (status) mailimap_mailbox_data_status_free(status); |
1007 | if (att_list) mailimap_status_att_list_free(att_list); | 1007 | if (att_list) mailimap_status_att_list_free(att_list); |
1008 | } | 1008 | } |
1009 | 1009 | ||
1010 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1010 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1011 | { | 1011 | { |
1012 | login(); | 1012 | login(); |
1013 | if (!m_imap) return; | 1013 | if (!m_imap) return; |
1014 | if (!msg) return; | 1014 | if (!msg) return; |
1015 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1015 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1016 | if (r != MAILIMAP_NO_ERROR) { | 1016 | if (r != MAILIMAP_NO_ERROR) { |
1017 | Global::statusMessage("Error storing mail!"); | 1017 | Global::statusMessage("Error storing mail!"); |
1018 | } | 1018 | } |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | const QString&IMAPwrapper::getType()const | 1021 | const QString&IMAPwrapper::getType()const |
1022 | { | 1022 | { |
1023 | return account->getType(); | 1023 | return account->getType(); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | const QString&IMAPwrapper::getName()const | 1026 | const QString&IMAPwrapper::getName()const |
1027 | { | 1027 | { |
1028 | qDebug("Get name: %s",account->getAccountName().latin1()); | 1028 | qDebug("Get name: %s",account->getAccountName().latin1()); |
1029 | return account->getAccountName(); | 1029 | return account->getAccountName(); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) | 1032 | encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) |
1033 | { | 1033 | { |
1034 | // dummy | 1034 | // dummy |
1035 | QValueList<int> path; | 1035 | QValueList<int> path; |
1036 | return fetchRawPart(mail,path,false); | 1036 | return fetchRawPart(mail,path,false); |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1039 | void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1040 | { | 1040 | { |
1041 | if (targetWrapper != this) { | 1041 | if (targetWrapper != this) { |
1042 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1042 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
1043 | qDebug("Using generic"); | 1043 | qDebug("Using generic"); |
1044 | return; | 1044 | return; |
1045 | } | 1045 | } |
1046 | mailimap_set *set = 0; | 1046 | mailimap_set *set = 0; |
1047 | login(); | 1047 | login(); |
1048 | if (!m_imap) { | 1048 | if (!m_imap) { |
1049 | return; | 1049 | return; |
1050 | } | 1050 | } |
1051 | int err = selectMbox(fromFolder->getName()); | 1051 | int err = selectMbox(fromFolder->getName()); |
1052 | if ( err != MAILIMAP_NO_ERROR ) { | 1052 | if ( err != MAILIMAP_NO_ERROR ) { |
1053 | return; | 1053 | return; |
1054 | } | 1054 | } |
1055 | int last = m_imap->imap_selection_info->sel_exists; | 1055 | int last = m_imap->imap_selection_info->sel_exists; |
1056 | set = mailimap_set_new_interval( 1, last ); | 1056 | set = mailimap_set_new_interval( 1, last ); |
1057 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1057 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1058 | mailimap_set_free( set ); | 1058 | mailimap_set_free( set ); |
1059 | if ( err != MAILIMAP_NO_ERROR ) { | 1059 | if ( err != MAILIMAP_NO_ERROR ) { |
1060 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | 1060 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); |
1061 | Global::statusMessage(error_msg); | 1061 | Global::statusMessage(error_msg); |
1062 | qDebug(error_msg); | 1062 | qDebug(error_msg); |
1063 | return; | 1063 | return; |
1064 | } | 1064 | } |
1065 | if (moveit) { | 1065 | if (moveit) { |
1066 | deleteAllMail(fromFolder); | 1066 | deleteAllMail(fromFolder); |
1067 | } | 1067 | } |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1070 | void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1071 | { | 1071 | { |
1072 | if (targetWrapper != this) { | 1072 | if (targetWrapper != this) { |
1073 | qDebug("Using generic"); | 1073 | qDebug("Using generic"); |
1074 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1074 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1075 | return; | 1075 | return; |
1076 | } | 1076 | } |
1077 | mailimap_set *set = 0; | 1077 | mailimap_set *set = 0; |
1078 | login(); | 1078 | login(); |
1079 | if (!m_imap) { | 1079 | if (!m_imap) { |
1080 | return; | 1080 | return; |
1081 | } | 1081 | } |
1082 | int err = selectMbox(mail.getMbox()); | 1082 | int err = selectMbox(mail.getMbox()); |
1083 | if ( err != MAILIMAP_NO_ERROR ) { | 1083 | if ( err != MAILIMAP_NO_ERROR ) { |
1084 | return; | 1084 | return; |
1085 | } | 1085 | } |
1086 | set = mailimap_set_new_single(mail.getNumber()); | 1086 | set = mailimap_set_new_single(mail.getNumber()); |
1087 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1087 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1088 | mailimap_set_free( set ); | 1088 | mailimap_set_free( set ); |
1089 | if ( err != MAILIMAP_NO_ERROR ) { | 1089 | if ( err != MAILIMAP_NO_ERROR ) { |
1090 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1090 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1091 | Global::statusMessage(error_msg); | 1091 | Global::statusMessage(error_msg); |
1092 | qDebug(error_msg); | 1092 | qDebug(error_msg); |
1093 | return; | 1093 | return; |
1094 | } | 1094 | } |
1095 | if (moveit) { | 1095 | if (moveit) { |
1096 | deleteMail(mail); | 1096 | deleteMail(mail); |
1097 | } | 1097 | } |
1098 | } | 1098 | } |