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