-rw-r--r-- | noncore/net/mail/genericwrapper.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 33 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 33 |
10 files changed, 84 insertions, 46 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp index 447cad0..c1b6e48 100644 --- a/noncore/net/mail/genericwrapper.cpp +++ b/noncore/net/mail/genericwrapper.cpp | |||
@@ -98,195 +98,195 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | |||
98 | { | 98 | { |
99 | QString enc="7bit"; | 99 | QString enc="7bit"; |
100 | if (!aEnc) return enc; | 100 | if (!aEnc) return enc; |
101 | switch(aEnc->enc_type) { | 101 | switch(aEnc->enc_type) { |
102 | case MAILMIME_MECHANISM_7BIT: | 102 | case MAILMIME_MECHANISM_7BIT: |
103 | enc = "7bit"; | 103 | enc = "7bit"; |
104 | break; | 104 | break; |
105 | case MAILMIME_MECHANISM_8BIT: | 105 | case MAILMIME_MECHANISM_8BIT: |
106 | enc = "8bit"; | 106 | enc = "8bit"; |
107 | break; | 107 | break; |
108 | case MAILMIME_MECHANISM_BINARY: | 108 | case MAILMIME_MECHANISM_BINARY: |
109 | enc = "binary"; | 109 | enc = "binary"; |
110 | break; | 110 | break; |
111 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 111 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
112 | enc = "quoted-printable"; | 112 | enc = "quoted-printable"; |
113 | break; | 113 | break; |
114 | case MAILMIME_MECHANISM_BASE64: | 114 | case MAILMIME_MECHANISM_BASE64: |
115 | enc = "base64"; | 115 | enc = "base64"; |
116 | break; | 116 | break; |
117 | case MAILMIME_MECHANISM_TOKEN: | 117 | case MAILMIME_MECHANISM_TOKEN: |
118 | default: | 118 | default: |
119 | if (aEnc->enc_token) { | 119 | if (aEnc->enc_token) { |
120 | enc = QString(aEnc->enc_token); | 120 | enc = QString(aEnc->enc_token); |
121 | } | 121 | } |
122 | break; | 122 | break; |
123 | } | 123 | } |
124 | return enc; | 124 | return enc; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | 127 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) |
128 | { | 128 | { |
129 | if (current_rec >= 10) { | 129 | if (current_rec >= 10) { |
130 | qDebug("too deep recursion!"); | 130 | qDebug("too deep recursion!"); |
131 | } | 131 | } |
132 | if (!message || !mime) { | 132 | if (!message || !mime) { |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | int r; | 135 | int r; |
136 | char*data = 0; | 136 | char*data = 0; |
137 | size_t len; | 137 | size_t len; |
138 | clistiter * cur = 0; | 138 | clistiter * cur = 0; |
139 | QString b; | 139 | QString b; |
140 | RecPart part; | 140 | RecPart part; |
141 | 141 | ||
142 | switch (mime->mm_type) { | 142 | switch (mime->mm_type) { |
143 | case MAILMIME_SINGLE: | 143 | case MAILMIME_SINGLE: |
144 | r = mailmessage_fetch_section(message,mime,&data,&len); | 144 | r = mailmessage_fetch_section(message,mime,&data,&len); |
145 | part.setSize(len); | 145 | part.setSize(len); |
146 | fillSingleBody(part,message,mime); | 146 | fillSingleBody(part,message,mime); |
147 | if (part.Type()=="text" && target.Bodytext().isNull()) { | 147 | if (part.Type()=="text" && target.Bodytext().isNull()) { |
148 | encodedString*r = new encodedString(); | 148 | encodedString*r = new encodedString(); |
149 | r->setContent(data,len); | 149 | r->setContent(data,len); |
150 | encodedString*res = decode_String(r,part.Encoding()); | 150 | encodedString*res = decode_String(r,part.Encoding()); |
151 | b = QString(res->Content()); | 151 | b = QString(res->Content()); |
152 | delete r; | 152 | delete r; |
153 | delete res; | 153 | delete res; |
154 | target.setBodytext(b); | 154 | target.setBodytext(b); |
155 | target.setDescription(part); | 155 | target.setDescription(part); |
156 | } else { | 156 | } else { |
157 | b = gen_attachment_id(); | 157 | b = gen_attachment_id(); |
158 | part.setIdentifier(b); | 158 | part.setIdentifier(b); |
159 | bodyCache[b]=new encodedString(data,len); | 159 | bodyCache[b]=new encodedString(data,len); |
160 | target.addPart(part); | 160 | target.addPart(part); |
161 | } | 161 | } |
162 | break; | 162 | break; |
163 | case MAILMIME_MULTIPLE: | 163 | case MAILMIME_MULTIPLE: |
164 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 164 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
165 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | 165 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); |
166 | } | 166 | } |
167 | break; | 167 | break; |
168 | case MAILMIME_MESSAGE: | 168 | case MAILMIME_MESSAGE: |
169 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 169 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
170 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | 170 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); |
171 | } | 171 | } |
172 | break; | 172 | break; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | RecBody Genericwrapper::parseMail( mailmessage * msg ) | 176 | RecBody Genericwrapper::parseMail( mailmessage * msg ) |
177 | { | 177 | { |
178 | int err = MAILIMF_NO_ERROR; | 178 | int err = MAILIMF_NO_ERROR; |
179 | mailmime_single_fields fields; | 179 | mailmime_single_fields fields; |
180 | /* is bound to msg and will be freed there */ | 180 | /* is bound to msg and will be freed there */ |
181 | mailmime * mime=0; | 181 | mailmime * mime=0; |
182 | RecBody body; | 182 | RecBody body; |
183 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 183 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
184 | err = mailmessage_get_bodystructure(msg,&mime); | 184 | err = mailmessage_get_bodystructure(msg,&mime); |
185 | traverseBody(body,msg,mime); | 185 | traverseBody(body,msg,mime); |
186 | return body; | 186 | return body; |
187 | } | 187 | } |
188 | 188 | ||
189 | RecMail *Genericwrapper::parseHeader( const char *header ) | 189 | RecMail *Genericwrapper::parseHeader( const char *header ) |
190 | { | 190 | { |
191 | int err = MAILIMF_NO_ERROR; | 191 | int err = MAILIMF_NO_ERROR; |
192 | size_t curTok = 0; | 192 | size_t curTok = 0; |
193 | RecMail *mail = new RecMail(); | 193 | RecMail *mail = new RecMail(); |
194 | mailimf_fields *fields; | 194 | mailimf_fields *fields = 0; |
195 | mailimf_references * refs; | 195 | mailimf_references * refs = 0; |
196 | mailimf_keywords*keys; | 196 | mailimf_keywords*keys = 0; |
197 | QString status; | 197 | QString status; |
198 | QString value; | 198 | QString value; |
199 | QBitArray mFlags(7); | 199 | QBitArray mFlags(7); |
200 | 200 | ||
201 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 201 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
202 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 202 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
203 | mailimf_field *field = (mailimf_field *) current->data; | 203 | mailimf_field *field = (mailimf_field *) current->data; |
204 | switch ( field->fld_type ) { | 204 | switch ( field->fld_type ) { |
205 | case MAILIMF_FIELD_FROM: | 205 | case MAILIMF_FIELD_FROM: |
206 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 206 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
207 | break; | 207 | break; |
208 | case MAILIMF_FIELD_TO: | 208 | case MAILIMF_FIELD_TO: |
209 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 209 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
210 | break; | 210 | break; |
211 | case MAILIMF_FIELD_CC: | 211 | case MAILIMF_FIELD_CC: |
212 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 212 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
213 | break; | 213 | break; |
214 | case MAILIMF_FIELD_BCC: | 214 | case MAILIMF_FIELD_BCC: |
215 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 215 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
216 | break; | 216 | break; |
217 | case MAILIMF_FIELD_SUBJECT: | 217 | case MAILIMF_FIELD_SUBJECT: |
218 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | 218 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
219 | break; | 219 | break; |
220 | case MAILIMF_FIELD_ORIG_DATE: | 220 | case MAILIMF_FIELD_ORIG_DATE: |
221 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 221 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
222 | break; | 222 | break; |
223 | case MAILIMF_FIELD_MESSAGE_ID: | 223 | case MAILIMF_FIELD_MESSAGE_ID: |
224 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 224 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
225 | break; | 225 | break; |
226 | case MAILIMF_FIELD_REFERENCES: | 226 | case MAILIMF_FIELD_REFERENCES: |
227 | refs = field->fld_data.fld_references; | 227 | refs = field->fld_data.fld_references; |
228 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 228 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
229 | char * text = (char*)refs->mid_list->first->data; | 229 | char * text = (char*)refs->mid_list->first->data; |
230 | mail->setReplyto(QString(text)); | 230 | mail->setReplyto(QString(text)); |
231 | } | 231 | } |
232 | break; | 232 | break; |
233 | case MAILIMF_FIELD_KEYWORDS: | 233 | case MAILIMF_FIELD_KEYWORDS: |
234 | keys = field->fld_data.fld_keywords; | 234 | keys = field->fld_data.fld_keywords; |
235 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 235 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
236 | qDebug("Keyword: %s",(char*)cur->data); | 236 | qDebug("Keyword: %s",(char*)cur->data); |
237 | } | 237 | } |
238 | break; | 238 | break; |
239 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 239 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
240 | status = field->fld_data.fld_optional_field->fld_name; | 240 | status = field->fld_data.fld_optional_field->fld_name; |
241 | value = field->fld_data.fld_optional_field->fld_value; | 241 | value = field->fld_data.fld_optional_field->fld_value; |
242 | if (status.lower()=="status") { | 242 | if (status.lower()=="status") { |
243 | if (value.lower()=="ro") { | 243 | if (value.lower()=="ro") { |
244 | mFlags.setBit(FLAG_SEEN); | 244 | mFlags.setBit(FLAG_SEEN); |
245 | } | 245 | } |
246 | } else if (status.lower()=="x-status") { | 246 | } else if (status.lower()=="x-status") { |
247 | qDebug("X-Status: %s",value.latin1()); | 247 | qDebug("X-Status: %s",value.latin1()); |
248 | if (value.lower()=="a") { | 248 | if (value.lower()=="a") { |
249 | mFlags.setBit(FLAG_ANSWERED); | 249 | mFlags.setBit(FLAG_ANSWERED); |
250 | } | 250 | } |
251 | } else { | 251 | } else { |
252 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 252 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
253 | // field->fld_data.fld_optional_field->fld_value); | 253 | // field->fld_data.fld_optional_field->fld_value); |
254 | } | 254 | } |
255 | break; | 255 | break; |
256 | default: | 256 | default: |
257 | qDebug("Non parsed field"); | 257 | qDebug("Non parsed field"); |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | if (fields) mailimf_fields_free(fields); | 261 | if (fields) mailimf_fields_free(fields); |
262 | mail->setFlags(mFlags); | 262 | mail->setFlags(mFlags); |
263 | return mail; | 263 | return mail; |
264 | } | 264 | } |
265 | 265 | ||
266 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | 266 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) |
267 | { | 267 | { |
268 | char tmp[23]; | 268 | char tmp[23]; |
269 | 269 | ||
270 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 270 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
271 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 271 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
272 | 272 | ||
273 | return QString( tmp ); | 273 | return QString( tmp ); |
274 | } | 274 | } |
275 | 275 | ||
276 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 276 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
277 | { | 277 | { |
278 | QString result( "" ); | 278 | QString result( "" ); |
279 | 279 | ||
280 | bool first = true; | 280 | bool first = true; |
281 | if (list == 0) return result; | 281 | if (list == 0) return result; |
282 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 282 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
283 | mailimf_address *addr = (mailimf_address *) current->data; | 283 | mailimf_address *addr = (mailimf_address *) current->data; |
284 | 284 | ||
285 | if ( !first ) { | 285 | if ( !first ) { |
286 | result.append( "," ); | 286 | result.append( "," ); |
287 | } else { | 287 | } else { |
288 | first = false; | 288 | first = false; |
289 | } | 289 | } |
290 | 290 | ||
291 | switch ( addr->ad_type ) { | 291 | switch ( addr->ad_type ) { |
292 | case MAILIMF_ADDRESS_MAILBOX: | 292 | case MAILIMF_ADDRESS_MAILBOX: |
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 853e4a2..0178e33 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,253 +1,251 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | mailstream_flush(m_imap->imap_stream); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | server = account->getServer().latin1(); | 39 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 40 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 43 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 44 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 45 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 46 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 47 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 48 | } else { |
49 | // cancel | 49 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 50 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | } else { | 53 | } else { |
54 | user = account->getUser().latin1(); | 54 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 55 | pass = account->getPassword().latin1(); |
56 | } | 56 | } |
57 | 57 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 58 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 59 | /* connect */ |
60 | if (account->getSSL()) { | 60 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 62 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 64 | } |
65 | 65 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 66 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 69 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 70 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 71 | m_imap = 0; |
72 | return; | 72 | return; |
73 | } | 73 | } |
74 | 74 | ||
75 | /* login */ | 75 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 77 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 78 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 79 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 80 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 81 | m_imap = 0; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | void IMAPwrapper::logout() | 85 | void IMAPwrapper::logout() |
86 | { | 86 | { |
87 | int err = MAILIMAP_NO_ERROR; | 87 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 88 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 89 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 90 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 91 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 92 | m_imap = 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 96 | { |
97 | const char *mb; | 97 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 98 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result; | 99 | clist *result = 0; |
100 | clistcell *current; | 100 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType; | 102 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set; | 103 | mailimap_set *set = 0; |
104 | 104 | ||
105 | mb = mailbox.latin1(); | 105 | mb = mailbox.latin1(); |
106 | login(); | 106 | login(); |
107 | if (!m_imap) { | 107 | if (!m_imap) { |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | /* select mailbox READONLY for operations */ | 110 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 111 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 112 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 117 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 118 | ||
119 | if (last == 0) { | 119 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 120 | qDebug("mailbox has no mails"); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | 123 | ||
124 | result = clist_new(); | ||
125 | /* the range has to start at 1!!! not with 0!!!! */ | 124 | /* the range has to start at 1!!! not with 0!!!! */ |
126 | set = mailimap_set_new_interval( 1, last ); | 125 | set = mailimap_set_new_interval( 1, last ); |
127 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
131 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
132 | 131 | ||
133 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
134 | mailimap_set_free( set ); | 133 | mailimap_set_free( set ); |
135 | mailimap_fetch_type_free( fetchType ); | 134 | mailimap_fetch_type_free( fetchType ); |
136 | 135 | ||
137 | QString date,subject,from; | 136 | QString date,subject,from; |
138 | 137 | ||
139 | if ( err == MAILIMAP_NO_ERROR ) { | 138 | if ( err == MAILIMAP_NO_ERROR ) { |
140 | |||
141 | mailimap_msg_att * msg_att; | 139 | mailimap_msg_att * msg_att; |
142 | int i = 0; | 140 | int i = 0; |
143 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
144 | ++i; | 142 | ++i; |
145 | msg_att = (mailimap_msg_att*)current->data; | 143 | msg_att = (mailimap_msg_att*)current->data; |
146 | RecMail*m = parse_list_result(msg_att); | 144 | RecMail*m = parse_list_result(msg_att); |
147 | if (m) { | 145 | if (m) { |
148 | m->setNumber(i); | 146 | m->setNumber(i); |
149 | m->setMbox(mailbox); | 147 | m->setMbox(mailbox); |
150 | m->setWrapper(this); | 148 | m->setWrapper(this); |
151 | target.append(m); | 149 | target.append(m); |
152 | } | 150 | } |
153 | } | 151 | } |
154 | } else { | 152 | } else { |
155 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 153 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
156 | } | 154 | } |
157 | mailimap_fetch_list_free(result); | 155 | if (result) mailimap_fetch_list_free(result); |
158 | } | 156 | } |
159 | 157 | ||
160 | QList<Folder>* IMAPwrapper::listFolders() | 158 | QList<Folder>* IMAPwrapper::listFolders() |
161 | { | 159 | { |
162 | const char *path, *mask; | 160 | const char *path, *mask; |
163 | int err = MAILIMAP_NO_ERROR; | 161 | int err = MAILIMAP_NO_ERROR; |
164 | clist *result; | 162 | clist *result; |
165 | clistcell *current; | 163 | clistcell *current; |
166 | 164 | ||
167 | QList<Folder> * folders = new QList<Folder>(); | 165 | QList<Folder> * folders = new QList<Folder>(); |
168 | folders->setAutoDelete( false ); | 166 | folders->setAutoDelete( false ); |
169 | login(); | 167 | login(); |
170 | if (!m_imap) { | 168 | if (!m_imap) { |
171 | return folders; | 169 | return folders; |
172 | } | 170 | } |
173 | 171 | ||
174 | /* | 172 | /* |
175 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
176 | * We must not forget to filter them out in next loop! | 174 | * We must not forget to filter them out in next loop! |
177 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 175 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
178 | */ | 176 | */ |
179 | QString temp; | 177 | QString temp; |
180 | mask = "INBOX" ; | 178 | mask = "INBOX" ; |
181 | result = clist_new(); | 179 | result = clist_new(); |
182 | mailimap_mailbox_list *list; | 180 | mailimap_mailbox_list *list; |
183 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 181 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
184 | QString del; | 182 | QString del; |
185 | if ( err == MAILIMAP_NO_ERROR ) { | 183 | if ( err == MAILIMAP_NO_ERROR ) { |
186 | current = result->first; | 184 | current = result->first; |
187 | for ( int i = result->count; i > 0; i-- ) { | 185 | for ( int i = result->count; i > 0; i-- ) { |
188 | list = (mailimap_mailbox_list *) current->data; | 186 | list = (mailimap_mailbox_list *) current->data; |
189 | // it is better use the deep copy mechanism of qt itself | 187 | // it is better use the deep copy mechanism of qt itself |
190 | // instead of using strdup! | 188 | // instead of using strdup! |
191 | temp = list->mb_name; | 189 | temp = list->mb_name; |
192 | del = list->mb_delimiter; | 190 | del = list->mb_delimiter; |
193 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 191 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
194 | current = current->next; | 192 | current = current->next; |
195 | } | 193 | } |
196 | } else { | 194 | } else { |
197 | qDebug("error fetching folders: %s",m_imap->imap_response); | 195 | qDebug("error fetching folders: %s",m_imap->imap_response); |
198 | } | 196 | } |
199 | mailimap_list_result_free( result ); | 197 | mailimap_list_result_free( result ); |
200 | 198 | ||
201 | /* | 199 | /* |
202 | * second stage - get the other then inbox folders | 200 | * second stage - get the other then inbox folders |
203 | */ | 201 | */ |
204 | mask = "*" ; | 202 | mask = "*" ; |
205 | path = account->getPrefix().latin1(); | 203 | path = account->getPrefix().latin1(); |
206 | if (!path) path = ""; | 204 | if (!path) path = ""; |
207 | result = clist_new(); | 205 | result = clist_new(); |
208 | qDebug(path); | 206 | qDebug(path); |
209 | bool selectable = true; | 207 | bool selectable = true; |
210 | mailimap_mbx_list_flags*bflags; | 208 | mailimap_mbx_list_flags*bflags; |
211 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 209 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
212 | if ( err == MAILIMAP_NO_ERROR ) { | 210 | if ( err == MAILIMAP_NO_ERROR ) { |
213 | current = result->first; | 211 | current = result->first; |
214 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 212 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
215 | list = (mailimap_mailbox_list *) current->data; | 213 | list = (mailimap_mailbox_list *) current->data; |
216 | // it is better use the deep copy mechanism of qt itself | 214 | // it is better use the deep copy mechanism of qt itself |
217 | // instead of using strdup! | 215 | // instead of using strdup! |
218 | temp = list->mb_name; | 216 | temp = list->mb_name; |
219 | if (temp.lower()=="inbox") | 217 | if (temp.lower()=="inbox") |
220 | continue; | 218 | continue; |
221 | if (temp.lower()==account->getPrefix().lower()) | 219 | if (temp.lower()==account->getPrefix().lower()) |
222 | continue; | 220 | continue; |
223 | if ( (bflags = list->mb_flag) ) { | 221 | if ( (bflags = list->mb_flag) ) { |
224 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 222 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
225 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 223 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
226 | } | 224 | } |
227 | del = list->mb_delimiter; | 225 | del = list->mb_delimiter; |
228 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 226 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
229 | } | 227 | } |
230 | } else { | 228 | } else { |
231 | qDebug("error fetching folders %s",m_imap->imap_response); | 229 | qDebug("error fetching folders %s",m_imap->imap_response); |
232 | } | 230 | } |
233 | mailimap_list_result_free( result ); | 231 | mailimap_list_result_free( result ); |
234 | return folders; | 232 | return folders; |
235 | } | 233 | } |
236 | 234 | ||
237 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 235 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
238 | { | 236 | { |
239 | RecMail * m = 0; | 237 | RecMail * m = 0; |
240 | mailimap_msg_att_item *item=0; | 238 | mailimap_msg_att_item *item=0; |
241 | clistcell *current,*c,*cf; | 239 | clistcell *current,*c,*cf; |
242 | mailimap_msg_att_dynamic*flist; | 240 | mailimap_msg_att_dynamic*flist; |
243 | mailimap_flag_fetch*cflag; | 241 | mailimap_flag_fetch*cflag; |
244 | int size; | 242 | int size; |
245 | QBitArray mFlags(7); | 243 | QBitArray mFlags(7); |
246 | QStringList addresslist; | 244 | QStringList addresslist; |
247 | 245 | ||
248 | if (!m_att) { | 246 | if (!m_att) { |
249 | return m; | 247 | return m; |
250 | } | 248 | } |
251 | m = new RecMail(); | 249 | m = new RecMail(); |
252 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 250 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
253 | current = c; | 251 | current = c; |
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index 447cad0..c1b6e48 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp | |||
@@ -98,195 +98,195 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | |||
98 | { | 98 | { |
99 | QString enc="7bit"; | 99 | QString enc="7bit"; |
100 | if (!aEnc) return enc; | 100 | if (!aEnc) return enc; |
101 | switch(aEnc->enc_type) { | 101 | switch(aEnc->enc_type) { |
102 | case MAILMIME_MECHANISM_7BIT: | 102 | case MAILMIME_MECHANISM_7BIT: |
103 | enc = "7bit"; | 103 | enc = "7bit"; |
104 | break; | 104 | break; |
105 | case MAILMIME_MECHANISM_8BIT: | 105 | case MAILMIME_MECHANISM_8BIT: |
106 | enc = "8bit"; | 106 | enc = "8bit"; |
107 | break; | 107 | break; |
108 | case MAILMIME_MECHANISM_BINARY: | 108 | case MAILMIME_MECHANISM_BINARY: |
109 | enc = "binary"; | 109 | enc = "binary"; |
110 | break; | 110 | break; |
111 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 111 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
112 | enc = "quoted-printable"; | 112 | enc = "quoted-printable"; |
113 | break; | 113 | break; |
114 | case MAILMIME_MECHANISM_BASE64: | 114 | case MAILMIME_MECHANISM_BASE64: |
115 | enc = "base64"; | 115 | enc = "base64"; |
116 | break; | 116 | break; |
117 | case MAILMIME_MECHANISM_TOKEN: | 117 | case MAILMIME_MECHANISM_TOKEN: |
118 | default: | 118 | default: |
119 | if (aEnc->enc_token) { | 119 | if (aEnc->enc_token) { |
120 | enc = QString(aEnc->enc_token); | 120 | enc = QString(aEnc->enc_token); |
121 | } | 121 | } |
122 | break; | 122 | break; |
123 | } | 123 | } |
124 | return enc; | 124 | return enc; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | 127 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) |
128 | { | 128 | { |
129 | if (current_rec >= 10) { | 129 | if (current_rec >= 10) { |
130 | qDebug("too deep recursion!"); | 130 | qDebug("too deep recursion!"); |
131 | } | 131 | } |
132 | if (!message || !mime) { | 132 | if (!message || !mime) { |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | int r; | 135 | int r; |
136 | char*data = 0; | 136 | char*data = 0; |
137 | size_t len; | 137 | size_t len; |
138 | clistiter * cur = 0; | 138 | clistiter * cur = 0; |
139 | QString b; | 139 | QString b; |
140 | RecPart part; | 140 | RecPart part; |
141 | 141 | ||
142 | switch (mime->mm_type) { | 142 | switch (mime->mm_type) { |
143 | case MAILMIME_SINGLE: | 143 | case MAILMIME_SINGLE: |
144 | r = mailmessage_fetch_section(message,mime,&data,&len); | 144 | r = mailmessage_fetch_section(message,mime,&data,&len); |
145 | part.setSize(len); | 145 | part.setSize(len); |
146 | fillSingleBody(part,message,mime); | 146 | fillSingleBody(part,message,mime); |
147 | if (part.Type()=="text" && target.Bodytext().isNull()) { | 147 | if (part.Type()=="text" && target.Bodytext().isNull()) { |
148 | encodedString*r = new encodedString(); | 148 | encodedString*r = new encodedString(); |
149 | r->setContent(data,len); | 149 | r->setContent(data,len); |
150 | encodedString*res = decode_String(r,part.Encoding()); | 150 | encodedString*res = decode_String(r,part.Encoding()); |
151 | b = QString(res->Content()); | 151 | b = QString(res->Content()); |
152 | delete r; | 152 | delete r; |
153 | delete res; | 153 | delete res; |
154 | target.setBodytext(b); | 154 | target.setBodytext(b); |
155 | target.setDescription(part); | 155 | target.setDescription(part); |
156 | } else { | 156 | } else { |
157 | b = gen_attachment_id(); | 157 | b = gen_attachment_id(); |
158 | part.setIdentifier(b); | 158 | part.setIdentifier(b); |
159 | bodyCache[b]=new encodedString(data,len); | 159 | bodyCache[b]=new encodedString(data,len); |
160 | target.addPart(part); | 160 | target.addPart(part); |
161 | } | 161 | } |
162 | break; | 162 | break; |
163 | case MAILMIME_MULTIPLE: | 163 | case MAILMIME_MULTIPLE: |
164 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 164 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
165 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | 165 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); |
166 | } | 166 | } |
167 | break; | 167 | break; |
168 | case MAILMIME_MESSAGE: | 168 | case MAILMIME_MESSAGE: |
169 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 169 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
170 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | 170 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); |
171 | } | 171 | } |
172 | break; | 172 | break; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | RecBody Genericwrapper::parseMail( mailmessage * msg ) | 176 | RecBody Genericwrapper::parseMail( mailmessage * msg ) |
177 | { | 177 | { |
178 | int err = MAILIMF_NO_ERROR; | 178 | int err = MAILIMF_NO_ERROR; |
179 | mailmime_single_fields fields; | 179 | mailmime_single_fields fields; |
180 | /* is bound to msg and will be freed there */ | 180 | /* is bound to msg and will be freed there */ |
181 | mailmime * mime=0; | 181 | mailmime * mime=0; |
182 | RecBody body; | 182 | RecBody body; |
183 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 183 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
184 | err = mailmessage_get_bodystructure(msg,&mime); | 184 | err = mailmessage_get_bodystructure(msg,&mime); |
185 | traverseBody(body,msg,mime); | 185 | traverseBody(body,msg,mime); |
186 | return body; | 186 | return body; |
187 | } | 187 | } |
188 | 188 | ||
189 | RecMail *Genericwrapper::parseHeader( const char *header ) | 189 | RecMail *Genericwrapper::parseHeader( const char *header ) |
190 | { | 190 | { |
191 | int err = MAILIMF_NO_ERROR; | 191 | int err = MAILIMF_NO_ERROR; |
192 | size_t curTok = 0; | 192 | size_t curTok = 0; |
193 | RecMail *mail = new RecMail(); | 193 | RecMail *mail = new RecMail(); |
194 | mailimf_fields *fields; | 194 | mailimf_fields *fields = 0; |
195 | mailimf_references * refs; | 195 | mailimf_references * refs = 0; |
196 | mailimf_keywords*keys; | 196 | mailimf_keywords*keys = 0; |
197 | QString status; | 197 | QString status; |
198 | QString value; | 198 | QString value; |
199 | QBitArray mFlags(7); | 199 | QBitArray mFlags(7); |
200 | 200 | ||
201 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 201 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
202 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 202 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
203 | mailimf_field *field = (mailimf_field *) current->data; | 203 | mailimf_field *field = (mailimf_field *) current->data; |
204 | switch ( field->fld_type ) { | 204 | switch ( field->fld_type ) { |
205 | case MAILIMF_FIELD_FROM: | 205 | case MAILIMF_FIELD_FROM: |
206 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 206 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
207 | break; | 207 | break; |
208 | case MAILIMF_FIELD_TO: | 208 | case MAILIMF_FIELD_TO: |
209 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 209 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
210 | break; | 210 | break; |
211 | case MAILIMF_FIELD_CC: | 211 | case MAILIMF_FIELD_CC: |
212 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 212 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
213 | break; | 213 | break; |
214 | case MAILIMF_FIELD_BCC: | 214 | case MAILIMF_FIELD_BCC: |
215 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 215 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
216 | break; | 216 | break; |
217 | case MAILIMF_FIELD_SUBJECT: | 217 | case MAILIMF_FIELD_SUBJECT: |
218 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | 218 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
219 | break; | 219 | break; |
220 | case MAILIMF_FIELD_ORIG_DATE: | 220 | case MAILIMF_FIELD_ORIG_DATE: |
221 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 221 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
222 | break; | 222 | break; |
223 | case MAILIMF_FIELD_MESSAGE_ID: | 223 | case MAILIMF_FIELD_MESSAGE_ID: |
224 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 224 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
225 | break; | 225 | break; |
226 | case MAILIMF_FIELD_REFERENCES: | 226 | case MAILIMF_FIELD_REFERENCES: |
227 | refs = field->fld_data.fld_references; | 227 | refs = field->fld_data.fld_references; |
228 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 228 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
229 | char * text = (char*)refs->mid_list->first->data; | 229 | char * text = (char*)refs->mid_list->first->data; |
230 | mail->setReplyto(QString(text)); | 230 | mail->setReplyto(QString(text)); |
231 | } | 231 | } |
232 | break; | 232 | break; |
233 | case MAILIMF_FIELD_KEYWORDS: | 233 | case MAILIMF_FIELD_KEYWORDS: |
234 | keys = field->fld_data.fld_keywords; | 234 | keys = field->fld_data.fld_keywords; |
235 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 235 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
236 | qDebug("Keyword: %s",(char*)cur->data); | 236 | qDebug("Keyword: %s",(char*)cur->data); |
237 | } | 237 | } |
238 | break; | 238 | break; |
239 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 239 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
240 | status = field->fld_data.fld_optional_field->fld_name; | 240 | status = field->fld_data.fld_optional_field->fld_name; |
241 | value = field->fld_data.fld_optional_field->fld_value; | 241 | value = field->fld_data.fld_optional_field->fld_value; |
242 | if (status.lower()=="status") { | 242 | if (status.lower()=="status") { |
243 | if (value.lower()=="ro") { | 243 | if (value.lower()=="ro") { |
244 | mFlags.setBit(FLAG_SEEN); | 244 | mFlags.setBit(FLAG_SEEN); |
245 | } | 245 | } |
246 | } else if (status.lower()=="x-status") { | 246 | } else if (status.lower()=="x-status") { |
247 | qDebug("X-Status: %s",value.latin1()); | 247 | qDebug("X-Status: %s",value.latin1()); |
248 | if (value.lower()=="a") { | 248 | if (value.lower()=="a") { |
249 | mFlags.setBit(FLAG_ANSWERED); | 249 | mFlags.setBit(FLAG_ANSWERED); |
250 | } | 250 | } |
251 | } else { | 251 | } else { |
252 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 252 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
253 | // field->fld_data.fld_optional_field->fld_value); | 253 | // field->fld_data.fld_optional_field->fld_value); |
254 | } | 254 | } |
255 | break; | 255 | break; |
256 | default: | 256 | default: |
257 | qDebug("Non parsed field"); | 257 | qDebug("Non parsed field"); |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | if (fields) mailimf_fields_free(fields); | 261 | if (fields) mailimf_fields_free(fields); |
262 | mail->setFlags(mFlags); | 262 | mail->setFlags(mFlags); |
263 | return mail; | 263 | return mail; |
264 | } | 264 | } |
265 | 265 | ||
266 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | 266 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) |
267 | { | 267 | { |
268 | char tmp[23]; | 268 | char tmp[23]; |
269 | 269 | ||
270 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 270 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
271 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 271 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
272 | 272 | ||
273 | return QString( tmp ); | 273 | return QString( tmp ); |
274 | } | 274 | } |
275 | 275 | ||
276 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 276 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
277 | { | 277 | { |
278 | QString result( "" ); | 278 | QString result( "" ); |
279 | 279 | ||
280 | bool first = true; | 280 | bool first = true; |
281 | if (list == 0) return result; | 281 | if (list == 0) return result; |
282 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 282 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
283 | mailimf_address *addr = (mailimf_address *) current->data; | 283 | mailimf_address *addr = (mailimf_address *) current->data; |
284 | 284 | ||
285 | if ( !first ) { | 285 | if ( !first ) { |
286 | result.append( "," ); | 286 | result.append( "," ); |
287 | } else { | 287 | } else { |
288 | first = false; | 288 | first = false; |
289 | } | 289 | } |
290 | 290 | ||
291 | switch ( addr->ad_type ) { | 291 | switch ( addr->ad_type ) { |
292 | case MAILIMF_ADDRESS_MAILBOX: | 292 | case MAILIMF_ADDRESS_MAILBOX: |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 853e4a2..0178e33 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,253 +1,251 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | mailstream_flush(m_imap->imap_stream); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | server = account->getServer().latin1(); | 39 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 40 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 43 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 44 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 45 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 46 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 47 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 48 | } else { |
49 | // cancel | 49 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 50 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | } else { | 53 | } else { |
54 | user = account->getUser().latin1(); | 54 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 55 | pass = account->getPassword().latin1(); |
56 | } | 56 | } |
57 | 57 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 58 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 59 | /* connect */ |
60 | if (account->getSSL()) { | 60 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 62 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 64 | } |
65 | 65 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 66 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 69 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 70 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 71 | m_imap = 0; |
72 | return; | 72 | return; |
73 | } | 73 | } |
74 | 74 | ||
75 | /* login */ | 75 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 77 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 78 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 79 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 80 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 81 | m_imap = 0; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | void IMAPwrapper::logout() | 85 | void IMAPwrapper::logout() |
86 | { | 86 | { |
87 | int err = MAILIMAP_NO_ERROR; | 87 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 88 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 89 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 90 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 91 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 92 | m_imap = 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 96 | { |
97 | const char *mb; | 97 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 98 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result; | 99 | clist *result = 0; |
100 | clistcell *current; | 100 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType; | 102 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set; | 103 | mailimap_set *set = 0; |
104 | 104 | ||
105 | mb = mailbox.latin1(); | 105 | mb = mailbox.latin1(); |
106 | login(); | 106 | login(); |
107 | if (!m_imap) { | 107 | if (!m_imap) { |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | /* select mailbox READONLY for operations */ | 110 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 111 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 112 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 117 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 118 | ||
119 | if (last == 0) { | 119 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 120 | qDebug("mailbox has no mails"); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | 123 | ||
124 | result = clist_new(); | ||
125 | /* the range has to start at 1!!! not with 0!!!! */ | 124 | /* the range has to start at 1!!! not with 0!!!! */ |
126 | set = mailimap_set_new_interval( 1, last ); | 125 | set = mailimap_set_new_interval( 1, last ); |
127 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
131 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
132 | 131 | ||
133 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
134 | mailimap_set_free( set ); | 133 | mailimap_set_free( set ); |
135 | mailimap_fetch_type_free( fetchType ); | 134 | mailimap_fetch_type_free( fetchType ); |
136 | 135 | ||
137 | QString date,subject,from; | 136 | QString date,subject,from; |
138 | 137 | ||
139 | if ( err == MAILIMAP_NO_ERROR ) { | 138 | if ( err == MAILIMAP_NO_ERROR ) { |
140 | |||
141 | mailimap_msg_att * msg_att; | 139 | mailimap_msg_att * msg_att; |
142 | int i = 0; | 140 | int i = 0; |
143 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
144 | ++i; | 142 | ++i; |
145 | msg_att = (mailimap_msg_att*)current->data; | 143 | msg_att = (mailimap_msg_att*)current->data; |
146 | RecMail*m = parse_list_result(msg_att); | 144 | RecMail*m = parse_list_result(msg_att); |
147 | if (m) { | 145 | if (m) { |
148 | m->setNumber(i); | 146 | m->setNumber(i); |
149 | m->setMbox(mailbox); | 147 | m->setMbox(mailbox); |
150 | m->setWrapper(this); | 148 | m->setWrapper(this); |
151 | target.append(m); | 149 | target.append(m); |
152 | } | 150 | } |
153 | } | 151 | } |
154 | } else { | 152 | } else { |
155 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 153 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
156 | } | 154 | } |
157 | mailimap_fetch_list_free(result); | 155 | if (result) mailimap_fetch_list_free(result); |
158 | } | 156 | } |
159 | 157 | ||
160 | QList<Folder>* IMAPwrapper::listFolders() | 158 | QList<Folder>* IMAPwrapper::listFolders() |
161 | { | 159 | { |
162 | const char *path, *mask; | 160 | const char *path, *mask; |
163 | int err = MAILIMAP_NO_ERROR; | 161 | int err = MAILIMAP_NO_ERROR; |
164 | clist *result; | 162 | clist *result; |
165 | clistcell *current; | 163 | clistcell *current; |
166 | 164 | ||
167 | QList<Folder> * folders = new QList<Folder>(); | 165 | QList<Folder> * folders = new QList<Folder>(); |
168 | folders->setAutoDelete( false ); | 166 | folders->setAutoDelete( false ); |
169 | login(); | 167 | login(); |
170 | if (!m_imap) { | 168 | if (!m_imap) { |
171 | return folders; | 169 | return folders; |
172 | } | 170 | } |
173 | 171 | ||
174 | /* | 172 | /* |
175 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
176 | * We must not forget to filter them out in next loop! | 174 | * We must not forget to filter them out in next loop! |
177 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 175 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
178 | */ | 176 | */ |
179 | QString temp; | 177 | QString temp; |
180 | mask = "INBOX" ; | 178 | mask = "INBOX" ; |
181 | result = clist_new(); | 179 | result = clist_new(); |
182 | mailimap_mailbox_list *list; | 180 | mailimap_mailbox_list *list; |
183 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 181 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
184 | QString del; | 182 | QString del; |
185 | if ( err == MAILIMAP_NO_ERROR ) { | 183 | if ( err == MAILIMAP_NO_ERROR ) { |
186 | current = result->first; | 184 | current = result->first; |
187 | for ( int i = result->count; i > 0; i-- ) { | 185 | for ( int i = result->count; i > 0; i-- ) { |
188 | list = (mailimap_mailbox_list *) current->data; | 186 | list = (mailimap_mailbox_list *) current->data; |
189 | // it is better use the deep copy mechanism of qt itself | 187 | // it is better use the deep copy mechanism of qt itself |
190 | // instead of using strdup! | 188 | // instead of using strdup! |
191 | temp = list->mb_name; | 189 | temp = list->mb_name; |
192 | del = list->mb_delimiter; | 190 | del = list->mb_delimiter; |
193 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 191 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
194 | current = current->next; | 192 | current = current->next; |
195 | } | 193 | } |
196 | } else { | 194 | } else { |
197 | qDebug("error fetching folders: %s",m_imap->imap_response); | 195 | qDebug("error fetching folders: %s",m_imap->imap_response); |
198 | } | 196 | } |
199 | mailimap_list_result_free( result ); | 197 | mailimap_list_result_free( result ); |
200 | 198 | ||
201 | /* | 199 | /* |
202 | * second stage - get the other then inbox folders | 200 | * second stage - get the other then inbox folders |
203 | */ | 201 | */ |
204 | mask = "*" ; | 202 | mask = "*" ; |
205 | path = account->getPrefix().latin1(); | 203 | path = account->getPrefix().latin1(); |
206 | if (!path) path = ""; | 204 | if (!path) path = ""; |
207 | result = clist_new(); | 205 | result = clist_new(); |
208 | qDebug(path); | 206 | qDebug(path); |
209 | bool selectable = true; | 207 | bool selectable = true; |
210 | mailimap_mbx_list_flags*bflags; | 208 | mailimap_mbx_list_flags*bflags; |
211 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 209 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
212 | if ( err == MAILIMAP_NO_ERROR ) { | 210 | if ( err == MAILIMAP_NO_ERROR ) { |
213 | current = result->first; | 211 | current = result->first; |
214 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 212 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
215 | list = (mailimap_mailbox_list *) current->data; | 213 | list = (mailimap_mailbox_list *) current->data; |
216 | // it is better use the deep copy mechanism of qt itself | 214 | // it is better use the deep copy mechanism of qt itself |
217 | // instead of using strdup! | 215 | // instead of using strdup! |
218 | temp = list->mb_name; | 216 | temp = list->mb_name; |
219 | if (temp.lower()=="inbox") | 217 | if (temp.lower()=="inbox") |
220 | continue; | 218 | continue; |
221 | if (temp.lower()==account->getPrefix().lower()) | 219 | if (temp.lower()==account->getPrefix().lower()) |
222 | continue; | 220 | continue; |
223 | if ( (bflags = list->mb_flag) ) { | 221 | if ( (bflags = list->mb_flag) ) { |
224 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 222 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
225 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 223 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
226 | } | 224 | } |
227 | del = list->mb_delimiter; | 225 | del = list->mb_delimiter; |
228 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 226 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
229 | } | 227 | } |
230 | } else { | 228 | } else { |
231 | qDebug("error fetching folders %s",m_imap->imap_response); | 229 | qDebug("error fetching folders %s",m_imap->imap_response); |
232 | } | 230 | } |
233 | mailimap_list_result_free( result ); | 231 | mailimap_list_result_free( result ); |
234 | return folders; | 232 | return folders; |
235 | } | 233 | } |
236 | 234 | ||
237 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 235 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
238 | { | 236 | { |
239 | RecMail * m = 0; | 237 | RecMail * m = 0; |
240 | mailimap_msg_att_item *item=0; | 238 | mailimap_msg_att_item *item=0; |
241 | clistcell *current,*c,*cf; | 239 | clistcell *current,*c,*cf; |
242 | mailimap_msg_att_dynamic*flist; | 240 | mailimap_msg_att_dynamic*flist; |
243 | mailimap_flag_fetch*cflag; | 241 | mailimap_flag_fetch*cflag; |
244 | int size; | 242 | int size; |
245 | QBitArray mFlags(7); | 243 | QBitArray mFlags(7); |
246 | QStringList addresslist; | 244 | QStringList addresslist; |
247 | 245 | ||
248 | if (!m_att) { | 246 | if (!m_att) { |
249 | return m; | 247 | return m; |
250 | } | 248 | } |
251 | m = new RecMail(); | 249 | m = new RecMail(); |
252 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 250 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
253 | current = c; | 251 | current = c; |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index f8efd09..6479783 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,137 +1,137 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | #include "defines.h" | 11 | #include "defines.h" |
12 | 12 | ||
13 | Attachment::Attachment( DocLnk lnk ) | 13 | Attachment::Attachment( DocLnk lnk ) |
14 | { | 14 | { |
15 | doc = lnk; | 15 | doc = lnk; |
16 | size = QFileInfo( doc.file() ).size(); | 16 | size = QFileInfo( doc.file() ).size(); |
17 | } | 17 | } |
18 | 18 | ||
19 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 19 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
20 | { | 20 | { |
21 | name = tmp_name; | 21 | name = tmp_name; |
22 | nameDisplay = name; | 22 | nameDisplay = name; |
23 | separator = sep; | 23 | separator = sep; |
24 | } | 24 | } |
25 | 25 | ||
26 | const QString& Folder::Separator()const | 26 | const QString& Folder::Separator()const |
27 | { | 27 | { |
28 | return separator; | 28 | return separator; |
29 | } | 29 | } |
30 | 30 | ||
31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) | 31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) |
32 | : Folder( name,sep ),m_MaySelect(select) | 32 | : Folder( name,sep ),m_MaySelect(select) |
33 | { | 33 | { |
34 | // Decode IMAP foldername | 34 | // Decode IMAP foldername |
35 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 35 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
37 | 37 | ||
38 | if (prefix.length()>0) { | 38 | if (prefix.length()>0) { |
39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | static unsigned char base64chars[] = | 45 | static unsigned char base64chars[] = |
46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Decodes base64 encoded parts of the imapfolder name | 49 | * Decodes base64 encoded parts of the imapfolder name |
50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
51 | */ | 51 | */ |
52 | QString IMAPFolder::decodeFolderName( const QString &name ) | 52 | QString IMAPFolder::decodeFolderName( const QString &name ) |
53 | { | 53 | { |
54 | unsigned char c, i, bitcount; | 54 | unsigned char c, i, bitcount; |
55 | unsigned long ucs4, utf16, bitbuf; | 55 | unsigned long ucs4, utf16, bitbuf; |
56 | unsigned char base64[256], utf8[6]; | 56 | unsigned char base64[256], utf8[6]; |
57 | unsigned long srcPtr = 0; | 57 | unsigned long srcPtr = 0; |
58 | QCString dst; | 58 | QCString dst = ""; |
59 | QCString src = name.ascii(); | 59 | QCString src = name.ascii(); |
60 | 60 | ||
61 | /* initialize modified base64 decoding table */ | 61 | /* initialize modified base64 decoding table */ |
62 | memset(base64, UNDEFINED, sizeof(base64)); | 62 | memset(base64, UNDEFINED, sizeof(base64)); |
63 | for (i = 0; i < sizeof(base64chars); ++i) { | 63 | for (i = 0; i < sizeof(base64chars); ++i) { |
64 | base64[(int)base64chars[i]] = i; | 64 | base64[(int)base64chars[i]] = i; |
65 | } | 65 | } |
66 | 66 | ||
67 | /* loop until end of string */ | 67 | /* loop until end of string */ |
68 | while (srcPtr < src.length ()) { | 68 | while (srcPtr < src.length ()) { |
69 | c = src[srcPtr++]; | 69 | c = src[srcPtr++]; |
70 | /* deal with literal characters and &- */ | 70 | /* deal with literal characters and &- */ |
71 | if (c != '&' || src[srcPtr] == '-') { | 71 | if (c != '&' || src[srcPtr] == '-') { |
72 | /* encode literally */ | 72 | /* encode literally */ |
73 | dst += c; | 73 | dst += c; |
74 | /* skip over the '-' if this is an &- sequence */ | 74 | /* skip over the '-' if this is an &- sequence */ |
75 | if (c == '&') | 75 | if (c == '&') |
76 | srcPtr++; | 76 | srcPtr++; |
77 | } else { | 77 | } else { |
78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | 78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ |
79 | bitbuf = 0; | 79 | bitbuf = 0; |
80 | bitcount = 0; | 80 | bitcount = 0; |
81 | ucs4 = 0; | 81 | ucs4 = 0; |
82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | 82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { |
83 | ++srcPtr; | 83 | ++srcPtr; |
84 | bitbuf = (bitbuf << 6) | c; | 84 | bitbuf = (bitbuf << 6) | c; |
85 | bitcount += 6; | 85 | bitcount += 6; |
86 | /* enough bits for a UTF-16 character? */ | 86 | /* enough bits for a UTF-16 character? */ |
87 | if (bitcount >= 16) { | 87 | if (bitcount >= 16) { |
88 | bitcount -= 16; | 88 | bitcount -= 16; |
89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | 89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; |
90 | /* convert UTF16 to UCS4 */ | 90 | /* convert UTF16 to UCS4 */ |
91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | 91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { |
92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | 92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; |
93 | continue; | 93 | continue; |
94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
96 | } else { | 96 | } else { |
97 | ucs4 = utf16; | 97 | ucs4 = utf16; |
98 | } | 98 | } |
99 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 99 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
100 | if (ucs4 <= 0x7fUL) { | 100 | if (ucs4 <= 0x7fUL) { |
101 | utf8[0] = ucs4; | 101 | utf8[0] = ucs4; |
102 | i = 1; | 102 | i = 1; |
103 | } else if (ucs4 <= 0x7ffUL) { | 103 | } else if (ucs4 <= 0x7ffUL) { |
104 | utf8[0] = 0xc0 | (ucs4 >> 6); | 104 | utf8[0] = 0xc0 | (ucs4 >> 6); |
105 | utf8[1] = 0x80 | (ucs4 & 0x3f); | 105 | utf8[1] = 0x80 | (ucs4 & 0x3f); |
106 | i = 2; | 106 | i = 2; |
107 | } else if (ucs4 <= 0xffffUL) { | 107 | } else if (ucs4 <= 0xffffUL) { |
108 | utf8[0] = 0xe0 | (ucs4 >> 12); | 108 | utf8[0] = 0xe0 | (ucs4 >> 12); |
109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | 109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); |
110 | utf8[2] = 0x80 | (ucs4 & 0x3f); | 110 | utf8[2] = 0x80 | (ucs4 & 0x3f); |
111 | i = 3; | 111 | i = 3; |
112 | } else { | 112 | } else { |
113 | utf8[0] = 0xf0 | (ucs4 >> 18); | 113 | utf8[0] = 0xf0 | (ucs4 >> 18); |
114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | 114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); |
115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | 115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); |
116 | utf8[3] = 0x80 | (ucs4 & 0x3f); | 116 | utf8[3] = 0x80 | (ucs4 & 0x3f); |
117 | i = 4; | 117 | i = 4; |
118 | } | 118 | } |
119 | /* copy it */ | 119 | /* copy it */ |
120 | for (c = 0; c < i; ++c) { | 120 | for (c = 0; c < i; ++c) { |
121 | dst += utf8[c]; | 121 | dst += utf8[c]; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | /* skip over trailing '-' in modified UTF-7 encoding */ | 125 | /* skip over trailing '-' in modified UTF-7 encoding */ |
126 | if (src[srcPtr] == '-') | 126 | if (src[srcPtr] == '-') |
127 | ++srcPtr; | 127 | ++srcPtr; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | return QString::fromUtf8( dst.data() ); | 131 | return QString::fromUtf8( dst.data() ); |
132 | } | 132 | } |
133 | 133 | ||
134 | Mail::Mail() | 134 | Mail::Mail() |
135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
136 | { | 136 | { |
137 | } | 137 | } |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 293ae1b..6d69263 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,201 +1,209 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <libetpan/mailstorage.h> | 5 | #include <libetpan/mailstorage.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <stdlib.h> | ||
7 | 8 | ||
8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
9 | : Genericwrapper(),MBOXPath(mbox_dir) | 10 | : Genericwrapper(),MBOXPath(mbox_dir) |
10 | { | 11 | { |
11 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
12 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
13 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
14 | } | 15 | } |
15 | } | 16 | } |
16 | 17 | ||
17 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
18 | { | 19 | { |
19 | } | 20 | } |
20 | 21 | ||
21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
22 | { | 23 | { |
23 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
24 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
25 | p+=mailbox; | 26 | p+=mailbox; |
27 | char*fname = 0; | ||
26 | 28 | ||
27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 29 | fname = strdup(p.latin1()); |
30 | |||
31 | int r = mbox_mailstorage_init(storage,fname,0,0,0); | ||
28 | mailfolder*folder; | 32 | mailfolder*folder; |
29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 33 | folder = mailfolder_new( storage,fname,NULL); |
30 | r = mailfolder_connect(folder); | 34 | r = mailfolder_connect(folder); |
31 | if (r != MAIL_NO_ERROR) { | 35 | if (r != MAIL_NO_ERROR) { |
32 | qDebug("Error initializing mbox"); | 36 | qDebug("Error initializing mbox"); |
33 | mailfolder_free(folder); | 37 | mailfolder_free(folder); |
34 | mailstorage_free(storage); | 38 | mailstorage_free(storage); |
39 | free(fname); | ||
35 | return; | 40 | return; |
36 | } | 41 | } |
37 | mailmessage_list * env_list = 0; | 42 | mailmessage_list * env_list = 0; |
38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 43 | r = mailsession_get_messages_list(folder->fld_session,&env_list); |
39 | if (r != MAIL_NO_ERROR) { | 44 | if (r != MAIL_NO_ERROR) { |
40 | qDebug("Error message list"); | 45 | qDebug("Error message list"); |
41 | mailfolder_free(folder); | 46 | mailfolder_free(folder); |
42 | mailstorage_free(storage); | 47 | mailstorage_free(storage); |
48 | free(fname); | ||
43 | return; | 49 | return; |
44 | } | 50 | } |
45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | 51 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); |
46 | if (r != MAIL_NO_ERROR) { | 52 | if (r != MAIL_NO_ERROR) { |
47 | qDebug("Error filling message list"); | 53 | qDebug("Error filling message list"); |
48 | if (env_list) { | 54 | if (env_list) { |
49 | mailmessage_list_free(env_list); | 55 | mailmessage_list_free(env_list); |
50 | } | 56 | } |
51 | mailfolder_free(folder); | 57 | mailfolder_free(folder); |
52 | mailstorage_free(storage); | 58 | mailstorage_free(storage); |
59 | free(fname); | ||
53 | return; | 60 | return; |
54 | } | 61 | } |
55 | mailimf_references * refs; | 62 | mailimf_references * refs; |
56 | 63 | ||
57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | 64 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { |
58 | mailmessage * msg; | 65 | mailmessage * msg; |
59 | QBitArray mFlags(7); | 66 | QBitArray mFlags(7); |
60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 67 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
61 | if (msg->msg_fields == NULL) { | 68 | if (msg->msg_fields == NULL) { |
62 | qDebug("could not fetch envelope of message %i", i); | 69 | qDebug("could not fetch envelope of message %i", i); |
63 | continue; | 70 | continue; |
64 | } | 71 | } |
65 | RecMail * mail = new RecMail(); | 72 | RecMail * mail = new RecMail(); |
66 | mail->setWrapper(this); | 73 | mail->setWrapper(this); |
67 | mail_flags * flag_result = 0; | 74 | mail_flags * flag_result = 0; |
68 | r = mailmessage_get_flags(msg,&flag_result); | 75 | r = mailmessage_get_flags(msg,&flag_result); |
69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 76 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
70 | mFlags.setBit(FLAG_SEEN); | 77 | mFlags.setBit(FLAG_SEEN); |
71 | } | 78 | } |
72 | mailimf_single_fields single_fields; | 79 | mailimf_single_fields single_fields; |
73 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 80 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
74 | mail->setMsgsize(msg->msg_size); | 81 | mail->setMsgsize(msg->msg_size); |
75 | mail->setFlags(mFlags); | 82 | mail->setFlags(mFlags); |
76 | mail->setMbox(mailbox); | 83 | mail->setMbox(mailbox); |
77 | mail->setNumber(i+1); | 84 | mail->setNumber(i+1); |
78 | if (single_fields.fld_subject) | 85 | if (single_fields.fld_subject) |
79 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 86 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
80 | if (single_fields.fld_from) | 87 | if (single_fields.fld_from) |
81 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 88 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
82 | if (single_fields.fld_to) | 89 | if (single_fields.fld_to) |
83 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 90 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
84 | if (single_fields.fld_cc) | 91 | if (single_fields.fld_cc) |
85 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 92 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
86 | if (single_fields.fld_bcc) | 93 | if (single_fields.fld_bcc) |
87 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 94 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
88 | if (single_fields.fld_orig_date) | 95 | if (single_fields.fld_orig_date) |
89 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 96 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
90 | if (single_fields.fld_message_id->mid_value) | 97 | if (single_fields.fld_message_id->mid_value) |
91 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 98 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
92 | refs = single_fields.fld_references; | 99 | refs = single_fields.fld_references; |
93 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 100 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
94 | char * text = (char*)refs->mid_list->first->data; | 101 | char * text = (char*)refs->mid_list->first->data; |
95 | mail->setReplyto(QString(text)); | 102 | mail->setReplyto(QString(text)); |
96 | } | 103 | } |
97 | 104 | ||
98 | target.append(mail); | 105 | target.append(mail); |
99 | } | 106 | } |
100 | if (env_list) { | 107 | if (env_list) { |
101 | mailmessage_list_free(env_list); | 108 | mailmessage_list_free(env_list); |
102 | } | 109 | } |
103 | mailfolder_disconnect(folder); | 110 | mailfolder_disconnect(folder); |
104 | mailfolder_free(folder); | 111 | mailfolder_free(folder); |
105 | mailstorage_free(storage); | 112 | mailstorage_free(storage); |
113 | free(fname); | ||
106 | } | 114 | } |
107 | 115 | ||
108 | QList<Folder>* MBOXwrapper::listFolders() | 116 | QList<Folder>* MBOXwrapper::listFolders() |
109 | { | 117 | { |
110 | QList<Folder> * folders = new QList<Folder>(); | 118 | QList<Folder> * folders = new QList<Folder>(); |
111 | folders->setAutoDelete( false ); | 119 | folders->setAutoDelete( false ); |
112 | QDir dir(MBOXPath); | 120 | QDir dir(MBOXPath); |
113 | if (!dir.exists()) return folders; | 121 | if (!dir.exists()) return folders; |
114 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 122 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
115 | QStringList entries = dir.entryList(); | 123 | QStringList entries = dir.entryList(); |
116 | QStringList::ConstIterator it = entries.begin(); | 124 | QStringList::ConstIterator it = entries.begin(); |
117 | for (;it!=entries.end();++it) { | 125 | for (;it!=entries.end();++it) { |
118 | Folder*inb=new Folder(*it,"/"); | 126 | Folder*inb=new Folder(*it,"/"); |
119 | folders->append(inb); | 127 | folders->append(inb); |
120 | } | 128 | } |
121 | return folders; | 129 | return folders; |
122 | } | 130 | } |
123 | 131 | ||
124 | void MBOXwrapper::deleteMail(const RecMail&mail) | 132 | void MBOXwrapper::deleteMail(const RecMail&mail) |
125 | { | 133 | { |
126 | mailstorage*storage = mailstorage_new(NULL); | 134 | mailstorage*storage = mailstorage_new(NULL); |
127 | QString p = MBOXPath+"/"; | 135 | QString p = MBOXPath+"/"; |
128 | p+=mail.getMbox(); | 136 | p+=mail.getMbox(); |
129 | mailmessage * msg; | 137 | mailmessage * msg; |
130 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 138 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
131 | mailfolder*folder; | 139 | mailfolder*folder; |
132 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 140 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
133 | r = mailfolder_connect(folder); | 141 | r = mailfolder_connect(folder); |
134 | if (r != MAIL_NO_ERROR) { | 142 | if (r != MAIL_NO_ERROR) { |
135 | qDebug("Error initializing mbox"); | 143 | qDebug("Error initializing mbox"); |
136 | mailfolder_free(folder); | 144 | mailfolder_free(folder); |
137 | mailstorage_free(storage); | 145 | mailstorage_free(storage); |
138 | return; | 146 | return; |
139 | } | 147 | } |
140 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 148 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
141 | if (r != MAIL_NO_ERROR) { | 149 | if (r != MAIL_NO_ERROR) { |
142 | qDebug("error deleting mail"); | 150 | qDebug("error deleting mail"); |
143 | } | 151 | } |
144 | mailfolder_free(folder); | 152 | mailfolder_free(folder); |
145 | mailstorage_free(storage); | 153 | mailstorage_free(storage); |
146 | } | 154 | } |
147 | 155 | ||
148 | void MBOXwrapper::answeredMail(const RecMail&) | 156 | void MBOXwrapper::answeredMail(const RecMail&) |
149 | { | 157 | { |
150 | } | 158 | } |
151 | 159 | ||
152 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 160 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
153 | { | 161 | { |
154 | RecBody body; | 162 | RecBody body; |
155 | mailstorage*storage = mailstorage_new(NULL); | 163 | mailstorage*storage = mailstorage_new(NULL); |
156 | QString p = MBOXPath+"/"; | 164 | QString p = MBOXPath+"/"; |
157 | p+=mail.getMbox(); | 165 | p+=mail.getMbox(); |
158 | mailmessage * msg; | 166 | mailmessage * msg; |
159 | char*data=0; | 167 | char*data=0; |
160 | size_t size; | 168 | size_t size; |
161 | 169 | ||
162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 170 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
163 | mailfolder*folder; | 171 | mailfolder*folder; |
164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 172 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
165 | r = mailfolder_connect(folder); | 173 | r = mailfolder_connect(folder); |
166 | if (r != MAIL_NO_ERROR) { | 174 | if (r != MAIL_NO_ERROR) { |
167 | qDebug("Error initializing mbox"); | 175 | qDebug("Error initializing mbox"); |
168 | mailfolder_free(folder); | 176 | mailfolder_free(folder); |
169 | mailstorage_free(storage); | 177 | mailstorage_free(storage); |
170 | return body; | 178 | return body; |
171 | } | 179 | } |
172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 180 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
173 | if (r != MAIL_NO_ERROR) { | 181 | if (r != MAIL_NO_ERROR) { |
174 | qDebug("Error fetching mail %i",mail.getNumber()); | 182 | qDebug("Error fetching mail %i",mail.getNumber()); |
175 | mailfolder_free(folder); | 183 | mailfolder_free(folder); |
176 | mailstorage_free(storage); | 184 | mailstorage_free(storage); |
177 | return body; | 185 | return body; |
178 | } | 186 | } |
179 | r = mailmessage_fetch(msg,&data,&size); | 187 | r = mailmessage_fetch(msg,&data,&size); |
180 | if (r != MAIL_NO_ERROR) { | 188 | if (r != MAIL_NO_ERROR) { |
181 | qDebug("Error fetching mail %i",mail.getNumber()); | 189 | qDebug("Error fetching mail %i",mail.getNumber()); |
182 | mailfolder_free(folder); | 190 | mailfolder_free(folder); |
183 | mailstorage_free(storage); | 191 | mailstorage_free(storage); |
184 | mailmessage_free(msg); | 192 | mailmessage_free(msg); |
185 | return body; | 193 | return body; |
186 | } | 194 | } |
187 | body = parseMail(msg); | 195 | body = parseMail(msg); |
188 | mailmessage_fetch_result_free(msg,data); | 196 | mailmessage_fetch_result_free(msg,data); |
189 | mailfolder_free(folder); | 197 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 198 | mailstorage_free(storage); |
191 | 199 | ||
192 | return body; | 200 | return body; |
193 | } | 201 | } |
194 | 202 | ||
195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 203 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
196 | { | 204 | { |
197 | qDebug("MBOX %i von %i",current,maximum); | 205 | qDebug("MBOX %i von %i",current,maximum); |
198 | } | 206 | } |
199 | 207 | ||
200 | void MBOXwrapper::createFolder(const QString&) | 208 | void MBOXwrapper::createFolder(const QString&) |
201 | { | 209 | { |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index a7e4837..21992b4 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -348,397 +348,410 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
348 | err_free_txtPart: | 348 | err_free_txtPart: |
349 | mailmime_free( txtPart ); | 349 | mailmime_free( txtPart ); |
350 | err_free_message: | 350 | err_free_message: |
351 | mailmime_free( message ); | 351 | mailmime_free( message ); |
352 | err_free_fields: | 352 | err_free_fields: |
353 | mailimf_fields_free( fields ); | 353 | mailimf_fields_free( fields ); |
354 | err_free: | 354 | err_free: |
355 | qDebug( "createMimeMail: error" ); | 355 | qDebug( "createMimeMail: error" ); |
356 | 356 | ||
357 | return NULL; // Error :( | 357 | return NULL; // Error :( |
358 | } | 358 | } |
359 | 359 | ||
360 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 360 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
361 | { | 361 | { |
362 | mailimf_field *field; | 362 | mailimf_field *field; |
363 | clistiter *it; | 363 | clistiter *it; |
364 | 364 | ||
365 | it = clist_begin( fields->fld_list ); | 365 | it = clist_begin( fields->fld_list ); |
366 | while ( it ) { | 366 | while ( it ) { |
367 | field = (mailimf_field *) it->data; | 367 | field = (mailimf_field *) it->data; |
368 | if ( field->fld_type == type ) { | 368 | if ( field->fld_type == type ) { |
369 | return field; | 369 | return field; |
370 | } | 370 | } |
371 | it = it->next; | 371 | it = it->next; |
372 | } | 372 | } |
373 | 373 | ||
374 | return NULL; | 374 | return NULL; |
375 | } | 375 | } |
376 | 376 | ||
377 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 377 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
378 | { | 378 | { |
379 | clistiter *it, *it2; | 379 | clistiter *it, *it2; |
380 | 380 | ||
381 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 381 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
382 | mailimf_address *addr; | 382 | mailimf_address *addr; |
383 | addr = (mailimf_address *) it->data; | 383 | addr = (mailimf_address *) it->data; |
384 | 384 | ||
385 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 385 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
386 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 386 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
387 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 387 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
388 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 388 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
389 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 389 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
390 | mailimf_mailbox *mbox; | 390 | mailimf_mailbox *mbox; |
391 | mbox = (mailimf_mailbox *) it2->data; | 391 | mbox = (mailimf_mailbox *) it2->data; |
392 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 392 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 398 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
399 | { | 399 | { |
400 | clist *rcptList; | 400 | clist *rcptList; |
401 | mailimf_field *field; | 401 | mailimf_field *field; |
402 | 402 | ||
403 | rcptList = esmtp_address_list_new(); | 403 | rcptList = esmtp_address_list_new(); |
404 | 404 | ||
405 | field = getField( fields, MAILIMF_FIELD_TO ); | 405 | field = getField( fields, MAILIMF_FIELD_TO ); |
406 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 406 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
407 | && field->fld_data.fld_to->to_addr_list ) { | 407 | && field->fld_data.fld_to->to_addr_list ) { |
408 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 408 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
409 | } | 409 | } |
410 | 410 | ||
411 | field = getField( fields, MAILIMF_FIELD_CC ); | 411 | field = getField( fields, MAILIMF_FIELD_CC ); |
412 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 412 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
413 | && field->fld_data.fld_cc->cc_addr_list ) { | 413 | && field->fld_data.fld_cc->cc_addr_list ) { |
414 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 414 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
415 | } | 415 | } |
416 | 416 | ||
417 | field = getField( fields, MAILIMF_FIELD_BCC ); | 417 | field = getField( fields, MAILIMF_FIELD_BCC ); |
418 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 418 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
419 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 419 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
420 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 420 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
421 | } | 421 | } |
422 | 422 | ||
423 | return rcptList; | 423 | return rcptList; |
424 | } | 424 | } |
425 | 425 | ||
426 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) | 426 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
427 | { | 427 | { |
428 | char *from = NULL; | 428 | char *from = NULL; |
429 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 429 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
430 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 430 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
431 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 431 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
432 | clistiter *it; | 432 | clistiter *it; |
433 | for ( it = clist_begin( cl ); it; it = it->next ) { | 433 | for ( it = clist_begin( cl ); it; it = it->next ) { |
434 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 434 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
435 | from = strdup( mb->mb_addr_spec ); | 435 | from = strdup( mb->mb_addr_spec ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | 438 | ||
439 | return from; | 439 | return from; |
440 | } | 440 | } |
441 | 441 | ||
442 | char *SMTPwrapper::getFrom( mailmime *mail ) | 442 | char *SMTPwrapper::getFrom( mailmime *mail ) |
443 | { | 443 | { |
444 | /* no need to delete - its just a pointer to structure content */ | ||
444 | mailimf_field *ffrom = 0; | 445 | mailimf_field *ffrom = 0; |
446 | char*f = 0; | ||
445 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 447 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
446 | return getFrom(ffrom); | 448 | return getFrom(ffrom); |
447 | } | 449 | } |
448 | 450 | ||
449 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | 451 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) |
450 | { | 452 | { |
451 | SMTPaccount *smtp; | 453 | SMTPaccount *smtp; |
452 | 454 | ||
453 | QList<Account> list = settings->getAccounts(); | 455 | QList<Account> list = settings->getAccounts(); |
454 | Account *it; | 456 | Account *it; |
455 | for ( it = list.first(); it; it = list.next() ) { | 457 | for ( it = list.first(); it; it = list.next() ) { |
456 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 458 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
457 | smtp = static_cast<SMTPaccount *>(it); | 459 | smtp = static_cast<SMTPaccount *>(it); |
458 | if ( smtp->getName()== name ) { | 460 | if ( smtp->getName()== name ) { |
459 | qDebug( "SMTPaccount found for" ); | 461 | qDebug( "SMTPaccount found for" ); |
460 | qDebug( name ); | 462 | qDebug( name ); |
461 | return smtp; | 463 | return smtp; |
462 | } | 464 | } |
463 | } | 465 | } |
464 | } | 466 | } |
465 | 467 | ||
466 | return NULL; | 468 | return NULL; |
467 | } | 469 | } |
468 | 470 | ||
469 | QString SMTPwrapper::getTmpFile() { | 471 | QString SMTPwrapper::getTmpFile() { |
470 | int num = 0; | 472 | int num = 0; |
471 | QString unique; | 473 | QString unique; |
472 | 474 | ||
473 | QDir dir( "/tmp" ); | 475 | QDir dir( "/tmp" ); |
474 | 476 | ||
475 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 477 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
476 | 478 | ||
477 | do { | 479 | do { |
478 | unique.setNum( num++ ); | 480 | unique.setNum( num++ ); |
479 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 481 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
480 | 482 | ||
481 | return "/tmp/opiemail-tmp-" + unique; | 483 | return "/tmp/opiemail-tmp-" + unique; |
482 | } | 484 | } |
483 | 485 | ||
484 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 486 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
485 | { | 487 | { |
486 | FILE *f; | 488 | FILE *f; |
487 | int err, col = 0; | 489 | int err, col = 0; |
488 | 490 | ||
489 | f = fopen( file.latin1(), "w" ); | 491 | f = fopen( file.latin1(), "w" ); |
490 | if ( f == NULL ) { | 492 | if ( f == NULL ) { |
491 | qDebug( "writeToFile: error opening file" ); | 493 | qDebug( "writeToFile: error opening file" ); |
492 | return; | 494 | return; |
493 | } | 495 | } |
494 | 496 | ||
495 | err = mailmime_write( f, &col, mail ); | 497 | err = mailmime_write( f, &col, mail ); |
496 | if ( err != MAILIMF_NO_ERROR ) { | 498 | if ( err != MAILIMF_NO_ERROR ) { |
497 | fclose( f ); | 499 | fclose( f ); |
498 | qDebug( "writeToFile: error writing mailmime" ); | 500 | qDebug( "writeToFile: error writing mailmime" ); |
499 | return; | 501 | return; |
500 | } | 502 | } |
501 | 503 | ||
502 | fclose( f ); | 504 | fclose( f ); |
503 | } | 505 | } |
504 | 506 | ||
505 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 507 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
506 | { | 508 | { |
507 | 509 | ||
508 | QFile msg_cache(file); | 510 | QFile msg_cache(file); |
509 | QString msg = ""; | 511 | QString msg = ""; |
510 | msg_cache.open(IO_ReadOnly); | 512 | msg_cache.open(IO_ReadOnly); |
511 | char*message = new char[4096]; | 513 | char*message = new char[4096]; |
512 | memset(message,0,4096); | 514 | memset(message,0,4096); |
513 | while (msg_cache.readBlock(message,4095)>0) { | 515 | while (msg_cache.readBlock(message,4095)>0) { |
514 | msg+=message; | 516 | msg+=message; |
515 | memset(message,0,4096); | 517 | memset(message,0,4096); |
516 | } | 518 | } |
517 | delete message; | 519 | delete message; |
518 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | 520 | *data = (char*)malloc(msg.length()+1*sizeof(char)); |
519 | memset(*data,0,msg.length()+1); | 521 | memset(*data,0,msg.length()+1); |
520 | memcpy(*data,msg.ascii(),msg.length()); | 522 | memcpy(*data,msg.ascii(),msg.length()); |
521 | *size=msg.length(); | 523 | *size=msg.length(); |
522 | } | 524 | } |
523 | 525 | ||
524 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 526 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
525 | { | 527 | { |
526 | if (SMTPwrapper::sendProgress) { | 528 | if (SMTPwrapper::sendProgress) { |
527 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 529 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
528 | qApp->processEvents(); | 530 | qApp->processEvents(); |
529 | } | 531 | } |
530 | } | 532 | } |
531 | 533 | ||
532 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 534 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
533 | { | 535 | { |
534 | if (!mail) return; | 536 | if (!mail) return; |
535 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 537 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
536 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 538 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
537 | wrap->storeMessage(mail,length,box); | 539 | wrap->storeMessage(mail,length,box); |
538 | delete wrap; | 540 | delete wrap; |
539 | } | 541 | } |
540 | 542 | ||
541 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | 543 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
542 | { | 544 | { |
543 | clist *rcpts = 0; | 545 | clist *rcpts = 0; |
544 | char *from, *data; | 546 | char *from, *data; |
545 | size_t size; | 547 | size_t size; |
546 | 548 | ||
547 | if ( smtp == NULL ) { | 549 | if ( smtp == NULL ) { |
548 | return; | 550 | return; |
549 | } | 551 | } |
550 | from = data = 0; | 552 | from = data = 0; |
551 | 553 | ||
552 | QString file = getTmpFile(); | 554 | QString file = getTmpFile(); |
553 | writeToFile( file, mail ); | 555 | writeToFile( file, mail ); |
554 | readFromFile( file, &data, &size ); | 556 | readFromFile( file, &data, &size ); |
555 | QFile f( file ); | 557 | QFile f( file ); |
556 | f.remove(); | 558 | f.remove(); |
557 | 559 | ||
558 | if (later) { | 560 | if (later) { |
559 | storeMail(data,size,"Outgoing"); | 561 | storeMail(data,size,"Outgoing"); |
560 | if (data) free( data ); | 562 | if (data) free( data ); |
561 | return; | 563 | return; |
562 | } | 564 | } |
563 | from = getFrom( mail ); | 565 | from = getFrom( mail ); |
564 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 566 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
565 | smtpSend(from,rcpts,data,size,smtp); | 567 | smtpSend(from,rcpts,data,size,smtp); |
568 | if (data) {free(data);} | ||
569 | if (from) {free(from);} | ||
570 | if (rcpts) smtp_address_list_free( rcpts ); | ||
566 | } | 571 | } |
567 | 572 | ||
568 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | 573 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) |
569 | { | 574 | { |
570 | char *server, *user, *pass; | 575 | char *server, *user, *pass; |
571 | bool ssl; | 576 | bool ssl; |
572 | uint16_t port; | 577 | uint16_t port; |
573 | mailsmtp *session; | 578 | mailsmtp *session; |
574 | int err,result; | 579 | int err,result; |
575 | 580 | ||
576 | result = 1; | 581 | result = 1; |
577 | server = user = pass = 0; | 582 | server = user = pass = 0; |
578 | server = strdup( smtp->getServer().latin1() ); | 583 | server = strdup( smtp->getServer().latin1() ); |
579 | ssl = smtp->getSSL(); | 584 | ssl = smtp->getSSL(); |
580 | port = smtp->getPort().toUInt(); | 585 | port = smtp->getPort().toUInt(); |
581 | 586 | ||
582 | session = mailsmtp_new( 20, &progress ); | 587 | session = mailsmtp_new( 20, &progress ); |
583 | if ( session == NULL ) goto free_mem; | 588 | if ( session == NULL ) goto free_mem; |
584 | 589 | ||
585 | qDebug( "Servername %s at port %i", server, port ); | 590 | qDebug( "Servername %s at port %i", server, port ); |
586 | if ( ssl ) { | 591 | if ( ssl ) { |
587 | qDebug( "SSL session" ); | 592 | qDebug( "SSL session" ); |
588 | err = mailsmtp_ssl_connect( session, server, port ); | 593 | err = mailsmtp_ssl_connect( session, server, port ); |
589 | } else { | 594 | } else { |
590 | qDebug( "No SSL session" ); | 595 | qDebug( "No SSL session" ); |
591 | err = mailsmtp_socket_connect( session, server, port ); | 596 | err = mailsmtp_socket_connect( session, server, port ); |
592 | } | 597 | } |
593 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} | 598 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
594 | 599 | ||
595 | err = mailsmtp_init( session ); | 600 | err = mailsmtp_init( session ); |
596 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 601 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
597 | 602 | ||
598 | qDebug( "INIT OK" ); | 603 | qDebug( "INIT OK" ); |
599 | 604 | ||
600 | if ( smtp->getLogin() ) { | 605 | if ( smtp->getLogin() ) { |
601 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 606 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
602 | // get'em | 607 | // get'em |
603 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 608 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
604 | login.show(); | 609 | login.show(); |
605 | if ( QDialog::Accepted == login.exec() ) { | 610 | if ( QDialog::Accepted == login.exec() ) { |
606 | // ok | 611 | // ok |
607 | user = strdup( login.getUser().latin1() ); | 612 | user = strdup( login.getUser().latin1() ); |
608 | pass = strdup( login.getPassword().latin1() ); | 613 | pass = strdup( login.getPassword().latin1() ); |
609 | } else { | 614 | } else { |
610 | result = 0; goto free_con_session; | 615 | result = 0; goto free_con_session; |
611 | } | 616 | } |
612 | } else { | 617 | } else { |
613 | user = strdup( smtp->getUser().latin1() ); | 618 | user = strdup( smtp->getUser().latin1() ); |
614 | pass = strdup( smtp->getPassword().latin1() ); | 619 | pass = strdup( smtp->getPassword().latin1() ); |
615 | } | 620 | } |
616 | qDebug( "session->auth: %i", session->auth); | 621 | qDebug( "session->auth: %i", session->auth); |
617 | err = mailsmtp_auth( session, user, pass ); | 622 | err = mailsmtp_auth( session, user, pass ); |
618 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 623 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
619 | qDebug( "Done auth!" ); | 624 | qDebug( "Done auth!" ); |
620 | } | 625 | } |
621 | 626 | ||
622 | err = mailsmtp_send( session, from, rcpts, data, size ); | 627 | err = mailsmtp_send( session, from, rcpts, data, size ); |
623 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 628 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
624 | 629 | ||
625 | qDebug( "Mail sent." ); | 630 | qDebug( "Mail sent." ); |
626 | storeMail(data,size,"Sent"); | 631 | storeMail(data,size,"Sent"); |
627 | 632 | ||
628 | free_con_session: | 633 | free_con_session: |
629 | mailsmtp_quit( session ); | 634 | mailsmtp_quit( session ); |
630 | free_mem_session: | 635 | free_mem_session: |
631 | mailsmtp_free( session ); | 636 | mailsmtp_free( session ); |
632 | free_mem: | 637 | free_mem: |
633 | if (rcpts) smtp_address_list_free( rcpts ); | ||
634 | if (data) free( data ); | ||
635 | if (server) free( server ); | 638 | if (server) free( server ); |
636 | if (from) free( from ); | ||
637 | if ( smtp->getLogin() ) { | 639 | if ( smtp->getLogin() ) { |
638 | free( user ); | 640 | free( user ); |
639 | free( pass ); | 641 | free( pass ); |
640 | } | 642 | } |
641 | return result; | 643 | return result; |
642 | } | 644 | } |
643 | 645 | ||
644 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 646 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
645 | { | 647 | { |
646 | mailmime * mimeMail; | 648 | mailmime * mimeMail; |
647 | 649 | ||
648 | SMTPaccount *smtp = getAccount(mail.getName()); | 650 | SMTPaccount *smtp = getAccount(mail.getName()); |
649 | 651 | ||
650 | mimeMail = createMimeMail(mail ); | 652 | mimeMail = createMimeMail(mail ); |
651 | if ( mimeMail == NULL ) { | 653 | if ( mimeMail == NULL ) { |
652 | qDebug( "sendMail: error creating mime mail" ); | 654 | qDebug( "sendMail: error creating mime mail" ); |
653 | } else { | 655 | } else { |
654 | sendProgress = new progressMailSend(); | 656 | sendProgress = new progressMailSend(); |
655 | // sendProgress->showMaximized(); | ||
656 | sendProgress->show(); | 657 | sendProgress->show(); |
657 | sendProgress->setMaxMails(1); | 658 | sendProgress->setMaxMails(1); |
658 | smtpSend( mimeMail,later,smtp); | 659 | smtpSend( mimeMail,later,smtp); |
659 | mailmime_free( mimeMail ); | 660 | mailmime_free( mimeMail ); |
660 | qDebug("Clean up done"); | 661 | qDebug("Clean up done"); |
661 | sendProgress->hide(); | 662 | sendProgress->hide(); |
662 | delete sendProgress; | 663 | delete sendProgress; |
663 | sendProgress = 0; | 664 | sendProgress = 0; |
664 | } | 665 | } |
665 | } | 666 | } |
666 | 667 | ||
667 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | 668 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) |
668 | { | 669 | { |
669 | char*data = 0; | 670 | char*data = 0; |
670 | size_t length = 0; | 671 | size_t length = 0; |
671 | size_t curTok = 0; | 672 | size_t curTok = 0; |
672 | mailimf_fields *fields = 0; | 673 | mailimf_fields *fields = 0; |
673 | mailimf_field*ffrom = 0; | 674 | mailimf_field*ffrom = 0; |
674 | clist *rcpts = 0; | 675 | clist *rcpts = 0; |
675 | char*from = 0; | 676 | char*from = 0; |
677 | int res = 0; | ||
676 | 678 | ||
677 | wrap->fetchRawBody(*which,&data,&length); | 679 | wrap->fetchRawBody(*which,&data,&length); |
678 | if (!data) return 0; | 680 | if (!data) return 0; |
679 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | 681 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); |
680 | if (err != MAILIMF_NO_ERROR) { | 682 | if (err != MAILIMF_NO_ERROR) { |
681 | free(data); | 683 | free(data); |
682 | delete wrap; | 684 | delete wrap; |
683 | return 0; | 685 | return 0; |
684 | } | 686 | } |
685 | 687 | ||
686 | rcpts = createRcptList( fields ); | 688 | rcpts = createRcptList( fields ); |
687 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 689 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
688 | from = getFrom(ffrom); | 690 | from = getFrom(ffrom); |
689 | 691 | ||
690 | qDebug("Size: %i vs. %i",length,strlen(data)); | 692 | qDebug("Size: %i vs. %i",length,strlen(data)); |
691 | if (rcpts && from) { | 693 | if (rcpts && from) { |
692 | return smtpSend(from,rcpts,data,strlen(data),smtp ); | 694 | res = smtpSend(from,rcpts,data,length,smtp ); |
693 | } | 695 | } |
694 | return 0; | 696 | if (fields) { |
697 | mailimf_fields_free(fields); | ||
698 | fields = 0; | ||
699 | } | ||
700 | if (data) { | ||
701 | free(data); | ||
702 | } | ||
703 | if (from) { | ||
704 | free(from); | ||
705 | } | ||
706 | if (rcpts) { | ||
707 | smtp_address_list_free( rcpts ); | ||
708 | } | ||
709 | return res; | ||
695 | } | 710 | } |
696 | 711 | ||
697 | /* this is a special fun */ | 712 | /* this is a special fun */ |
698 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | 713 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) |
699 | { | 714 | { |
700 | bool returnValue = true; | 715 | bool returnValue = true; |
701 | 716 | ||
702 | if (!smtp) return false; | 717 | if (!smtp) return false; |
703 | 718 | ||
704 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 719 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
705 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 720 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
706 | if (!wrap) { | 721 | if (!wrap) { |
707 | qDebug("memory error"); | 722 | qDebug("memory error"); |
708 | return false; | 723 | return false; |
709 | } | 724 | } |
710 | QList<RecMail> mailsToSend; | 725 | QList<RecMail> mailsToSend; |
711 | QList<RecMail> mailsToRemove; | 726 | QList<RecMail> mailsToRemove; |
712 | QString mbox("Outgoing"); | 727 | QString mbox("Outgoing"); |
713 | wrap->listMessages(mbox,mailsToSend); | 728 | wrap->listMessages(mbox,mailsToSend); |
714 | if (mailsToSend.count()==0) { | 729 | if (mailsToSend.count()==0) { |
715 | delete wrap; | 730 | delete wrap; |
716 | return false; | 731 | return false; |
717 | } | 732 | } |
718 | mailsToSend.setAutoDelete(false); | 733 | mailsToSend.setAutoDelete(false); |
719 | sendProgress = new progressMailSend(); | 734 | sendProgress = new progressMailSend(); |
720 | // sendProgress->showMaximized(); | 735 | sendProgress->show(); |
721 | sendProgress->show(); | 736 | sendProgress->setMaxMails(mailsToSend.count()); |
722 | sendProgress->setMaxMails(mailsToSend.count()); | ||
723 | 737 | ||
724 | while (mailsToSend.count()>0) { | 738 | while (mailsToSend.count()>0) { |
725 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 739 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
726 | QMessageBox::critical(0,tr("Error sending mail"), | 740 | QMessageBox::critical(0,tr("Error sending mail"), |
727 | tr("Error sending queued mail - breaking")); | 741 | tr("Error sending queued mail - breaking")); |
728 | 742 | ||
729 | returnValue = false; | 743 | returnValue = false; |
730 | break; | 744 | break; |
731 | } | 745 | } |
732 | mailsToRemove.append(mailsToSend.at(0)); | 746 | mailsToRemove.append(mailsToSend.at(0)); |
733 | mailsToSend.removeFirst(); | 747 | mailsToSend.removeFirst(); |
734 | sendProgress->setCurrentMails(mailsToRemove.count()); | 748 | sendProgress->setCurrentMails(mailsToRemove.count()); |
735 | } | 749 | } |
736 | sendProgress->hide(); | 750 | sendProgress->hide(); |
737 | delete sendProgress; | 751 | delete sendProgress; |
738 | sendProgress = 0; | 752 | sendProgress = 0; |
739 | wrap->deleteMails(mbox,mailsToRemove); | 753 | wrap->deleteMails(mbox,mailsToRemove); |
740 | mailsToSend.setAutoDelete(true); | 754 | mailsToSend.setAutoDelete(true); |
741 | delete wrap; | 755 | delete wrap; |
742 | return returnValue; | 756 | return returnValue; |
743 | |||
744 | } | 757 | } |
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index f8efd09..6479783 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp | |||
@@ -1,137 +1,137 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | #include "defines.h" | 11 | #include "defines.h" |
12 | 12 | ||
13 | Attachment::Attachment( DocLnk lnk ) | 13 | Attachment::Attachment( DocLnk lnk ) |
14 | { | 14 | { |
15 | doc = lnk; | 15 | doc = lnk; |
16 | size = QFileInfo( doc.file() ).size(); | 16 | size = QFileInfo( doc.file() ).size(); |
17 | } | 17 | } |
18 | 18 | ||
19 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 19 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
20 | { | 20 | { |
21 | name = tmp_name; | 21 | name = tmp_name; |
22 | nameDisplay = name; | 22 | nameDisplay = name; |
23 | separator = sep; | 23 | separator = sep; |
24 | } | 24 | } |
25 | 25 | ||
26 | const QString& Folder::Separator()const | 26 | const QString& Folder::Separator()const |
27 | { | 27 | { |
28 | return separator; | 28 | return separator; |
29 | } | 29 | } |
30 | 30 | ||
31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) | 31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) |
32 | : Folder( name,sep ),m_MaySelect(select) | 32 | : Folder( name,sep ),m_MaySelect(select) |
33 | { | 33 | { |
34 | // Decode IMAP foldername | 34 | // Decode IMAP foldername |
35 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 35 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
37 | 37 | ||
38 | if (prefix.length()>0) { | 38 | if (prefix.length()>0) { |
39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | static unsigned char base64chars[] = | 45 | static unsigned char base64chars[] = |
46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Decodes base64 encoded parts of the imapfolder name | 49 | * Decodes base64 encoded parts of the imapfolder name |
50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
51 | */ | 51 | */ |
52 | QString IMAPFolder::decodeFolderName( const QString &name ) | 52 | QString IMAPFolder::decodeFolderName( const QString &name ) |
53 | { | 53 | { |
54 | unsigned char c, i, bitcount; | 54 | unsigned char c, i, bitcount; |
55 | unsigned long ucs4, utf16, bitbuf; | 55 | unsigned long ucs4, utf16, bitbuf; |
56 | unsigned char base64[256], utf8[6]; | 56 | unsigned char base64[256], utf8[6]; |
57 | unsigned long srcPtr = 0; | 57 | unsigned long srcPtr = 0; |
58 | QCString dst; | 58 | QCString dst = ""; |
59 | QCString src = name.ascii(); | 59 | QCString src = name.ascii(); |
60 | 60 | ||
61 | /* initialize modified base64 decoding table */ | 61 | /* initialize modified base64 decoding table */ |
62 | memset(base64, UNDEFINED, sizeof(base64)); | 62 | memset(base64, UNDEFINED, sizeof(base64)); |
63 | for (i = 0; i < sizeof(base64chars); ++i) { | 63 | for (i = 0; i < sizeof(base64chars); ++i) { |
64 | base64[(int)base64chars[i]] = i; | 64 | base64[(int)base64chars[i]] = i; |
65 | } | 65 | } |
66 | 66 | ||
67 | /* loop until end of string */ | 67 | /* loop until end of string */ |
68 | while (srcPtr < src.length ()) { | 68 | while (srcPtr < src.length ()) { |
69 | c = src[srcPtr++]; | 69 | c = src[srcPtr++]; |
70 | /* deal with literal characters and &- */ | 70 | /* deal with literal characters and &- */ |
71 | if (c != '&' || src[srcPtr] == '-') { | 71 | if (c != '&' || src[srcPtr] == '-') { |
72 | /* encode literally */ | 72 | /* encode literally */ |
73 | dst += c; | 73 | dst += c; |
74 | /* skip over the '-' if this is an &- sequence */ | 74 | /* skip over the '-' if this is an &- sequence */ |
75 | if (c == '&') | 75 | if (c == '&') |
76 | srcPtr++; | 76 | srcPtr++; |
77 | } else { | 77 | } else { |
78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | 78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ |
79 | bitbuf = 0; | 79 | bitbuf = 0; |
80 | bitcount = 0; | 80 | bitcount = 0; |
81 | ucs4 = 0; | 81 | ucs4 = 0; |
82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | 82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { |
83 | ++srcPtr; | 83 | ++srcPtr; |
84 | bitbuf = (bitbuf << 6) | c; | 84 | bitbuf = (bitbuf << 6) | c; |
85 | bitcount += 6; | 85 | bitcount += 6; |
86 | /* enough bits for a UTF-16 character? */ | 86 | /* enough bits for a UTF-16 character? */ |
87 | if (bitcount >= 16) { | 87 | if (bitcount >= 16) { |
88 | bitcount -= 16; | 88 | bitcount -= 16; |
89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | 89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; |
90 | /* convert UTF16 to UCS4 */ | 90 | /* convert UTF16 to UCS4 */ |
91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | 91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { |
92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | 92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; |
93 | continue; | 93 | continue; |
94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
96 | } else { | 96 | } else { |
97 | ucs4 = utf16; | 97 | ucs4 = utf16; |
98 | } | 98 | } |
99 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 99 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
100 | if (ucs4 <= 0x7fUL) { | 100 | if (ucs4 <= 0x7fUL) { |
101 | utf8[0] = ucs4; | 101 | utf8[0] = ucs4; |
102 | i = 1; | 102 | i = 1; |
103 | } else if (ucs4 <= 0x7ffUL) { | 103 | } else if (ucs4 <= 0x7ffUL) { |
104 | utf8[0] = 0xc0 | (ucs4 >> 6); | 104 | utf8[0] = 0xc0 | (ucs4 >> 6); |
105 | utf8[1] = 0x80 | (ucs4 & 0x3f); | 105 | utf8[1] = 0x80 | (ucs4 & 0x3f); |
106 | i = 2; | 106 | i = 2; |
107 | } else if (ucs4 <= 0xffffUL) { | 107 | } else if (ucs4 <= 0xffffUL) { |
108 | utf8[0] = 0xe0 | (ucs4 >> 12); | 108 | utf8[0] = 0xe0 | (ucs4 >> 12); |
109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | 109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); |
110 | utf8[2] = 0x80 | (ucs4 & 0x3f); | 110 | utf8[2] = 0x80 | (ucs4 & 0x3f); |
111 | i = 3; | 111 | i = 3; |
112 | } else { | 112 | } else { |
113 | utf8[0] = 0xf0 | (ucs4 >> 18); | 113 | utf8[0] = 0xf0 | (ucs4 >> 18); |
114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | 114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); |
115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | 115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); |
116 | utf8[3] = 0x80 | (ucs4 & 0x3f); | 116 | utf8[3] = 0x80 | (ucs4 & 0x3f); |
117 | i = 4; | 117 | i = 4; |
118 | } | 118 | } |
119 | /* copy it */ | 119 | /* copy it */ |
120 | for (c = 0; c < i; ++c) { | 120 | for (c = 0; c < i; ++c) { |
121 | dst += utf8[c]; | 121 | dst += utf8[c]; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | /* skip over trailing '-' in modified UTF-7 encoding */ | 125 | /* skip over trailing '-' in modified UTF-7 encoding */ |
126 | if (src[srcPtr] == '-') | 126 | if (src[srcPtr] == '-') |
127 | ++srcPtr; | 127 | ++srcPtr; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | return QString::fromUtf8( dst.data() ); | 131 | return QString::fromUtf8( dst.data() ); |
132 | } | 132 | } |
133 | 133 | ||
134 | Mail::Mail() | 134 | Mail::Mail() |
135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
136 | { | 136 | { |
137 | } | 137 | } |
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 293ae1b..6d69263 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -1,201 +1,209 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <libetpan/mailstorage.h> | 5 | #include <libetpan/mailstorage.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <stdlib.h> | ||
7 | 8 | ||
8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
9 | : Genericwrapper(),MBOXPath(mbox_dir) | 10 | : Genericwrapper(),MBOXPath(mbox_dir) |
10 | { | 11 | { |
11 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
12 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
13 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
14 | } | 15 | } |
15 | } | 16 | } |
16 | 17 | ||
17 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
18 | { | 19 | { |
19 | } | 20 | } |
20 | 21 | ||
21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
22 | { | 23 | { |
23 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
24 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
25 | p+=mailbox; | 26 | p+=mailbox; |
27 | char*fname = 0; | ||
26 | 28 | ||
27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 29 | fname = strdup(p.latin1()); |
30 | |||
31 | int r = mbox_mailstorage_init(storage,fname,0,0,0); | ||
28 | mailfolder*folder; | 32 | mailfolder*folder; |
29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 33 | folder = mailfolder_new( storage,fname,NULL); |
30 | r = mailfolder_connect(folder); | 34 | r = mailfolder_connect(folder); |
31 | if (r != MAIL_NO_ERROR) { | 35 | if (r != MAIL_NO_ERROR) { |
32 | qDebug("Error initializing mbox"); | 36 | qDebug("Error initializing mbox"); |
33 | mailfolder_free(folder); | 37 | mailfolder_free(folder); |
34 | mailstorage_free(storage); | 38 | mailstorage_free(storage); |
39 | free(fname); | ||
35 | return; | 40 | return; |
36 | } | 41 | } |
37 | mailmessage_list * env_list = 0; | 42 | mailmessage_list * env_list = 0; |
38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 43 | r = mailsession_get_messages_list(folder->fld_session,&env_list); |
39 | if (r != MAIL_NO_ERROR) { | 44 | if (r != MAIL_NO_ERROR) { |
40 | qDebug("Error message list"); | 45 | qDebug("Error message list"); |
41 | mailfolder_free(folder); | 46 | mailfolder_free(folder); |
42 | mailstorage_free(storage); | 47 | mailstorage_free(storage); |
48 | free(fname); | ||
43 | return; | 49 | return; |
44 | } | 50 | } |
45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | 51 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); |
46 | if (r != MAIL_NO_ERROR) { | 52 | if (r != MAIL_NO_ERROR) { |
47 | qDebug("Error filling message list"); | 53 | qDebug("Error filling message list"); |
48 | if (env_list) { | 54 | if (env_list) { |
49 | mailmessage_list_free(env_list); | 55 | mailmessage_list_free(env_list); |
50 | } | 56 | } |
51 | mailfolder_free(folder); | 57 | mailfolder_free(folder); |
52 | mailstorage_free(storage); | 58 | mailstorage_free(storage); |
59 | free(fname); | ||
53 | return; | 60 | return; |
54 | } | 61 | } |
55 | mailimf_references * refs; | 62 | mailimf_references * refs; |
56 | 63 | ||
57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | 64 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { |
58 | mailmessage * msg; | 65 | mailmessage * msg; |
59 | QBitArray mFlags(7); | 66 | QBitArray mFlags(7); |
60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 67 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
61 | if (msg->msg_fields == NULL) { | 68 | if (msg->msg_fields == NULL) { |
62 | qDebug("could not fetch envelope of message %i", i); | 69 | qDebug("could not fetch envelope of message %i", i); |
63 | continue; | 70 | continue; |
64 | } | 71 | } |
65 | RecMail * mail = new RecMail(); | 72 | RecMail * mail = new RecMail(); |
66 | mail->setWrapper(this); | 73 | mail->setWrapper(this); |
67 | mail_flags * flag_result = 0; | 74 | mail_flags * flag_result = 0; |
68 | r = mailmessage_get_flags(msg,&flag_result); | 75 | r = mailmessage_get_flags(msg,&flag_result); |
69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 76 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
70 | mFlags.setBit(FLAG_SEEN); | 77 | mFlags.setBit(FLAG_SEEN); |
71 | } | 78 | } |
72 | mailimf_single_fields single_fields; | 79 | mailimf_single_fields single_fields; |
73 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 80 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
74 | mail->setMsgsize(msg->msg_size); | 81 | mail->setMsgsize(msg->msg_size); |
75 | mail->setFlags(mFlags); | 82 | mail->setFlags(mFlags); |
76 | mail->setMbox(mailbox); | 83 | mail->setMbox(mailbox); |
77 | mail->setNumber(i+1); | 84 | mail->setNumber(i+1); |
78 | if (single_fields.fld_subject) | 85 | if (single_fields.fld_subject) |
79 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 86 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
80 | if (single_fields.fld_from) | 87 | if (single_fields.fld_from) |
81 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 88 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
82 | if (single_fields.fld_to) | 89 | if (single_fields.fld_to) |
83 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 90 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
84 | if (single_fields.fld_cc) | 91 | if (single_fields.fld_cc) |
85 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 92 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
86 | if (single_fields.fld_bcc) | 93 | if (single_fields.fld_bcc) |
87 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 94 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
88 | if (single_fields.fld_orig_date) | 95 | if (single_fields.fld_orig_date) |
89 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 96 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
90 | if (single_fields.fld_message_id->mid_value) | 97 | if (single_fields.fld_message_id->mid_value) |
91 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 98 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
92 | refs = single_fields.fld_references; | 99 | refs = single_fields.fld_references; |
93 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 100 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
94 | char * text = (char*)refs->mid_list->first->data; | 101 | char * text = (char*)refs->mid_list->first->data; |
95 | mail->setReplyto(QString(text)); | 102 | mail->setReplyto(QString(text)); |
96 | } | 103 | } |
97 | 104 | ||
98 | target.append(mail); | 105 | target.append(mail); |
99 | } | 106 | } |
100 | if (env_list) { | 107 | if (env_list) { |
101 | mailmessage_list_free(env_list); | 108 | mailmessage_list_free(env_list); |
102 | } | 109 | } |
103 | mailfolder_disconnect(folder); | 110 | mailfolder_disconnect(folder); |
104 | mailfolder_free(folder); | 111 | mailfolder_free(folder); |
105 | mailstorage_free(storage); | 112 | mailstorage_free(storage); |
113 | free(fname); | ||
106 | } | 114 | } |
107 | 115 | ||
108 | QList<Folder>* MBOXwrapper::listFolders() | 116 | QList<Folder>* MBOXwrapper::listFolders() |
109 | { | 117 | { |
110 | QList<Folder> * folders = new QList<Folder>(); | 118 | QList<Folder> * folders = new QList<Folder>(); |
111 | folders->setAutoDelete( false ); | 119 | folders->setAutoDelete( false ); |
112 | QDir dir(MBOXPath); | 120 | QDir dir(MBOXPath); |
113 | if (!dir.exists()) return folders; | 121 | if (!dir.exists()) return folders; |
114 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 122 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
115 | QStringList entries = dir.entryList(); | 123 | QStringList entries = dir.entryList(); |
116 | QStringList::ConstIterator it = entries.begin(); | 124 | QStringList::ConstIterator it = entries.begin(); |
117 | for (;it!=entries.end();++it) { | 125 | for (;it!=entries.end();++it) { |
118 | Folder*inb=new Folder(*it,"/"); | 126 | Folder*inb=new Folder(*it,"/"); |
119 | folders->append(inb); | 127 | folders->append(inb); |
120 | } | 128 | } |
121 | return folders; | 129 | return folders; |
122 | } | 130 | } |
123 | 131 | ||
124 | void MBOXwrapper::deleteMail(const RecMail&mail) | 132 | void MBOXwrapper::deleteMail(const RecMail&mail) |
125 | { | 133 | { |
126 | mailstorage*storage = mailstorage_new(NULL); | 134 | mailstorage*storage = mailstorage_new(NULL); |
127 | QString p = MBOXPath+"/"; | 135 | QString p = MBOXPath+"/"; |
128 | p+=mail.getMbox(); | 136 | p+=mail.getMbox(); |
129 | mailmessage * msg; | 137 | mailmessage * msg; |
130 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 138 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
131 | mailfolder*folder; | 139 | mailfolder*folder; |
132 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 140 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
133 | r = mailfolder_connect(folder); | 141 | r = mailfolder_connect(folder); |
134 | if (r != MAIL_NO_ERROR) { | 142 | if (r != MAIL_NO_ERROR) { |
135 | qDebug("Error initializing mbox"); | 143 | qDebug("Error initializing mbox"); |
136 | mailfolder_free(folder); | 144 | mailfolder_free(folder); |
137 | mailstorage_free(storage); | 145 | mailstorage_free(storage); |
138 | return; | 146 | return; |
139 | } | 147 | } |
140 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 148 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
141 | if (r != MAIL_NO_ERROR) { | 149 | if (r != MAIL_NO_ERROR) { |
142 | qDebug("error deleting mail"); | 150 | qDebug("error deleting mail"); |
143 | } | 151 | } |
144 | mailfolder_free(folder); | 152 | mailfolder_free(folder); |
145 | mailstorage_free(storage); | 153 | mailstorage_free(storage); |
146 | } | 154 | } |
147 | 155 | ||
148 | void MBOXwrapper::answeredMail(const RecMail&) | 156 | void MBOXwrapper::answeredMail(const RecMail&) |
149 | { | 157 | { |
150 | } | 158 | } |
151 | 159 | ||
152 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 160 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
153 | { | 161 | { |
154 | RecBody body; | 162 | RecBody body; |
155 | mailstorage*storage = mailstorage_new(NULL); | 163 | mailstorage*storage = mailstorage_new(NULL); |
156 | QString p = MBOXPath+"/"; | 164 | QString p = MBOXPath+"/"; |
157 | p+=mail.getMbox(); | 165 | p+=mail.getMbox(); |
158 | mailmessage * msg; | 166 | mailmessage * msg; |
159 | char*data=0; | 167 | char*data=0; |
160 | size_t size; | 168 | size_t size; |
161 | 169 | ||
162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 170 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
163 | mailfolder*folder; | 171 | mailfolder*folder; |
164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 172 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
165 | r = mailfolder_connect(folder); | 173 | r = mailfolder_connect(folder); |
166 | if (r != MAIL_NO_ERROR) { | 174 | if (r != MAIL_NO_ERROR) { |
167 | qDebug("Error initializing mbox"); | 175 | qDebug("Error initializing mbox"); |
168 | mailfolder_free(folder); | 176 | mailfolder_free(folder); |
169 | mailstorage_free(storage); | 177 | mailstorage_free(storage); |
170 | return body; | 178 | return body; |
171 | } | 179 | } |
172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 180 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
173 | if (r != MAIL_NO_ERROR) { | 181 | if (r != MAIL_NO_ERROR) { |
174 | qDebug("Error fetching mail %i",mail.getNumber()); | 182 | qDebug("Error fetching mail %i",mail.getNumber()); |
175 | mailfolder_free(folder); | 183 | mailfolder_free(folder); |
176 | mailstorage_free(storage); | 184 | mailstorage_free(storage); |
177 | return body; | 185 | return body; |
178 | } | 186 | } |
179 | r = mailmessage_fetch(msg,&data,&size); | 187 | r = mailmessage_fetch(msg,&data,&size); |
180 | if (r != MAIL_NO_ERROR) { | 188 | if (r != MAIL_NO_ERROR) { |
181 | qDebug("Error fetching mail %i",mail.getNumber()); | 189 | qDebug("Error fetching mail %i",mail.getNumber()); |
182 | mailfolder_free(folder); | 190 | mailfolder_free(folder); |
183 | mailstorage_free(storage); | 191 | mailstorage_free(storage); |
184 | mailmessage_free(msg); | 192 | mailmessage_free(msg); |
185 | return body; | 193 | return body; |
186 | } | 194 | } |
187 | body = parseMail(msg); | 195 | body = parseMail(msg); |
188 | mailmessage_fetch_result_free(msg,data); | 196 | mailmessage_fetch_result_free(msg,data); |
189 | mailfolder_free(folder); | 197 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 198 | mailstorage_free(storage); |
191 | 199 | ||
192 | return body; | 200 | return body; |
193 | } | 201 | } |
194 | 202 | ||
195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 203 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
196 | { | 204 | { |
197 | qDebug("MBOX %i von %i",current,maximum); | 205 | qDebug("MBOX %i von %i",current,maximum); |
198 | } | 206 | } |
199 | 207 | ||
200 | void MBOXwrapper::createFolder(const QString&) | 208 | void MBOXwrapper::createFolder(const QString&) |
201 | { | 209 | { |
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index a7e4837..21992b4 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp | |||
@@ -348,397 +348,410 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
348 | err_free_txtPart: | 348 | err_free_txtPart: |
349 | mailmime_free( txtPart ); | 349 | mailmime_free( txtPart ); |
350 | err_free_message: | 350 | err_free_message: |
351 | mailmime_free( message ); | 351 | mailmime_free( message ); |
352 | err_free_fields: | 352 | err_free_fields: |
353 | mailimf_fields_free( fields ); | 353 | mailimf_fields_free( fields ); |
354 | err_free: | 354 | err_free: |
355 | qDebug( "createMimeMail: error" ); | 355 | qDebug( "createMimeMail: error" ); |
356 | 356 | ||
357 | return NULL; // Error :( | 357 | return NULL; // Error :( |
358 | } | 358 | } |
359 | 359 | ||
360 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 360 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
361 | { | 361 | { |
362 | mailimf_field *field; | 362 | mailimf_field *field; |
363 | clistiter *it; | 363 | clistiter *it; |
364 | 364 | ||
365 | it = clist_begin( fields->fld_list ); | 365 | it = clist_begin( fields->fld_list ); |
366 | while ( it ) { | 366 | while ( it ) { |
367 | field = (mailimf_field *) it->data; | 367 | field = (mailimf_field *) it->data; |
368 | if ( field->fld_type == type ) { | 368 | if ( field->fld_type == type ) { |
369 | return field; | 369 | return field; |
370 | } | 370 | } |
371 | it = it->next; | 371 | it = it->next; |
372 | } | 372 | } |
373 | 373 | ||
374 | return NULL; | 374 | return NULL; |
375 | } | 375 | } |
376 | 376 | ||
377 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 377 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
378 | { | 378 | { |
379 | clistiter *it, *it2; | 379 | clistiter *it, *it2; |
380 | 380 | ||
381 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 381 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
382 | mailimf_address *addr; | 382 | mailimf_address *addr; |
383 | addr = (mailimf_address *) it->data; | 383 | addr = (mailimf_address *) it->data; |
384 | 384 | ||
385 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 385 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
386 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 386 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
387 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 387 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
388 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 388 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
389 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 389 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
390 | mailimf_mailbox *mbox; | 390 | mailimf_mailbox *mbox; |
391 | mbox = (mailimf_mailbox *) it2->data; | 391 | mbox = (mailimf_mailbox *) it2->data; |
392 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 392 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 398 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
399 | { | 399 | { |
400 | clist *rcptList; | 400 | clist *rcptList; |
401 | mailimf_field *field; | 401 | mailimf_field *field; |
402 | 402 | ||
403 | rcptList = esmtp_address_list_new(); | 403 | rcptList = esmtp_address_list_new(); |
404 | 404 | ||
405 | field = getField( fields, MAILIMF_FIELD_TO ); | 405 | field = getField( fields, MAILIMF_FIELD_TO ); |
406 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 406 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
407 | && field->fld_data.fld_to->to_addr_list ) { | 407 | && field->fld_data.fld_to->to_addr_list ) { |
408 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 408 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
409 | } | 409 | } |
410 | 410 | ||
411 | field = getField( fields, MAILIMF_FIELD_CC ); | 411 | field = getField( fields, MAILIMF_FIELD_CC ); |
412 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 412 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
413 | && field->fld_data.fld_cc->cc_addr_list ) { | 413 | && field->fld_data.fld_cc->cc_addr_list ) { |
414 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 414 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
415 | } | 415 | } |
416 | 416 | ||
417 | field = getField( fields, MAILIMF_FIELD_BCC ); | 417 | field = getField( fields, MAILIMF_FIELD_BCC ); |
418 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 418 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
419 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 419 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
420 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 420 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
421 | } | 421 | } |
422 | 422 | ||
423 | return rcptList; | 423 | return rcptList; |
424 | } | 424 | } |
425 | 425 | ||
426 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) | 426 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
427 | { | 427 | { |
428 | char *from = NULL; | 428 | char *from = NULL; |
429 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 429 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
430 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 430 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
431 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 431 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
432 | clistiter *it; | 432 | clistiter *it; |
433 | for ( it = clist_begin( cl ); it; it = it->next ) { | 433 | for ( it = clist_begin( cl ); it; it = it->next ) { |
434 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 434 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
435 | from = strdup( mb->mb_addr_spec ); | 435 | from = strdup( mb->mb_addr_spec ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | 438 | ||
439 | return from; | 439 | return from; |
440 | } | 440 | } |
441 | 441 | ||
442 | char *SMTPwrapper::getFrom( mailmime *mail ) | 442 | char *SMTPwrapper::getFrom( mailmime *mail ) |
443 | { | 443 | { |
444 | /* no need to delete - its just a pointer to structure content */ | ||
444 | mailimf_field *ffrom = 0; | 445 | mailimf_field *ffrom = 0; |
446 | char*f = 0; | ||
445 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 447 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
446 | return getFrom(ffrom); | 448 | return getFrom(ffrom); |
447 | } | 449 | } |
448 | 450 | ||
449 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | 451 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) |
450 | { | 452 | { |
451 | SMTPaccount *smtp; | 453 | SMTPaccount *smtp; |
452 | 454 | ||
453 | QList<Account> list = settings->getAccounts(); | 455 | QList<Account> list = settings->getAccounts(); |
454 | Account *it; | 456 | Account *it; |
455 | for ( it = list.first(); it; it = list.next() ) { | 457 | for ( it = list.first(); it; it = list.next() ) { |
456 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 458 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
457 | smtp = static_cast<SMTPaccount *>(it); | 459 | smtp = static_cast<SMTPaccount *>(it); |
458 | if ( smtp->getName()== name ) { | 460 | if ( smtp->getName()== name ) { |
459 | qDebug( "SMTPaccount found for" ); | 461 | qDebug( "SMTPaccount found for" ); |
460 | qDebug( name ); | 462 | qDebug( name ); |
461 | return smtp; | 463 | return smtp; |
462 | } | 464 | } |
463 | } | 465 | } |
464 | } | 466 | } |
465 | 467 | ||
466 | return NULL; | 468 | return NULL; |
467 | } | 469 | } |
468 | 470 | ||
469 | QString SMTPwrapper::getTmpFile() { | 471 | QString SMTPwrapper::getTmpFile() { |
470 | int num = 0; | 472 | int num = 0; |
471 | QString unique; | 473 | QString unique; |
472 | 474 | ||
473 | QDir dir( "/tmp" ); | 475 | QDir dir( "/tmp" ); |
474 | 476 | ||
475 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 477 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
476 | 478 | ||
477 | do { | 479 | do { |
478 | unique.setNum( num++ ); | 480 | unique.setNum( num++ ); |
479 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 481 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
480 | 482 | ||
481 | return "/tmp/opiemail-tmp-" + unique; | 483 | return "/tmp/opiemail-tmp-" + unique; |
482 | } | 484 | } |
483 | 485 | ||
484 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 486 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
485 | { | 487 | { |
486 | FILE *f; | 488 | FILE *f; |
487 | int err, col = 0; | 489 | int err, col = 0; |
488 | 490 | ||
489 | f = fopen( file.latin1(), "w" ); | 491 | f = fopen( file.latin1(), "w" ); |
490 | if ( f == NULL ) { | 492 | if ( f == NULL ) { |
491 | qDebug( "writeToFile: error opening file" ); | 493 | qDebug( "writeToFile: error opening file" ); |
492 | return; | 494 | return; |
493 | } | 495 | } |
494 | 496 | ||
495 | err = mailmime_write( f, &col, mail ); | 497 | err = mailmime_write( f, &col, mail ); |
496 | if ( err != MAILIMF_NO_ERROR ) { | 498 | if ( err != MAILIMF_NO_ERROR ) { |
497 | fclose( f ); | 499 | fclose( f ); |
498 | qDebug( "writeToFile: error writing mailmime" ); | 500 | qDebug( "writeToFile: error writing mailmime" ); |
499 | return; | 501 | return; |
500 | } | 502 | } |
501 | 503 | ||
502 | fclose( f ); | 504 | fclose( f ); |
503 | } | 505 | } |
504 | 506 | ||
505 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 507 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
506 | { | 508 | { |
507 | 509 | ||
508 | QFile msg_cache(file); | 510 | QFile msg_cache(file); |
509 | QString msg = ""; | 511 | QString msg = ""; |
510 | msg_cache.open(IO_ReadOnly); | 512 | msg_cache.open(IO_ReadOnly); |
511 | char*message = new char[4096]; | 513 | char*message = new char[4096]; |
512 | memset(message,0,4096); | 514 | memset(message,0,4096); |
513 | while (msg_cache.readBlock(message,4095)>0) { | 515 | while (msg_cache.readBlock(message,4095)>0) { |
514 | msg+=message; | 516 | msg+=message; |
515 | memset(message,0,4096); | 517 | memset(message,0,4096); |
516 | } | 518 | } |
517 | delete message; | 519 | delete message; |
518 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | 520 | *data = (char*)malloc(msg.length()+1*sizeof(char)); |
519 | memset(*data,0,msg.length()+1); | 521 | memset(*data,0,msg.length()+1); |
520 | memcpy(*data,msg.ascii(),msg.length()); | 522 | memcpy(*data,msg.ascii(),msg.length()); |
521 | *size=msg.length(); | 523 | *size=msg.length(); |
522 | } | 524 | } |
523 | 525 | ||
524 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 526 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
525 | { | 527 | { |
526 | if (SMTPwrapper::sendProgress) { | 528 | if (SMTPwrapper::sendProgress) { |
527 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 529 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
528 | qApp->processEvents(); | 530 | qApp->processEvents(); |
529 | } | 531 | } |
530 | } | 532 | } |
531 | 533 | ||
532 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 534 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
533 | { | 535 | { |
534 | if (!mail) return; | 536 | if (!mail) return; |
535 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 537 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
536 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 538 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
537 | wrap->storeMessage(mail,length,box); | 539 | wrap->storeMessage(mail,length,box); |
538 | delete wrap; | 540 | delete wrap; |
539 | } | 541 | } |
540 | 542 | ||
541 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | 543 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
542 | { | 544 | { |
543 | clist *rcpts = 0; | 545 | clist *rcpts = 0; |
544 | char *from, *data; | 546 | char *from, *data; |
545 | size_t size; | 547 | size_t size; |
546 | 548 | ||
547 | if ( smtp == NULL ) { | 549 | if ( smtp == NULL ) { |
548 | return; | 550 | return; |
549 | } | 551 | } |
550 | from = data = 0; | 552 | from = data = 0; |
551 | 553 | ||
552 | QString file = getTmpFile(); | 554 | QString file = getTmpFile(); |
553 | writeToFile( file, mail ); | 555 | writeToFile( file, mail ); |
554 | readFromFile( file, &data, &size ); | 556 | readFromFile( file, &data, &size ); |
555 | QFile f( file ); | 557 | QFile f( file ); |
556 | f.remove(); | 558 | f.remove(); |
557 | 559 | ||
558 | if (later) { | 560 | if (later) { |
559 | storeMail(data,size,"Outgoing"); | 561 | storeMail(data,size,"Outgoing"); |
560 | if (data) free( data ); | 562 | if (data) free( data ); |
561 | return; | 563 | return; |
562 | } | 564 | } |
563 | from = getFrom( mail ); | 565 | from = getFrom( mail ); |
564 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 566 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
565 | smtpSend(from,rcpts,data,size,smtp); | 567 | smtpSend(from,rcpts,data,size,smtp); |
568 | if (data) {free(data);} | ||
569 | if (from) {free(from);} | ||
570 | if (rcpts) smtp_address_list_free( rcpts ); | ||
566 | } | 571 | } |
567 | 572 | ||
568 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | 573 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) |
569 | { | 574 | { |
570 | char *server, *user, *pass; | 575 | char *server, *user, *pass; |
571 | bool ssl; | 576 | bool ssl; |
572 | uint16_t port; | 577 | uint16_t port; |
573 | mailsmtp *session; | 578 | mailsmtp *session; |
574 | int err,result; | 579 | int err,result; |
575 | 580 | ||
576 | result = 1; | 581 | result = 1; |
577 | server = user = pass = 0; | 582 | server = user = pass = 0; |
578 | server = strdup( smtp->getServer().latin1() ); | 583 | server = strdup( smtp->getServer().latin1() ); |
579 | ssl = smtp->getSSL(); | 584 | ssl = smtp->getSSL(); |
580 | port = smtp->getPort().toUInt(); | 585 | port = smtp->getPort().toUInt(); |
581 | 586 | ||
582 | session = mailsmtp_new( 20, &progress ); | 587 | session = mailsmtp_new( 20, &progress ); |
583 | if ( session == NULL ) goto free_mem; | 588 | if ( session == NULL ) goto free_mem; |
584 | 589 | ||
585 | qDebug( "Servername %s at port %i", server, port ); | 590 | qDebug( "Servername %s at port %i", server, port ); |
586 | if ( ssl ) { | 591 | if ( ssl ) { |
587 | qDebug( "SSL session" ); | 592 | qDebug( "SSL session" ); |
588 | err = mailsmtp_ssl_connect( session, server, port ); | 593 | err = mailsmtp_ssl_connect( session, server, port ); |
589 | } else { | 594 | } else { |
590 | qDebug( "No SSL session" ); | 595 | qDebug( "No SSL session" ); |
591 | err = mailsmtp_socket_connect( session, server, port ); | 596 | err = mailsmtp_socket_connect( session, server, port ); |
592 | } | 597 | } |
593 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} | 598 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
594 | 599 | ||
595 | err = mailsmtp_init( session ); | 600 | err = mailsmtp_init( session ); |
596 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 601 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
597 | 602 | ||
598 | qDebug( "INIT OK" ); | 603 | qDebug( "INIT OK" ); |
599 | 604 | ||
600 | if ( smtp->getLogin() ) { | 605 | if ( smtp->getLogin() ) { |
601 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 606 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
602 | // get'em | 607 | // get'em |
603 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 608 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
604 | login.show(); | 609 | login.show(); |
605 | if ( QDialog::Accepted == login.exec() ) { | 610 | if ( QDialog::Accepted == login.exec() ) { |
606 | // ok | 611 | // ok |
607 | user = strdup( login.getUser().latin1() ); | 612 | user = strdup( login.getUser().latin1() ); |
608 | pass = strdup( login.getPassword().latin1() ); | 613 | pass = strdup( login.getPassword().latin1() ); |
609 | } else { | 614 | } else { |
610 | result = 0; goto free_con_session; | 615 | result = 0; goto free_con_session; |
611 | } | 616 | } |
612 | } else { | 617 | } else { |
613 | user = strdup( smtp->getUser().latin1() ); | 618 | user = strdup( smtp->getUser().latin1() ); |
614 | pass = strdup( smtp->getPassword().latin1() ); | 619 | pass = strdup( smtp->getPassword().latin1() ); |
615 | } | 620 | } |
616 | qDebug( "session->auth: %i", session->auth); | 621 | qDebug( "session->auth: %i", session->auth); |
617 | err = mailsmtp_auth( session, user, pass ); | 622 | err = mailsmtp_auth( session, user, pass ); |
618 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 623 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
619 | qDebug( "Done auth!" ); | 624 | qDebug( "Done auth!" ); |
620 | } | 625 | } |
621 | 626 | ||
622 | err = mailsmtp_send( session, from, rcpts, data, size ); | 627 | err = mailsmtp_send( session, from, rcpts, data, size ); |
623 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 628 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
624 | 629 | ||
625 | qDebug( "Mail sent." ); | 630 | qDebug( "Mail sent." ); |
626 | storeMail(data,size,"Sent"); | 631 | storeMail(data,size,"Sent"); |
627 | 632 | ||
628 | free_con_session: | 633 | free_con_session: |
629 | mailsmtp_quit( session ); | 634 | mailsmtp_quit( session ); |
630 | free_mem_session: | 635 | free_mem_session: |
631 | mailsmtp_free( session ); | 636 | mailsmtp_free( session ); |
632 | free_mem: | 637 | free_mem: |
633 | if (rcpts) smtp_address_list_free( rcpts ); | ||
634 | if (data) free( data ); | ||
635 | if (server) free( server ); | 638 | if (server) free( server ); |
636 | if (from) free( from ); | ||
637 | if ( smtp->getLogin() ) { | 639 | if ( smtp->getLogin() ) { |
638 | free( user ); | 640 | free( user ); |
639 | free( pass ); | 641 | free( pass ); |
640 | } | 642 | } |
641 | return result; | 643 | return result; |
642 | } | 644 | } |
643 | 645 | ||
644 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 646 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
645 | { | 647 | { |
646 | mailmime * mimeMail; | 648 | mailmime * mimeMail; |
647 | 649 | ||
648 | SMTPaccount *smtp = getAccount(mail.getName()); | 650 | SMTPaccount *smtp = getAccount(mail.getName()); |
649 | 651 | ||
650 | mimeMail = createMimeMail(mail ); | 652 | mimeMail = createMimeMail(mail ); |
651 | if ( mimeMail == NULL ) { | 653 | if ( mimeMail == NULL ) { |
652 | qDebug( "sendMail: error creating mime mail" ); | 654 | qDebug( "sendMail: error creating mime mail" ); |
653 | } else { | 655 | } else { |
654 | sendProgress = new progressMailSend(); | 656 | sendProgress = new progressMailSend(); |
655 | // sendProgress->showMaximized(); | ||
656 | sendProgress->show(); | 657 | sendProgress->show(); |
657 | sendProgress->setMaxMails(1); | 658 | sendProgress->setMaxMails(1); |
658 | smtpSend( mimeMail,later,smtp); | 659 | smtpSend( mimeMail,later,smtp); |
659 | mailmime_free( mimeMail ); | 660 | mailmime_free( mimeMail ); |
660 | qDebug("Clean up done"); | 661 | qDebug("Clean up done"); |
661 | sendProgress->hide(); | 662 | sendProgress->hide(); |
662 | delete sendProgress; | 663 | delete sendProgress; |
663 | sendProgress = 0; | 664 | sendProgress = 0; |
664 | } | 665 | } |
665 | } | 666 | } |
666 | 667 | ||
667 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | 668 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) |
668 | { | 669 | { |
669 | char*data = 0; | 670 | char*data = 0; |
670 | size_t length = 0; | 671 | size_t length = 0; |
671 | size_t curTok = 0; | 672 | size_t curTok = 0; |
672 | mailimf_fields *fields = 0; | 673 | mailimf_fields *fields = 0; |
673 | mailimf_field*ffrom = 0; | 674 | mailimf_field*ffrom = 0; |
674 | clist *rcpts = 0; | 675 | clist *rcpts = 0; |
675 | char*from = 0; | 676 | char*from = 0; |
677 | int res = 0; | ||
676 | 678 | ||
677 | wrap->fetchRawBody(*which,&data,&length); | 679 | wrap->fetchRawBody(*which,&data,&length); |
678 | if (!data) return 0; | 680 | if (!data) return 0; |
679 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | 681 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); |
680 | if (err != MAILIMF_NO_ERROR) { | 682 | if (err != MAILIMF_NO_ERROR) { |
681 | free(data); | 683 | free(data); |
682 | delete wrap; | 684 | delete wrap; |
683 | return 0; | 685 | return 0; |
684 | } | 686 | } |
685 | 687 | ||
686 | rcpts = createRcptList( fields ); | 688 | rcpts = createRcptList( fields ); |
687 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 689 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
688 | from = getFrom(ffrom); | 690 | from = getFrom(ffrom); |
689 | 691 | ||
690 | qDebug("Size: %i vs. %i",length,strlen(data)); | 692 | qDebug("Size: %i vs. %i",length,strlen(data)); |
691 | if (rcpts && from) { | 693 | if (rcpts && from) { |
692 | return smtpSend(from,rcpts,data,strlen(data),smtp ); | 694 | res = smtpSend(from,rcpts,data,length,smtp ); |
693 | } | 695 | } |
694 | return 0; | 696 | if (fields) { |
697 | mailimf_fields_free(fields); | ||
698 | fields = 0; | ||
699 | } | ||
700 | if (data) { | ||
701 | free(data); | ||
702 | } | ||
703 | if (from) { | ||
704 | free(from); | ||
705 | } | ||
706 | if (rcpts) { | ||
707 | smtp_address_list_free( rcpts ); | ||
708 | } | ||
709 | return res; | ||
695 | } | 710 | } |
696 | 711 | ||
697 | /* this is a special fun */ | 712 | /* this is a special fun */ |
698 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | 713 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) |
699 | { | 714 | { |
700 | bool returnValue = true; | 715 | bool returnValue = true; |
701 | 716 | ||
702 | if (!smtp) return false; | 717 | if (!smtp) return false; |
703 | 718 | ||
704 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 719 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
705 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 720 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
706 | if (!wrap) { | 721 | if (!wrap) { |
707 | qDebug("memory error"); | 722 | qDebug("memory error"); |
708 | return false; | 723 | return false; |
709 | } | 724 | } |
710 | QList<RecMail> mailsToSend; | 725 | QList<RecMail> mailsToSend; |
711 | QList<RecMail> mailsToRemove; | 726 | QList<RecMail> mailsToRemove; |
712 | QString mbox("Outgoing"); | 727 | QString mbox("Outgoing"); |
713 | wrap->listMessages(mbox,mailsToSend); | 728 | wrap->listMessages(mbox,mailsToSend); |
714 | if (mailsToSend.count()==0) { | 729 | if (mailsToSend.count()==0) { |
715 | delete wrap; | 730 | delete wrap; |
716 | return false; | 731 | return false; |
717 | } | 732 | } |
718 | mailsToSend.setAutoDelete(false); | 733 | mailsToSend.setAutoDelete(false); |
719 | sendProgress = new progressMailSend(); | 734 | sendProgress = new progressMailSend(); |
720 | // sendProgress->showMaximized(); | 735 | sendProgress->show(); |
721 | sendProgress->show(); | 736 | sendProgress->setMaxMails(mailsToSend.count()); |
722 | sendProgress->setMaxMails(mailsToSend.count()); | ||
723 | 737 | ||
724 | while (mailsToSend.count()>0) { | 738 | while (mailsToSend.count()>0) { |
725 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 739 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
726 | QMessageBox::critical(0,tr("Error sending mail"), | 740 | QMessageBox::critical(0,tr("Error sending mail"), |
727 | tr("Error sending queued mail - breaking")); | 741 | tr("Error sending queued mail - breaking")); |
728 | 742 | ||
729 | returnValue = false; | 743 | returnValue = false; |
730 | break; | 744 | break; |
731 | } | 745 | } |
732 | mailsToRemove.append(mailsToSend.at(0)); | 746 | mailsToRemove.append(mailsToSend.at(0)); |
733 | mailsToSend.removeFirst(); | 747 | mailsToSend.removeFirst(); |
734 | sendProgress->setCurrentMails(mailsToRemove.count()); | 748 | sendProgress->setCurrentMails(mailsToRemove.count()); |
735 | } | 749 | } |
736 | sendProgress->hide(); | 750 | sendProgress->hide(); |
737 | delete sendProgress; | 751 | delete sendProgress; |
738 | sendProgress = 0; | 752 | sendProgress = 0; |
739 | wrap->deleteMails(mbox,mailsToRemove); | 753 | wrap->deleteMails(mbox,mailsToRemove); |
740 | mailsToSend.setAutoDelete(true); | 754 | mailsToSend.setAutoDelete(true); |
741 | delete wrap; | 755 | delete wrap; |
742 | return returnValue; | 756 | return returnValue; |
743 | |||
744 | } | 757 | } |