author | alwin <alwin> | 2003-12-24 14:18:28 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-24 14:18:28 (UTC) |
commit | 9d2a848b254d6c859d7054d486eedac6535d26ec (patch) (unidiff) | |
tree | d3cb3479465b1cc6ef4b67898fc9649f8416c3da | |
parent | c609fd3341bccf6150e313f4fa08ff3ca9086503 (diff) | |
download | opie-9d2a848b254d6c859d7054d486eedac6535d26ec.zip opie-9d2a848b254d6c859d7054d486eedac6535d26ec.tar.gz opie-9d2a848b254d6c859d7054d486eedac6535d26ec.tar.bz2 |
hopefully fixed some memleaks and some not initialized vars
-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 | |||
@@ -1,393 +1,393 @@ | |||
1 | #include "genericwrapper.h" | 1 | #include "genericwrapper.h" |
2 | #include <libetpan/mailmime.h> | 2 | #include <libetpan/mailmime.h> |
3 | #include <libetpan/data_message_driver.h> | 3 | #include <libetpan/data_message_driver.h> |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | Genericwrapper::Genericwrapper() | 6 | Genericwrapper::Genericwrapper() |
7 | : AbstractMail() | 7 | : AbstractMail() |
8 | { | 8 | { |
9 | bodyCache.clear(); | 9 | bodyCache.clear(); |
10 | } | 10 | } |
11 | 11 | ||
12 | Genericwrapper::~Genericwrapper() | 12 | Genericwrapper::~Genericwrapper() |
13 | { | 13 | { |
14 | cleanMimeCache(); | 14 | cleanMimeCache(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | 17 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) |
18 | { | 18 | { |
19 | if (!mime) { | 19 | if (!mime) { |
20 | return; | 20 | return; |
21 | } | 21 | } |
22 | mailmime_field*field = 0; | 22 | mailmime_field*field = 0; |
23 | mailmime_single_fields fields; | 23 | mailmime_single_fields fields; |
24 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 24 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
25 | if (mime->mm_mime_fields != NULL) { | 25 | if (mime->mm_mime_fields != NULL) { |
26 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 26 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
27 | mime->mm_content_type); | 27 | mime->mm_content_type); |
28 | } | 28 | } |
29 | 29 | ||
30 | mailmime_content*type = fields.fld_content; | 30 | mailmime_content*type = fields.fld_content; |
31 | clistcell*current; | 31 | clistcell*current; |
32 | if (!type) { | 32 | if (!type) { |
33 | target.setType("text"); | 33 | target.setType("text"); |
34 | target.setSubtype("plain"); | 34 | target.setSubtype("plain"); |
35 | } else { | 35 | } else { |
36 | target.setSubtype(type->ct_subtype); | 36 | target.setSubtype(type->ct_subtype); |
37 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 37 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
38 | case MAILMIME_DISCRETE_TYPE_TEXT: | 38 | case MAILMIME_DISCRETE_TYPE_TEXT: |
39 | target.setType("text"); | 39 | target.setType("text"); |
40 | break; | 40 | break; |
41 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 41 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
42 | target.setType("image"); | 42 | target.setType("image"); |
43 | break; | 43 | break; |
44 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 44 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
45 | target.setType("audio"); | 45 | target.setType("audio"); |
46 | break; | 46 | break; |
47 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 47 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
48 | target.setType("video"); | 48 | target.setType("video"); |
49 | break; | 49 | break; |
50 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 50 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
51 | target.setType("application"); | 51 | target.setType("application"); |
52 | break; | 52 | break; |
53 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 53 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
54 | default: | 54 | default: |
55 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 55 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
56 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 56 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
57 | } | 57 | } |
58 | break; | 58 | break; |
59 | } | 59 | } |
60 | if (type->ct_parameters) { | 60 | if (type->ct_parameters) { |
61 | fillParameters(target,type->ct_parameters); | 61 | fillParameters(target,type->ct_parameters); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 64 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
65 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 65 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
66 | field = (mailmime_field*)current->data; | 66 | field = (mailmime_field*)current->data; |
67 | switch(field->fld_type) { | 67 | switch(field->fld_type) { |
68 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 68 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
69 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | 69 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); |
70 | break; | 70 | break; |
71 | case MAILMIME_FIELD_ID: | 71 | case MAILMIME_FIELD_ID: |
72 | target.setIdentifier(field->fld_data.fld_id); | 72 | target.setIdentifier(field->fld_data.fld_id); |
73 | break; | 73 | break; |
74 | case MAILMIME_FIELD_DESCRIPTION: | 74 | case MAILMIME_FIELD_DESCRIPTION: |
75 | target.setDescription(field->fld_data.fld_description); | 75 | target.setDescription(field->fld_data.fld_description); |
76 | break; | 76 | break; |
77 | default: | 77 | default: |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) | 84 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) |
85 | { | 85 | { |
86 | if (!parameters) {return;} | 86 | if (!parameters) {return;} |
87 | clistcell*current=0; | 87 | clistcell*current=0; |
88 | mailmime_parameter*param; | 88 | mailmime_parameter*param; |
89 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 89 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
90 | param = (mailmime_parameter*)current->data; | 90 | param = (mailmime_parameter*)current->data; |
91 | if (param) { | 91 | if (param) { |
92 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 92 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 97 | 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: |
293 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 293 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
294 | break; | 294 | break; |
295 | case MAILIMF_ADDRESS_GROUP: | 295 | case MAILIMF_ADDRESS_GROUP: |
296 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 296 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
297 | break; | 297 | break; |
298 | default: | 298 | default: |
299 | qDebug( "Generic: unkown mailimf address type" ); | 299 | qDebug( "Generic: unkown mailimf address type" ); |
300 | break; | 300 | break; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | return result; | 304 | return result; |
305 | } | 305 | } |
306 | 306 | ||
307 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 307 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
308 | { | 308 | { |
309 | QString result( "" ); | 309 | QString result( "" ); |
310 | 310 | ||
311 | result.append( group->grp_display_name ); | 311 | result.append( group->grp_display_name ); |
312 | result.append( ": " ); | 312 | result.append( ": " ); |
313 | 313 | ||
314 | if ( group->grp_mb_list != NULL ) { | 314 | if ( group->grp_mb_list != NULL ) { |
315 | result.append( parseMailboxList( group->grp_mb_list ) ); | 315 | result.append( parseMailboxList( group->grp_mb_list ) ); |
316 | } | 316 | } |
317 | 317 | ||
318 | result.append( ";" ); | 318 | result.append( ";" ); |
319 | 319 | ||
320 | return result; | 320 | return result; |
321 | } | 321 | } |
322 | 322 | ||
323 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 323 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
324 | { | 324 | { |
325 | QString result( "" ); | 325 | QString result( "" ); |
326 | 326 | ||
327 | if ( box->mb_display_name == NULL ) { | 327 | if ( box->mb_display_name == NULL ) { |
328 | result.append( box->mb_addr_spec ); | 328 | result.append( box->mb_addr_spec ); |
329 | } else { | 329 | } else { |
330 | result.append( convert_String(box->mb_display_name).latin1() ); | 330 | result.append( convert_String(box->mb_display_name).latin1() ); |
331 | result.append( " <" ); | 331 | result.append( " <" ); |
332 | result.append( box->mb_addr_spec ); | 332 | result.append( box->mb_addr_spec ); |
333 | result.append( ">" ); | 333 | result.append( ">" ); |
334 | } | 334 | } |
335 | 335 | ||
336 | return result; | 336 | return result; |
337 | } | 337 | } |
338 | 338 | ||
339 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 339 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
340 | { | 340 | { |
341 | QString result( "" ); | 341 | QString result( "" ); |
342 | 342 | ||
343 | bool first = true; | 343 | bool first = true; |
344 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 344 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
345 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 345 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
346 | 346 | ||
347 | if ( !first ) { | 347 | if ( !first ) { |
348 | result.append( "," ); | 348 | result.append( "," ); |
349 | } else { | 349 | } else { |
350 | first = false; | 350 | first = false; |
351 | } | 351 | } |
352 | 352 | ||
353 | result.append( parseMailbox( box ) ); | 353 | result.append( parseMailbox( box ) ); |
354 | } | 354 | } |
355 | 355 | ||
356 | return result; | 356 | return result; |
357 | } | 357 | } |
358 | 358 | ||
359 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) | 359 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
360 | { | 360 | { |
361 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 361 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
362 | if (it==bodyCache.end()) return new encodedString(); | 362 | if (it==bodyCache.end()) return new encodedString(); |
363 | encodedString*t = decode_String(it.data(),part.Encoding()); | 363 | encodedString*t = decode_String(it.data(),part.Encoding()); |
364 | return t; | 364 | return t; |
365 | } | 365 | } |
366 | 366 | ||
367 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 367 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
368 | { | 368 | { |
369 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 369 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
370 | if (it==bodyCache.end()) return new encodedString(); | 370 | if (it==bodyCache.end()) return new encodedString(); |
371 | encodedString*t = it.data(); | 371 | encodedString*t = it.data(); |
372 | return t; | 372 | return t; |
373 | } | 373 | } |
374 | 374 | ||
375 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 375 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
376 | { | 376 | { |
377 | encodedString*t = fetchDecodedPart(mail,part); | 377 | encodedString*t = fetchDecodedPart(mail,part); |
378 | QString text=t->Content(); | 378 | QString text=t->Content(); |
379 | delete t; | 379 | delete t; |
380 | return text; | 380 | return text; |
381 | } | 381 | } |
382 | 382 | ||
383 | void Genericwrapper::cleanMimeCache() | 383 | void Genericwrapper::cleanMimeCache() |
384 | { | 384 | { |
385 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 385 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
386 | for (;it!=bodyCache.end();++it) { | 386 | for (;it!=bodyCache.end();++it) { |
387 | encodedString*t = it.data(); | 387 | encodedString*t = it.data(); |
388 | //it.setValue(0); | 388 | //it.setValue(0); |
389 | if (t) delete t; | 389 | if (t) delete t; |
390 | } | 390 | } |
391 | bodyCache.clear(); | 391 | bodyCache.clear(); |
392 | qDebug("Genericwrapper: cache cleaned"); | 392 | qDebug("Genericwrapper: cache cleaned"); |
393 | } | 393 | } |
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,820 +1,818 @@ | |||
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; |
254 | size = 0; | 252 | size = 0; |
255 | item = (mailimap_msg_att_item*)current->data; | 253 | item = (mailimap_msg_att_item*)current->data; |
256 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 254 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
257 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 255 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
258 | if (!flist->att_list) { | 256 | if (!flist->att_list) { |
259 | continue; | 257 | continue; |
260 | } | 258 | } |
261 | cf = flist->att_list->first; | 259 | cf = flist->att_list->first; |
262 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 260 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
263 | cflag = (mailimap_flag_fetch*)cf->data; | 261 | cflag = (mailimap_flag_fetch*)cf->data; |
264 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 262 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
265 | switch (cflag->fl_flag->fl_type) { | 263 | switch (cflag->fl_flag->fl_type) { |
266 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 264 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
267 | mFlags.setBit(FLAG_ANSWERED); | 265 | mFlags.setBit(FLAG_ANSWERED); |
268 | break; | 266 | break; |
269 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 267 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
270 | mFlags.setBit(FLAG_FLAGGED); | 268 | mFlags.setBit(FLAG_FLAGGED); |
271 | break; | 269 | break; |
272 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 270 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
273 | mFlags.setBit(FLAG_DELETED); | 271 | mFlags.setBit(FLAG_DELETED); |
274 | break; | 272 | break; |
275 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 273 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
276 | mFlags.setBit(FLAG_SEEN); | 274 | mFlags.setBit(FLAG_SEEN); |
277 | break; | 275 | break; |
278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 276 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
279 | mFlags.setBit(FLAG_DRAFT); | 277 | mFlags.setBit(FLAG_DRAFT); |
280 | break; | 278 | break; |
281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 279 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
282 | break; | 280 | break; |
283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 281 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
284 | break; | 282 | break; |
285 | default: | 283 | default: |
286 | break; | 284 | break; |
287 | } | 285 | } |
288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 286 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
289 | mFlags.setBit(FLAG_RECENT); | 287 | mFlags.setBit(FLAG_RECENT); |
290 | } | 288 | } |
291 | } | 289 | } |
292 | continue; | 290 | continue; |
293 | } | 291 | } |
294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 292 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 293 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
296 | m->setDate(head->env_date); | 294 | m->setDate(head->env_date); |
297 | m->setSubject(convert_String((const char*)head->env_subject)); | 295 | m->setSubject(convert_String((const char*)head->env_subject)); |
298 | //m->setSubject(head->env_subject); | 296 | //m->setSubject(head->env_subject); |
299 | if (head->env_from!=NULL) { | 297 | if (head->env_from!=NULL) { |
300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 298 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
301 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
302 | m->setFrom(addresslist.first()); | 300 | m->setFrom(addresslist.first()); |
303 | } | 301 | } |
304 | } | 302 | } |
305 | if (head->env_to!=NULL) { | 303 | if (head->env_to!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 304 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
307 | m->setTo(addresslist); | 305 | m->setTo(addresslist); |
308 | } | 306 | } |
309 | if (head->env_cc!=NULL) { | 307 | if (head->env_cc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 308 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
311 | m->setCC(addresslist); | 309 | m->setCC(addresslist); |
312 | } | 310 | } |
313 | if (head->env_bcc!=NULL) { | 311 | if (head->env_bcc!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 312 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
315 | m->setBcc(addresslist); | 313 | m->setBcc(addresslist); |
316 | } | 314 | } |
317 | if (head->env_reply_to!=NULL) { | 315 | if (head->env_reply_to!=NULL) { |
318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 316 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
319 | if (addresslist.count()) { | 317 | if (addresslist.count()) { |
320 | m->setReplyto(addresslist.first()); | 318 | m->setReplyto(addresslist.first()); |
321 | } | 319 | } |
322 | } | 320 | } |
323 | m->setMsgid(QString(head->env_message_id)); | 321 | m->setMsgid(QString(head->env_message_id)); |
324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 322 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
325 | #if 0 | 323 | #if 0 |
326 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 324 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
327 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 325 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
328 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 326 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
329 | qDebug(da.toString()); | 327 | qDebug(da.toString()); |
330 | #endif | 328 | #endif |
331 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 329 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
332 | size = item->att_data.att_static->att_data.att_rfc822_size; | 330 | size = item->att_data.att_static->att_data.att_rfc822_size; |
333 | } | 331 | } |
334 | } | 332 | } |
335 | /* msg is already deleted */ | 333 | /* msg is already deleted */ |
336 | if (mFlags.testBit(FLAG_DELETED) && m) { | 334 | if (mFlags.testBit(FLAG_DELETED) && m) { |
337 | delete m; | 335 | delete m; |
338 | m = 0; | 336 | m = 0; |
339 | } | 337 | } |
340 | if (m) { | 338 | if (m) { |
341 | m->setFlags(mFlags); | 339 | m->setFlags(mFlags); |
342 | m->setMsgsize(size); | 340 | m->setMsgsize(size); |
343 | } | 341 | } |
344 | return m; | 342 | return m; |
345 | } | 343 | } |
346 | 344 | ||
347 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 345 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
348 | { | 346 | { |
349 | RecBody body; | 347 | RecBody body; |
350 | const char *mb; | 348 | const char *mb; |
351 | int err = MAILIMAP_NO_ERROR; | 349 | int err = MAILIMAP_NO_ERROR; |
352 | clist *result; | 350 | clist *result; |
353 | clistcell *current; | 351 | clistcell *current; |
354 | mailimap_fetch_att *fetchAtt; | 352 | mailimap_fetch_att *fetchAtt; |
355 | mailimap_fetch_type *fetchType; | 353 | mailimap_fetch_type *fetchType; |
356 | mailimap_set *set; | 354 | mailimap_set *set; |
357 | mailimap_body*body_desc; | 355 | mailimap_body*body_desc; |
358 | 356 | ||
359 | mb = mail.getMbox().latin1(); | 357 | mb = mail.getMbox().latin1(); |
360 | 358 | ||
361 | login(); | 359 | login(); |
362 | if (!m_imap) { | 360 | if (!m_imap) { |
363 | return body; | 361 | return body; |
364 | } | 362 | } |
365 | 363 | ||
366 | err = mailimap_select( m_imap, (char*)mb); | 364 | err = mailimap_select( m_imap, (char*)mb); |
367 | if ( err != MAILIMAP_NO_ERROR ) { | 365 | if ( err != MAILIMAP_NO_ERROR ) { |
368 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 366 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
369 | return body; | 367 | return body; |
370 | } | 368 | } |
371 | 369 | ||
372 | result = clist_new(); | 370 | result = clist_new(); |
373 | /* the range has to start at 1!!! not with 0!!!! */ | 371 | /* the range has to start at 1!!! not with 0!!!! */ |
374 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 372 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
375 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 373 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
376 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 374 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
377 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 375 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
378 | mailimap_set_free( set ); | 376 | mailimap_set_free( set ); |
379 | mailimap_fetch_type_free( fetchType ); | 377 | mailimap_fetch_type_free( fetchType ); |
380 | 378 | ||
381 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 379 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
382 | mailimap_msg_att * msg_att; | 380 | mailimap_msg_att * msg_att; |
383 | msg_att = (mailimap_msg_att*)current->data; | 381 | msg_att = (mailimap_msg_att*)current->data; |
384 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 382 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
385 | body_desc = item->att_data.att_static->att_data.att_body; | 383 | body_desc = item->att_data.att_static->att_data.att_body; |
386 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 384 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
387 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 385 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
388 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 386 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
389 | qDebug("Mulitpart mail"); | 387 | qDebug("Mulitpart mail"); |
390 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 388 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
391 | } | 389 | } |
392 | } else { | 390 | } else { |
393 | qDebug("error fetching body: %s",m_imap->imap_response); | 391 | qDebug("error fetching body: %s",m_imap->imap_response); |
394 | } | 392 | } |
395 | mailimap_fetch_list_free(result); | 393 | mailimap_fetch_list_free(result); |
396 | return body; | 394 | return body; |
397 | } | 395 | } |
398 | 396 | ||
399 | /* this routine is just called when the mail has only ONE part. | 397 | /* this routine is just called when the mail has only ONE part. |
400 | for filling the parts of a multi-part-message there are other | 398 | for filling the parts of a multi-part-message there are other |
401 | routines 'cause we can not simply fetch the whole body. */ | 399 | routines 'cause we can not simply fetch the whole body. */ |
402 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 400 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
403 | { | 401 | { |
404 | if (!mailDescription) { | 402 | if (!mailDescription) { |
405 | return; | 403 | return; |
406 | } | 404 | } |
407 | QString sub,body_text; | 405 | QString sub,body_text; |
408 | RecPart singlePart; | 406 | RecPart singlePart; |
409 | QValueList<int> path; | 407 | QValueList<int> path; |
410 | fillSinglePart(singlePart,mailDescription); | 408 | fillSinglePart(singlePart,mailDescription); |
411 | switch (mailDescription->bd_type) { | 409 | switch (mailDescription->bd_type) { |
412 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 410 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
413 | path.append(1); | 411 | path.append(1); |
414 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 412 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
415 | target_body.setBodytext(body_text); | 413 | target_body.setBodytext(body_text); |
416 | target_body.setDescription(singlePart); | 414 | target_body.setDescription(singlePart); |
417 | break; | 415 | break; |
418 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 416 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
419 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 417 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
420 | path.append(1); | 418 | path.append(1); |
421 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 419 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
422 | target_body.setBodytext(body_text); | 420 | target_body.setBodytext(body_text); |
423 | target_body.setDescription(singlePart); | 421 | target_body.setDescription(singlePart); |
424 | break; | 422 | break; |
425 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 423 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
426 | qDebug("Single attachment"); | 424 | qDebug("Single attachment"); |
427 | target_body.setBodytext(""); | 425 | target_body.setBodytext(""); |
428 | target_body.addPart(singlePart); | 426 | target_body.addPart(singlePart); |
429 | break; | 427 | break; |
430 | default: | 428 | default: |
431 | break; | 429 | break; |
432 | } | 430 | } |
433 | 431 | ||
434 | return; | 432 | return; |
435 | } | 433 | } |
436 | 434 | ||
437 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 435 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
438 | { | 436 | { |
439 | QStringList l; | 437 | QStringList l; |
440 | QString from; | 438 | QString from; |
441 | bool named_from; | 439 | bool named_from; |
442 | clistcell *current = NULL; | 440 | clistcell *current = NULL; |
443 | mailimap_address * current_address=NULL; | 441 | mailimap_address * current_address=NULL; |
444 | if (!list) { | 442 | if (!list) { |
445 | return l; | 443 | return l; |
446 | } | 444 | } |
447 | unsigned int count = 0; | 445 | unsigned int count = 0; |
448 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 446 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
449 | from = ""; | 447 | from = ""; |
450 | named_from = false; | 448 | named_from = false; |
451 | current_address=(mailimap_address*)current->data; | 449 | current_address=(mailimap_address*)current->data; |
452 | if (current_address->ad_personal_name){ | 450 | if (current_address->ad_personal_name){ |
453 | from+=convert_String((const char*)current_address->ad_personal_name); | 451 | from+=convert_String((const char*)current_address->ad_personal_name); |
454 | //from+=QString(current_address->ad_personal_name); | 452 | //from+=QString(current_address->ad_personal_name); |
455 | from+=" "; | 453 | from+=" "; |
456 | named_from = true; | 454 | named_from = true; |
457 | } | 455 | } |
458 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 456 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
459 | from+="<"; | 457 | from+="<"; |
460 | } | 458 | } |
461 | if (current_address->ad_mailbox_name) { | 459 | if (current_address->ad_mailbox_name) { |
462 | from+=QString(current_address->ad_mailbox_name); | 460 | from+=QString(current_address->ad_mailbox_name); |
463 | from+="@"; | 461 | from+="@"; |
464 | } | 462 | } |
465 | if (current_address->ad_host_name) { | 463 | if (current_address->ad_host_name) { |
466 | from+=QString(current_address->ad_host_name); | 464 | from+=QString(current_address->ad_host_name); |
467 | } | 465 | } |
468 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 466 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
469 | from+=">"; | 467 | from+=">"; |
470 | } | 468 | } |
471 | l.append(QString(from)); | 469 | l.append(QString(from)); |
472 | if (++count > 99) { | 470 | if (++count > 99) { |
473 | break; | 471 | break; |
474 | } | 472 | } |
475 | } | 473 | } |
476 | return l; | 474 | return l; |
477 | } | 475 | } |
478 | 476 | ||
479 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 477 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
480 | { | 478 | { |
481 | encodedString*res=new encodedString; | 479 | encodedString*res=new encodedString; |
482 | const char*mb; | 480 | const char*mb; |
483 | int err; | 481 | int err; |
484 | mailimap_fetch_type *fetchType; | 482 | mailimap_fetch_type *fetchType; |
485 | mailimap_set *set; | 483 | mailimap_set *set; |
486 | clistcell*current,*cur; | 484 | clistcell*current,*cur; |
487 | 485 | ||
488 | login(); | 486 | login(); |
489 | if (!m_imap) { | 487 | if (!m_imap) { |
490 | return res; | 488 | return res; |
491 | } | 489 | } |
492 | if (!internal_call) { | 490 | if (!internal_call) { |
493 | mb = mail.getMbox().latin1(); | 491 | mb = mail.getMbox().latin1(); |
494 | err = mailimap_select( m_imap, (char*)mb); | 492 | err = mailimap_select( m_imap, (char*)mb); |
495 | if ( err != MAILIMAP_NO_ERROR ) { | 493 | if ( err != MAILIMAP_NO_ERROR ) { |
496 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 494 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
497 | return res; | 495 | return res; |
498 | } | 496 | } |
499 | } | 497 | } |
500 | set = mailimap_set_new_single(mail.getNumber()); | 498 | set = mailimap_set_new_single(mail.getNumber()); |
501 | clist*id_list=clist_new(); | 499 | clist*id_list=clist_new(); |
502 | for (unsigned j=0; j < path.count();++j) { | 500 | for (unsigned j=0; j < path.count();++j) { |
503 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 501 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
504 | *p_id = path[j]; | 502 | *p_id = path[j]; |
505 | clist_append(id_list,p_id); | 503 | clist_append(id_list,p_id); |
506 | } | 504 | } |
507 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 505 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 506 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
509 | mailimap_section * section = mailimap_section_new(section_spec); | 507 | mailimap_section * section = mailimap_section_new(section_spec); |
510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 508 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
511 | 509 | ||
512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 510 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
513 | 511 | ||
514 | clist*result = clist_new(); | 512 | clist*result = clist_new(); |
515 | 513 | ||
516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 514 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
517 | mailimap_set_free( set ); | 515 | mailimap_set_free( set ); |
518 | mailimap_fetch_type_free( fetchType ); | 516 | mailimap_fetch_type_free( fetchType ); |
519 | 517 | ||
520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 518 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
521 | mailimap_msg_att * msg_att; | 519 | mailimap_msg_att * msg_att; |
522 | msg_att = (mailimap_msg_att*)current->data; | 520 | msg_att = (mailimap_msg_att*)current->data; |
523 | mailimap_msg_att_item*msg_att_item; | 521 | mailimap_msg_att_item*msg_att_item; |
524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 522 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 523 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 524 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 525 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 526 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
529 | /* detach - we take over the content */ | 527 | /* detach - we take over the content */ |
530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 528 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 529 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
532 | } | 530 | } |
533 | } | 531 | } |
534 | } | 532 | } |
535 | } else { | 533 | } else { |
536 | qDebug("error fetching text: %s",m_imap->imap_response); | 534 | qDebug("error fetching text: %s",m_imap->imap_response); |
537 | } | 535 | } |
538 | mailimap_fetch_list_free(result); | 536 | mailimap_fetch_list_free(result); |
539 | return res; | 537 | return res; |
540 | } | 538 | } |
541 | 539 | ||
542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 540 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
543 | { | 541 | { |
544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 542 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
545 | if (!mailDescription||current_recursion==10) { | 543 | if (!mailDescription||current_recursion==10) { |
546 | return; | 544 | return; |
547 | } | 545 | } |
548 | clistcell*current; | 546 | clistcell*current; |
549 | mailimap_body*current_body; | 547 | mailimap_body*current_body; |
550 | unsigned int count = 0; | 548 | unsigned int count = 0; |
551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 549 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
552 | /* the point in the message */ | 550 | /* the point in the message */ |
553 | ++count; | 551 | ++count; |
554 | current_body = (mailimap_body*)current->data; | 552 | current_body = (mailimap_body*)current->data; |
555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 553 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
556 | QValueList<int>countlist = recList; | 554 | QValueList<int>countlist = recList; |
557 | countlist.append(count); | 555 | countlist.append(count); |
558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 556 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 557 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
560 | RecPart currentPart; | 558 | RecPart currentPart; |
561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 559 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
562 | QValueList<int>countlist = recList; | 560 | QValueList<int>countlist = recList; |
563 | countlist.append(count); | 561 | countlist.append(count); |
564 | /* important: Check for is NULL 'cause a body can be empty! */ | 562 | /* important: Check for is NULL 'cause a body can be empty! */ |
565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 563 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 564 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
567 | target_body.setDescription(currentPart); | 565 | target_body.setDescription(currentPart); |
568 | target_body.setBodytext(body_text); | 566 | target_body.setBodytext(body_text); |
569 | } else { | 567 | } else { |
570 | QString id(""); | 568 | QString id(""); |
571 | for (unsigned int j = 0; j < countlist.count();++j) { | 569 | for (unsigned int j = 0; j < countlist.count();++j) { |
572 | id+=(j>0?" ":""); | 570 | id+=(j>0?" ":""); |
573 | id+=QString("%1").arg(countlist[j]); | 571 | id+=QString("%1").arg(countlist[j]); |
574 | } | 572 | } |
575 | qDebug("ID= %s",id.latin1()); | 573 | qDebug("ID= %s",id.latin1()); |
576 | currentPart.setIdentifier(id); | 574 | currentPart.setIdentifier(id); |
577 | currentPart.setPositionlist(countlist); | 575 | currentPart.setPositionlist(countlist); |
578 | target_body.addPart(currentPart); | 576 | target_body.addPart(currentPart); |
579 | } | 577 | } |
580 | } | 578 | } |
581 | } | 579 | } |
582 | } | 580 | } |
583 | 581 | ||
584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 582 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
585 | { | 583 | { |
586 | if (!Description) { | 584 | if (!Description) { |
587 | return; | 585 | return; |
588 | } | 586 | } |
589 | switch (Description->bd_type) { | 587 | switch (Description->bd_type) { |
590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 588 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
591 | target_part.setType("text"); | 589 | target_part.setType("text"); |
592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 590 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
593 | break; | 591 | break; |
594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 592 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 593 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
596 | break; | 594 | break; |
597 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 595 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 596 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
599 | break; | 597 | break; |
600 | default: | 598 | default: |
601 | break; | 599 | break; |
602 | } | 600 | } |
603 | } | 601 | } |
604 | 602 | ||
605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 603 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
606 | { | 604 | { |
607 | if (!which) { | 605 | if (!which) { |
608 | return; | 606 | return; |
609 | } | 607 | } |
610 | QString sub; | 608 | QString sub; |
611 | sub = which->bd_media_text; | 609 | sub = which->bd_media_text; |
612 | target_part.setSubtype(sub.lower()); | 610 | target_part.setSubtype(sub.lower()); |
613 | target_part.setLines(which->bd_lines); | 611 | target_part.setLines(which->bd_lines); |
614 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
615 | } | 613 | } |
616 | 614 | ||
617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 615 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
618 | { | 616 | { |
619 | if (!which) { | 617 | if (!which) { |
620 | return; | 618 | return; |
621 | } | 619 | } |
622 | // QString sub; | 620 | // QString sub; |
623 | // sub = which->bd_media_text; | 621 | // sub = which->bd_media_text; |
624 | // target_part.setSubtype(sub.lower()); | 622 | // target_part.setSubtype(sub.lower()); |
625 | qDebug("Message part"); | 623 | qDebug("Message part"); |
626 | /* we set this type to text/plain */ | 624 | /* we set this type to text/plain */ |
627 | target_part.setType("text"); | 625 | target_part.setType("text"); |
628 | target_part.setSubtype("plain"); | 626 | target_part.setSubtype("plain"); |
629 | target_part.setLines(which->bd_lines); | 627 | target_part.setLines(which->bd_lines); |
630 | fillBodyFields(target_part,which->bd_fields); | 628 | fillBodyFields(target_part,which->bd_fields); |
631 | } | 629 | } |
632 | 630 | ||
633 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 631 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
634 | { | 632 | { |
635 | if (!which) { | 633 | if (!which) { |
636 | return; | 634 | return; |
637 | } | 635 | } |
638 | QString type,sub; | 636 | QString type,sub; |
639 | switch (which->bd_media_basic->med_type) { | 637 | switch (which->bd_media_basic->med_type) { |
640 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 638 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
641 | type = "application"; | 639 | type = "application"; |
642 | break; | 640 | break; |
643 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 641 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
644 | type = "audio"; | 642 | type = "audio"; |
645 | break; | 643 | break; |
646 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 644 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
647 | type = "image"; | 645 | type = "image"; |
648 | break; | 646 | break; |
649 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 647 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
650 | type = "message"; | 648 | type = "message"; |
651 | break; | 649 | break; |
652 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 650 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
653 | type = "video"; | 651 | type = "video"; |
654 | break; | 652 | break; |
655 | case MAILIMAP_MEDIA_BASIC_OTHER: | 653 | case MAILIMAP_MEDIA_BASIC_OTHER: |
656 | default: | 654 | default: |
657 | if (which->bd_media_basic->med_basic_type) { | 655 | if (which->bd_media_basic->med_basic_type) { |
658 | type = which->bd_media_basic->med_basic_type; | 656 | type = which->bd_media_basic->med_basic_type; |
659 | } else { | 657 | } else { |
660 | type = ""; | 658 | type = ""; |
661 | } | 659 | } |
662 | break; | 660 | break; |
663 | } | 661 | } |
664 | if (which->bd_media_basic->med_subtype) { | 662 | if (which->bd_media_basic->med_subtype) { |
665 | sub = which->bd_media_basic->med_subtype; | 663 | sub = which->bd_media_basic->med_subtype; |
666 | } else { | 664 | } else { |
667 | sub = ""; | 665 | sub = ""; |
668 | } | 666 | } |
669 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 667 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
670 | target_part.setType(type.lower()); | 668 | target_part.setType(type.lower()); |
671 | target_part.setSubtype(sub.lower()); | 669 | target_part.setSubtype(sub.lower()); |
672 | fillBodyFields(target_part,which->bd_fields); | 670 | fillBodyFields(target_part,which->bd_fields); |
673 | } | 671 | } |
674 | 672 | ||
675 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 673 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
676 | { | 674 | { |
677 | if (!which) return; | 675 | if (!which) return; |
678 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 676 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
679 | clistcell*cur; | 677 | clistcell*cur; |
680 | mailimap_single_body_fld_param*param=0; | 678 | mailimap_single_body_fld_param*param=0; |
681 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 679 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
682 | param = (mailimap_single_body_fld_param*)cur->data; | 680 | param = (mailimap_single_body_fld_param*)cur->data; |
683 | if (param) { | 681 | if (param) { |
684 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 682 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
685 | } | 683 | } |
686 | } | 684 | } |
687 | } | 685 | } |
688 | mailimap_body_fld_enc*enc = which->bd_encoding; | 686 | mailimap_body_fld_enc*enc = which->bd_encoding; |
689 | QString encoding(""); | 687 | QString encoding(""); |
690 | switch (enc->enc_type) { | 688 | switch (enc->enc_type) { |
691 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 689 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
692 | encoding = "7bit"; | 690 | encoding = "7bit"; |
693 | break; | 691 | break; |
694 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 692 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
695 | encoding = "8bit"; | 693 | encoding = "8bit"; |
696 | break; | 694 | break; |
697 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 695 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
698 | encoding="binary"; | 696 | encoding="binary"; |
699 | break; | 697 | break; |
700 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 698 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
701 | encoding="base64"; | 699 | encoding="base64"; |
702 | break; | 700 | break; |
703 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 701 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
704 | encoding="quoted-printable"; | 702 | encoding="quoted-printable"; |
705 | break; | 703 | break; |
706 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 704 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
707 | default: | 705 | default: |
708 | if (enc->enc_value) { | 706 | if (enc->enc_value) { |
709 | char*t=enc->enc_value; | 707 | char*t=enc->enc_value; |
710 | encoding=QString(enc->enc_value); | 708 | encoding=QString(enc->enc_value); |
711 | enc->enc_value=0L; | 709 | enc->enc_value=0L; |
712 | free(t); | 710 | free(t); |
713 | } | 711 | } |
714 | } | 712 | } |
715 | if (which->bd_description) { | 713 | if (which->bd_description) { |
716 | target_part.setDescription(QString(which->bd_description)); | 714 | target_part.setDescription(QString(which->bd_description)); |
717 | } | 715 | } |
718 | target_part.setEncoding(encoding); | 716 | target_part.setEncoding(encoding); |
719 | target_part.setSize(which->bd_size); | 717 | target_part.setSize(which->bd_size); |
720 | } | 718 | } |
721 | 719 | ||
722 | void IMAPwrapper::deleteMail(const RecMail&mail) | 720 | void IMAPwrapper::deleteMail(const RecMail&mail) |
723 | { | 721 | { |
724 | mailimap_flag_list*flist; | 722 | mailimap_flag_list*flist; |
725 | mailimap_set *set; | 723 | mailimap_set *set; |
726 | mailimap_store_att_flags * store_flags; | 724 | mailimap_store_att_flags * store_flags; |
727 | int err; | 725 | int err; |
728 | login(); | 726 | login(); |
729 | if (!m_imap) { | 727 | if (!m_imap) { |
730 | return; | 728 | return; |
731 | } | 729 | } |
732 | const char *mb = mail.getMbox().latin1(); | 730 | const char *mb = mail.getMbox().latin1(); |
733 | err = mailimap_select( m_imap, (char*)mb); | 731 | err = mailimap_select( m_imap, (char*)mb); |
734 | if ( err != MAILIMAP_NO_ERROR ) { | 732 | if ( err != MAILIMAP_NO_ERROR ) { |
735 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 733 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
736 | return; | 734 | return; |
737 | } | 735 | } |
738 | flist = mailimap_flag_list_new_empty(); | 736 | flist = mailimap_flag_list_new_empty(); |
739 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 737 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
740 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 738 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
741 | set = mailimap_set_new_single(mail.getNumber()); | 739 | set = mailimap_set_new_single(mail.getNumber()); |
742 | err = mailimap_store(m_imap,set,store_flags); | 740 | err = mailimap_store(m_imap,set,store_flags); |
743 | mailimap_set_free( set ); | 741 | mailimap_set_free( set ); |
744 | mailimap_store_att_flags_free(store_flags); | 742 | mailimap_store_att_flags_free(store_flags); |
745 | 743 | ||
746 | if (err != MAILIMAP_NO_ERROR) { | 744 | if (err != MAILIMAP_NO_ERROR) { |
747 | qDebug("error deleting mail: %s",m_imap->imap_response); | 745 | qDebug("error deleting mail: %s",m_imap->imap_response); |
748 | return; | 746 | return; |
749 | } | 747 | } |
750 | qDebug("deleting mail: %s",m_imap->imap_response); | 748 | qDebug("deleting mail: %s",m_imap->imap_response); |
751 | /* should we realy do that at this moment? */ | 749 | /* should we realy do that at this moment? */ |
752 | err = mailimap_expunge(m_imap); | 750 | err = mailimap_expunge(m_imap); |
753 | if (err != MAILIMAP_NO_ERROR) { | 751 | if (err != MAILIMAP_NO_ERROR) { |
754 | qDebug("error deleting mail: %s",m_imap->imap_response); | 752 | qDebug("error deleting mail: %s",m_imap->imap_response); |
755 | } | 753 | } |
756 | qDebug("Delete successfull %s",m_imap->imap_response); | 754 | qDebug("Delete successfull %s",m_imap->imap_response); |
757 | } | 755 | } |
758 | 756 | ||
759 | void IMAPwrapper::answeredMail(const RecMail&mail) | 757 | void IMAPwrapper::answeredMail(const RecMail&mail) |
760 | { | 758 | { |
761 | mailimap_flag_list*flist; | 759 | mailimap_flag_list*flist; |
762 | mailimap_set *set; | 760 | mailimap_set *set; |
763 | mailimap_store_att_flags * store_flags; | 761 | mailimap_store_att_flags * store_flags; |
764 | int err; | 762 | int err; |
765 | login(); | 763 | login(); |
766 | if (!m_imap) { | 764 | if (!m_imap) { |
767 | return; | 765 | return; |
768 | } | 766 | } |
769 | const char *mb = mail.getMbox().latin1(); | 767 | const char *mb = mail.getMbox().latin1(); |
770 | err = mailimap_select( m_imap, (char*)mb); | 768 | err = mailimap_select( m_imap, (char*)mb); |
771 | if ( err != MAILIMAP_NO_ERROR ) { | 769 | if ( err != MAILIMAP_NO_ERROR ) { |
772 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 770 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
773 | return; | 771 | return; |
774 | } | 772 | } |
775 | flist = mailimap_flag_list_new_empty(); | 773 | flist = mailimap_flag_list_new_empty(); |
776 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 774 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
777 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 775 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
778 | set = mailimap_set_new_single(mail.getNumber()); | 776 | set = mailimap_set_new_single(mail.getNumber()); |
779 | err = mailimap_store(m_imap,set,store_flags); | 777 | err = mailimap_store(m_imap,set,store_flags); |
780 | mailimap_set_free( set ); | 778 | mailimap_set_free( set ); |
781 | mailimap_store_att_flags_free(store_flags); | 779 | mailimap_store_att_flags_free(store_flags); |
782 | 780 | ||
783 | if (err != MAILIMAP_NO_ERROR) { | 781 | if (err != MAILIMAP_NO_ERROR) { |
784 | qDebug("error marking mail: %s",m_imap->imap_response); | 782 | qDebug("error marking mail: %s",m_imap->imap_response); |
785 | return; | 783 | return; |
786 | } | 784 | } |
787 | } | 785 | } |
788 | 786 | ||
789 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 787 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
790 | { | 788 | { |
791 | QString body(""); | 789 | QString body(""); |
792 | encodedString*res = fetchRawPart(mail,path,internal_call); | 790 | encodedString*res = fetchRawPart(mail,path,internal_call); |
793 | encodedString*r = decode_String(res,enc); | 791 | encodedString*r = decode_String(res,enc); |
794 | delete res; | 792 | delete res; |
795 | if (r) { | 793 | if (r) { |
796 | if (r->Length()>0) { | 794 | if (r->Length()>0) { |
797 | body = r->Content(); | 795 | body = r->Content(); |
798 | } | 796 | } |
799 | delete r; | 797 | delete r; |
800 | } | 798 | } |
801 | return body; | 799 | return body; |
802 | } | 800 | } |
803 | 801 | ||
804 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 802 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
805 | { | 803 | { |
806 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 804 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
807 | } | 805 | } |
808 | 806 | ||
809 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 807 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
810 | { | 808 | { |
811 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 809 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
812 | encodedString*r = decode_String(res,part.Encoding()); | 810 | encodedString*r = decode_String(res,part.Encoding()); |
813 | delete res; | 811 | delete res; |
814 | return r; | 812 | return r; |
815 | } | 813 | } |
816 | 814 | ||
817 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 815 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
818 | { | 816 | { |
819 | return fetchRawPart(mail,part.Positionlist(),false); | 817 | return fetchRawPart(mail,part.Positionlist(),false); |
820 | } | 818 | } |
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 | |||
@@ -1,393 +1,393 @@ | |||
1 | #include "genericwrapper.h" | 1 | #include "genericwrapper.h" |
2 | #include <libetpan/mailmime.h> | 2 | #include <libetpan/mailmime.h> |
3 | #include <libetpan/data_message_driver.h> | 3 | #include <libetpan/data_message_driver.h> |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | Genericwrapper::Genericwrapper() | 6 | Genericwrapper::Genericwrapper() |
7 | : AbstractMail() | 7 | : AbstractMail() |
8 | { | 8 | { |
9 | bodyCache.clear(); | 9 | bodyCache.clear(); |
10 | } | 10 | } |
11 | 11 | ||
12 | Genericwrapper::~Genericwrapper() | 12 | Genericwrapper::~Genericwrapper() |
13 | { | 13 | { |
14 | cleanMimeCache(); | 14 | cleanMimeCache(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | 17 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) |
18 | { | 18 | { |
19 | if (!mime) { | 19 | if (!mime) { |
20 | return; | 20 | return; |
21 | } | 21 | } |
22 | mailmime_field*field = 0; | 22 | mailmime_field*field = 0; |
23 | mailmime_single_fields fields; | 23 | mailmime_single_fields fields; |
24 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 24 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
25 | if (mime->mm_mime_fields != NULL) { | 25 | if (mime->mm_mime_fields != NULL) { |
26 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 26 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
27 | mime->mm_content_type); | 27 | mime->mm_content_type); |
28 | } | 28 | } |
29 | 29 | ||
30 | mailmime_content*type = fields.fld_content; | 30 | mailmime_content*type = fields.fld_content; |
31 | clistcell*current; | 31 | clistcell*current; |
32 | if (!type) { | 32 | if (!type) { |
33 | target.setType("text"); | 33 | target.setType("text"); |
34 | target.setSubtype("plain"); | 34 | target.setSubtype("plain"); |
35 | } else { | 35 | } else { |
36 | target.setSubtype(type->ct_subtype); | 36 | target.setSubtype(type->ct_subtype); |
37 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 37 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
38 | case MAILMIME_DISCRETE_TYPE_TEXT: | 38 | case MAILMIME_DISCRETE_TYPE_TEXT: |
39 | target.setType("text"); | 39 | target.setType("text"); |
40 | break; | 40 | break; |
41 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 41 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
42 | target.setType("image"); | 42 | target.setType("image"); |
43 | break; | 43 | break; |
44 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 44 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
45 | target.setType("audio"); | 45 | target.setType("audio"); |
46 | break; | 46 | break; |
47 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 47 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
48 | target.setType("video"); | 48 | target.setType("video"); |
49 | break; | 49 | break; |
50 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 50 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
51 | target.setType("application"); | 51 | target.setType("application"); |
52 | break; | 52 | break; |
53 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 53 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
54 | default: | 54 | default: |
55 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 55 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
56 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 56 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
57 | } | 57 | } |
58 | break; | 58 | break; |
59 | } | 59 | } |
60 | if (type->ct_parameters) { | 60 | if (type->ct_parameters) { |
61 | fillParameters(target,type->ct_parameters); | 61 | fillParameters(target,type->ct_parameters); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 64 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
65 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 65 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
66 | field = (mailmime_field*)current->data; | 66 | field = (mailmime_field*)current->data; |
67 | switch(field->fld_type) { | 67 | switch(field->fld_type) { |
68 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 68 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
69 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | 69 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); |
70 | break; | 70 | break; |
71 | case MAILMIME_FIELD_ID: | 71 | case MAILMIME_FIELD_ID: |
72 | target.setIdentifier(field->fld_data.fld_id); | 72 | target.setIdentifier(field->fld_data.fld_id); |
73 | break; | 73 | break; |
74 | case MAILMIME_FIELD_DESCRIPTION: | 74 | case MAILMIME_FIELD_DESCRIPTION: |
75 | target.setDescription(field->fld_data.fld_description); | 75 | target.setDescription(field->fld_data.fld_description); |
76 | break; | 76 | break; |
77 | default: | 77 | default: |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) | 84 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) |
85 | { | 85 | { |
86 | if (!parameters) {return;} | 86 | if (!parameters) {return;} |
87 | clistcell*current=0; | 87 | clistcell*current=0; |
88 | mailmime_parameter*param; | 88 | mailmime_parameter*param; |
89 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 89 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
90 | param = (mailmime_parameter*)current->data; | 90 | param = (mailmime_parameter*)current->data; |
91 | if (param) { | 91 | if (param) { |
92 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 92 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 97 | 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: |
293 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 293 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
294 | break; | 294 | break; |
295 | case MAILIMF_ADDRESS_GROUP: | 295 | case MAILIMF_ADDRESS_GROUP: |
296 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 296 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
297 | break; | 297 | break; |
298 | default: | 298 | default: |
299 | qDebug( "Generic: unkown mailimf address type" ); | 299 | qDebug( "Generic: unkown mailimf address type" ); |
300 | break; | 300 | break; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | return result; | 304 | return result; |
305 | } | 305 | } |
306 | 306 | ||
307 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 307 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
308 | { | 308 | { |
309 | QString result( "" ); | 309 | QString result( "" ); |
310 | 310 | ||
311 | result.append( group->grp_display_name ); | 311 | result.append( group->grp_display_name ); |
312 | result.append( ": " ); | 312 | result.append( ": " ); |
313 | 313 | ||
314 | if ( group->grp_mb_list != NULL ) { | 314 | if ( group->grp_mb_list != NULL ) { |
315 | result.append( parseMailboxList( group->grp_mb_list ) ); | 315 | result.append( parseMailboxList( group->grp_mb_list ) ); |
316 | } | 316 | } |
317 | 317 | ||
318 | result.append( ";" ); | 318 | result.append( ";" ); |
319 | 319 | ||
320 | return result; | 320 | return result; |
321 | } | 321 | } |
322 | 322 | ||
323 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 323 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
324 | { | 324 | { |
325 | QString result( "" ); | 325 | QString result( "" ); |
326 | 326 | ||
327 | if ( box->mb_display_name == NULL ) { | 327 | if ( box->mb_display_name == NULL ) { |
328 | result.append( box->mb_addr_spec ); | 328 | result.append( box->mb_addr_spec ); |
329 | } else { | 329 | } else { |
330 | result.append( convert_String(box->mb_display_name).latin1() ); | 330 | result.append( convert_String(box->mb_display_name).latin1() ); |
331 | result.append( " <" ); | 331 | result.append( " <" ); |
332 | result.append( box->mb_addr_spec ); | 332 | result.append( box->mb_addr_spec ); |
333 | result.append( ">" ); | 333 | result.append( ">" ); |
334 | } | 334 | } |
335 | 335 | ||
336 | return result; | 336 | return result; |
337 | } | 337 | } |
338 | 338 | ||
339 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 339 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
340 | { | 340 | { |
341 | QString result( "" ); | 341 | QString result( "" ); |
342 | 342 | ||
343 | bool first = true; | 343 | bool first = true; |
344 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 344 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
345 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 345 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
346 | 346 | ||
347 | if ( !first ) { | 347 | if ( !first ) { |
348 | result.append( "," ); | 348 | result.append( "," ); |
349 | } else { | 349 | } else { |
350 | first = false; | 350 | first = false; |
351 | } | 351 | } |
352 | 352 | ||
353 | result.append( parseMailbox( box ) ); | 353 | result.append( parseMailbox( box ) ); |
354 | } | 354 | } |
355 | 355 | ||
356 | return result; | 356 | return result; |
357 | } | 357 | } |
358 | 358 | ||
359 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) | 359 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
360 | { | 360 | { |
361 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 361 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
362 | if (it==bodyCache.end()) return new encodedString(); | 362 | if (it==bodyCache.end()) return new encodedString(); |
363 | encodedString*t = decode_String(it.data(),part.Encoding()); | 363 | encodedString*t = decode_String(it.data(),part.Encoding()); |
364 | return t; | 364 | return t; |
365 | } | 365 | } |
366 | 366 | ||
367 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 367 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
368 | { | 368 | { |
369 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 369 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
370 | if (it==bodyCache.end()) return new encodedString(); | 370 | if (it==bodyCache.end()) return new encodedString(); |
371 | encodedString*t = it.data(); | 371 | encodedString*t = it.data(); |
372 | return t; | 372 | return t; |
373 | } | 373 | } |
374 | 374 | ||
375 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 375 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
376 | { | 376 | { |
377 | encodedString*t = fetchDecodedPart(mail,part); | 377 | encodedString*t = fetchDecodedPart(mail,part); |
378 | QString text=t->Content(); | 378 | QString text=t->Content(); |
379 | delete t; | 379 | delete t; |
380 | return text; | 380 | return text; |
381 | } | 381 | } |
382 | 382 | ||
383 | void Genericwrapper::cleanMimeCache() | 383 | void Genericwrapper::cleanMimeCache() |
384 | { | 384 | { |
385 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 385 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
386 | for (;it!=bodyCache.end();++it) { | 386 | for (;it!=bodyCache.end();++it) { |
387 | encodedString*t = it.data(); | 387 | encodedString*t = it.data(); |
388 | //it.setValue(0); | 388 | //it.setValue(0); |
389 | if (t) delete t; | 389 | if (t) delete t; |
390 | } | 390 | } |
391 | bodyCache.clear(); | 391 | bodyCache.clear(); |
392 | qDebug("Genericwrapper: cache cleaned"); | 392 | qDebug("Genericwrapper: cache cleaned"); |
393 | } | 393 | } |
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,820 +1,818 @@ | |||
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; |
254 | size = 0; | 252 | size = 0; |
255 | item = (mailimap_msg_att_item*)current->data; | 253 | item = (mailimap_msg_att_item*)current->data; |
256 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 254 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
257 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 255 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
258 | if (!flist->att_list) { | 256 | if (!flist->att_list) { |
259 | continue; | 257 | continue; |
260 | } | 258 | } |
261 | cf = flist->att_list->first; | 259 | cf = flist->att_list->first; |
262 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 260 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
263 | cflag = (mailimap_flag_fetch*)cf->data; | 261 | cflag = (mailimap_flag_fetch*)cf->data; |
264 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 262 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
265 | switch (cflag->fl_flag->fl_type) { | 263 | switch (cflag->fl_flag->fl_type) { |
266 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 264 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
267 | mFlags.setBit(FLAG_ANSWERED); | 265 | mFlags.setBit(FLAG_ANSWERED); |
268 | break; | 266 | break; |
269 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 267 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
270 | mFlags.setBit(FLAG_FLAGGED); | 268 | mFlags.setBit(FLAG_FLAGGED); |
271 | break; | 269 | break; |
272 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 270 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
273 | mFlags.setBit(FLAG_DELETED); | 271 | mFlags.setBit(FLAG_DELETED); |
274 | break; | 272 | break; |
275 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 273 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
276 | mFlags.setBit(FLAG_SEEN); | 274 | mFlags.setBit(FLAG_SEEN); |
277 | break; | 275 | break; |
278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 276 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
279 | mFlags.setBit(FLAG_DRAFT); | 277 | mFlags.setBit(FLAG_DRAFT); |
280 | break; | 278 | break; |
281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 279 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
282 | break; | 280 | break; |
283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 281 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
284 | break; | 282 | break; |
285 | default: | 283 | default: |
286 | break; | 284 | break; |
287 | } | 285 | } |
288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 286 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
289 | mFlags.setBit(FLAG_RECENT); | 287 | mFlags.setBit(FLAG_RECENT); |
290 | } | 288 | } |
291 | } | 289 | } |
292 | continue; | 290 | continue; |
293 | } | 291 | } |
294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 292 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 293 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
296 | m->setDate(head->env_date); | 294 | m->setDate(head->env_date); |
297 | m->setSubject(convert_String((const char*)head->env_subject)); | 295 | m->setSubject(convert_String((const char*)head->env_subject)); |
298 | //m->setSubject(head->env_subject); | 296 | //m->setSubject(head->env_subject); |
299 | if (head->env_from!=NULL) { | 297 | if (head->env_from!=NULL) { |
300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 298 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
301 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
302 | m->setFrom(addresslist.first()); | 300 | m->setFrom(addresslist.first()); |
303 | } | 301 | } |
304 | } | 302 | } |
305 | if (head->env_to!=NULL) { | 303 | if (head->env_to!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 304 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
307 | m->setTo(addresslist); | 305 | m->setTo(addresslist); |
308 | } | 306 | } |
309 | if (head->env_cc!=NULL) { | 307 | if (head->env_cc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 308 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
311 | m->setCC(addresslist); | 309 | m->setCC(addresslist); |
312 | } | 310 | } |
313 | if (head->env_bcc!=NULL) { | 311 | if (head->env_bcc!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 312 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
315 | m->setBcc(addresslist); | 313 | m->setBcc(addresslist); |
316 | } | 314 | } |
317 | if (head->env_reply_to!=NULL) { | 315 | if (head->env_reply_to!=NULL) { |
318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 316 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
319 | if (addresslist.count()) { | 317 | if (addresslist.count()) { |
320 | m->setReplyto(addresslist.first()); | 318 | m->setReplyto(addresslist.first()); |
321 | } | 319 | } |
322 | } | 320 | } |
323 | m->setMsgid(QString(head->env_message_id)); | 321 | m->setMsgid(QString(head->env_message_id)); |
324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 322 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
325 | #if 0 | 323 | #if 0 |
326 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 324 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
327 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 325 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
328 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 326 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
329 | qDebug(da.toString()); | 327 | qDebug(da.toString()); |
330 | #endif | 328 | #endif |
331 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 329 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
332 | size = item->att_data.att_static->att_data.att_rfc822_size; | 330 | size = item->att_data.att_static->att_data.att_rfc822_size; |
333 | } | 331 | } |
334 | } | 332 | } |
335 | /* msg is already deleted */ | 333 | /* msg is already deleted */ |
336 | if (mFlags.testBit(FLAG_DELETED) && m) { | 334 | if (mFlags.testBit(FLAG_DELETED) && m) { |
337 | delete m; | 335 | delete m; |
338 | m = 0; | 336 | m = 0; |
339 | } | 337 | } |
340 | if (m) { | 338 | if (m) { |
341 | m->setFlags(mFlags); | 339 | m->setFlags(mFlags); |
342 | m->setMsgsize(size); | 340 | m->setMsgsize(size); |
343 | } | 341 | } |
344 | return m; | 342 | return m; |
345 | } | 343 | } |
346 | 344 | ||
347 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 345 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
348 | { | 346 | { |
349 | RecBody body; | 347 | RecBody body; |
350 | const char *mb; | 348 | const char *mb; |
351 | int err = MAILIMAP_NO_ERROR; | 349 | int err = MAILIMAP_NO_ERROR; |
352 | clist *result; | 350 | clist *result; |
353 | clistcell *current; | 351 | clistcell *current; |
354 | mailimap_fetch_att *fetchAtt; | 352 | mailimap_fetch_att *fetchAtt; |
355 | mailimap_fetch_type *fetchType; | 353 | mailimap_fetch_type *fetchType; |
356 | mailimap_set *set; | 354 | mailimap_set *set; |
357 | mailimap_body*body_desc; | 355 | mailimap_body*body_desc; |
358 | 356 | ||
359 | mb = mail.getMbox().latin1(); | 357 | mb = mail.getMbox().latin1(); |
360 | 358 | ||
361 | login(); | 359 | login(); |
362 | if (!m_imap) { | 360 | if (!m_imap) { |
363 | return body; | 361 | return body; |
364 | } | 362 | } |
365 | 363 | ||
366 | err = mailimap_select( m_imap, (char*)mb); | 364 | err = mailimap_select( m_imap, (char*)mb); |
367 | if ( err != MAILIMAP_NO_ERROR ) { | 365 | if ( err != MAILIMAP_NO_ERROR ) { |
368 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 366 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
369 | return body; | 367 | return body; |
370 | } | 368 | } |
371 | 369 | ||
372 | result = clist_new(); | 370 | result = clist_new(); |
373 | /* the range has to start at 1!!! not with 0!!!! */ | 371 | /* the range has to start at 1!!! not with 0!!!! */ |
374 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 372 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
375 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 373 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
376 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 374 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
377 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 375 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
378 | mailimap_set_free( set ); | 376 | mailimap_set_free( set ); |
379 | mailimap_fetch_type_free( fetchType ); | 377 | mailimap_fetch_type_free( fetchType ); |
380 | 378 | ||
381 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 379 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
382 | mailimap_msg_att * msg_att; | 380 | mailimap_msg_att * msg_att; |
383 | msg_att = (mailimap_msg_att*)current->data; | 381 | msg_att = (mailimap_msg_att*)current->data; |
384 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 382 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
385 | body_desc = item->att_data.att_static->att_data.att_body; | 383 | body_desc = item->att_data.att_static->att_data.att_body; |
386 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 384 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
387 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 385 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
388 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 386 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
389 | qDebug("Mulitpart mail"); | 387 | qDebug("Mulitpart mail"); |
390 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 388 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
391 | } | 389 | } |
392 | } else { | 390 | } else { |
393 | qDebug("error fetching body: %s",m_imap->imap_response); | 391 | qDebug("error fetching body: %s",m_imap->imap_response); |
394 | } | 392 | } |
395 | mailimap_fetch_list_free(result); | 393 | mailimap_fetch_list_free(result); |
396 | return body; | 394 | return body; |
397 | } | 395 | } |
398 | 396 | ||
399 | /* this routine is just called when the mail has only ONE part. | 397 | /* this routine is just called when the mail has only ONE part. |
400 | for filling the parts of a multi-part-message there are other | 398 | for filling the parts of a multi-part-message there are other |
401 | routines 'cause we can not simply fetch the whole body. */ | 399 | routines 'cause we can not simply fetch the whole body. */ |
402 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 400 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
403 | { | 401 | { |
404 | if (!mailDescription) { | 402 | if (!mailDescription) { |
405 | return; | 403 | return; |
406 | } | 404 | } |
407 | QString sub,body_text; | 405 | QString sub,body_text; |
408 | RecPart singlePart; | 406 | RecPart singlePart; |
409 | QValueList<int> path; | 407 | QValueList<int> path; |
410 | fillSinglePart(singlePart,mailDescription); | 408 | fillSinglePart(singlePart,mailDescription); |
411 | switch (mailDescription->bd_type) { | 409 | switch (mailDescription->bd_type) { |
412 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 410 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
413 | path.append(1); | 411 | path.append(1); |
414 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 412 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
415 | target_body.setBodytext(body_text); | 413 | target_body.setBodytext(body_text); |
416 | target_body.setDescription(singlePart); | 414 | target_body.setDescription(singlePart); |
417 | break; | 415 | break; |
418 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 416 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
419 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 417 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
420 | path.append(1); | 418 | path.append(1); |
421 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 419 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
422 | target_body.setBodytext(body_text); | 420 | target_body.setBodytext(body_text); |
423 | target_body.setDescription(singlePart); | 421 | target_body.setDescription(singlePart); |
424 | break; | 422 | break; |
425 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 423 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
426 | qDebug("Single attachment"); | 424 | qDebug("Single attachment"); |
427 | target_body.setBodytext(""); | 425 | target_body.setBodytext(""); |
428 | target_body.addPart(singlePart); | 426 | target_body.addPart(singlePart); |
429 | break; | 427 | break; |
430 | default: | 428 | default: |
431 | break; | 429 | break; |
432 | } | 430 | } |
433 | 431 | ||
434 | return; | 432 | return; |
435 | } | 433 | } |
436 | 434 | ||
437 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 435 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
438 | { | 436 | { |
439 | QStringList l; | 437 | QStringList l; |
440 | QString from; | 438 | QString from; |
441 | bool named_from; | 439 | bool named_from; |
442 | clistcell *current = NULL; | 440 | clistcell *current = NULL; |
443 | mailimap_address * current_address=NULL; | 441 | mailimap_address * current_address=NULL; |
444 | if (!list) { | 442 | if (!list) { |
445 | return l; | 443 | return l; |
446 | } | 444 | } |
447 | unsigned int count = 0; | 445 | unsigned int count = 0; |
448 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 446 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
449 | from = ""; | 447 | from = ""; |
450 | named_from = false; | 448 | named_from = false; |
451 | current_address=(mailimap_address*)current->data; | 449 | current_address=(mailimap_address*)current->data; |
452 | if (current_address->ad_personal_name){ | 450 | if (current_address->ad_personal_name){ |
453 | from+=convert_String((const char*)current_address->ad_personal_name); | 451 | from+=convert_String((const char*)current_address->ad_personal_name); |
454 | //from+=QString(current_address->ad_personal_name); | 452 | //from+=QString(current_address->ad_personal_name); |
455 | from+=" "; | 453 | from+=" "; |
456 | named_from = true; | 454 | named_from = true; |
457 | } | 455 | } |
458 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 456 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
459 | from+="<"; | 457 | from+="<"; |
460 | } | 458 | } |
461 | if (current_address->ad_mailbox_name) { | 459 | if (current_address->ad_mailbox_name) { |
462 | from+=QString(current_address->ad_mailbox_name); | 460 | from+=QString(current_address->ad_mailbox_name); |
463 | from+="@"; | 461 | from+="@"; |
464 | } | 462 | } |
465 | if (current_address->ad_host_name) { | 463 | if (current_address->ad_host_name) { |
466 | from+=QString(current_address->ad_host_name); | 464 | from+=QString(current_address->ad_host_name); |
467 | } | 465 | } |
468 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 466 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
469 | from+=">"; | 467 | from+=">"; |
470 | } | 468 | } |
471 | l.append(QString(from)); | 469 | l.append(QString(from)); |
472 | if (++count > 99) { | 470 | if (++count > 99) { |
473 | break; | 471 | break; |
474 | } | 472 | } |
475 | } | 473 | } |
476 | return l; | 474 | return l; |
477 | } | 475 | } |
478 | 476 | ||
479 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 477 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
480 | { | 478 | { |
481 | encodedString*res=new encodedString; | 479 | encodedString*res=new encodedString; |
482 | const char*mb; | 480 | const char*mb; |
483 | int err; | 481 | int err; |
484 | mailimap_fetch_type *fetchType; | 482 | mailimap_fetch_type *fetchType; |
485 | mailimap_set *set; | 483 | mailimap_set *set; |
486 | clistcell*current,*cur; | 484 | clistcell*current,*cur; |
487 | 485 | ||
488 | login(); | 486 | login(); |
489 | if (!m_imap) { | 487 | if (!m_imap) { |
490 | return res; | 488 | return res; |
491 | } | 489 | } |
492 | if (!internal_call) { | 490 | if (!internal_call) { |
493 | mb = mail.getMbox().latin1(); | 491 | mb = mail.getMbox().latin1(); |
494 | err = mailimap_select( m_imap, (char*)mb); | 492 | err = mailimap_select( m_imap, (char*)mb); |
495 | if ( err != MAILIMAP_NO_ERROR ) { | 493 | if ( err != MAILIMAP_NO_ERROR ) { |
496 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 494 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
497 | return res; | 495 | return res; |
498 | } | 496 | } |
499 | } | 497 | } |
500 | set = mailimap_set_new_single(mail.getNumber()); | 498 | set = mailimap_set_new_single(mail.getNumber()); |
501 | clist*id_list=clist_new(); | 499 | clist*id_list=clist_new(); |
502 | for (unsigned j=0; j < path.count();++j) { | 500 | for (unsigned j=0; j < path.count();++j) { |
503 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 501 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
504 | *p_id = path[j]; | 502 | *p_id = path[j]; |
505 | clist_append(id_list,p_id); | 503 | clist_append(id_list,p_id); |
506 | } | 504 | } |
507 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 505 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 506 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
509 | mailimap_section * section = mailimap_section_new(section_spec); | 507 | mailimap_section * section = mailimap_section_new(section_spec); |
510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 508 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
511 | 509 | ||
512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 510 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
513 | 511 | ||
514 | clist*result = clist_new(); | 512 | clist*result = clist_new(); |
515 | 513 | ||
516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 514 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
517 | mailimap_set_free( set ); | 515 | mailimap_set_free( set ); |
518 | mailimap_fetch_type_free( fetchType ); | 516 | mailimap_fetch_type_free( fetchType ); |
519 | 517 | ||
520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 518 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
521 | mailimap_msg_att * msg_att; | 519 | mailimap_msg_att * msg_att; |
522 | msg_att = (mailimap_msg_att*)current->data; | 520 | msg_att = (mailimap_msg_att*)current->data; |
523 | mailimap_msg_att_item*msg_att_item; | 521 | mailimap_msg_att_item*msg_att_item; |
524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 522 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 523 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 524 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 525 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 526 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
529 | /* detach - we take over the content */ | 527 | /* detach - we take over the content */ |
530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 528 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 529 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
532 | } | 530 | } |
533 | } | 531 | } |
534 | } | 532 | } |
535 | } else { | 533 | } else { |
536 | qDebug("error fetching text: %s",m_imap->imap_response); | 534 | qDebug("error fetching text: %s",m_imap->imap_response); |
537 | } | 535 | } |
538 | mailimap_fetch_list_free(result); | 536 | mailimap_fetch_list_free(result); |
539 | return res; | 537 | return res; |
540 | } | 538 | } |
541 | 539 | ||
542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 540 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
543 | { | 541 | { |
544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 542 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
545 | if (!mailDescription||current_recursion==10) { | 543 | if (!mailDescription||current_recursion==10) { |
546 | return; | 544 | return; |
547 | } | 545 | } |
548 | clistcell*current; | 546 | clistcell*current; |
549 | mailimap_body*current_body; | 547 | mailimap_body*current_body; |
550 | unsigned int count = 0; | 548 | unsigned int count = 0; |
551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 549 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
552 | /* the point in the message */ | 550 | /* the point in the message */ |
553 | ++count; | 551 | ++count; |
554 | current_body = (mailimap_body*)current->data; | 552 | current_body = (mailimap_body*)current->data; |
555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 553 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
556 | QValueList<int>countlist = recList; | 554 | QValueList<int>countlist = recList; |
557 | countlist.append(count); | 555 | countlist.append(count); |
558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 556 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 557 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
560 | RecPart currentPart; | 558 | RecPart currentPart; |
561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 559 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
562 | QValueList<int>countlist = recList; | 560 | QValueList<int>countlist = recList; |
563 | countlist.append(count); | 561 | countlist.append(count); |
564 | /* important: Check for is NULL 'cause a body can be empty! */ | 562 | /* important: Check for is NULL 'cause a body can be empty! */ |
565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 563 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 564 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
567 | target_body.setDescription(currentPart); | 565 | target_body.setDescription(currentPart); |
568 | target_body.setBodytext(body_text); | 566 | target_body.setBodytext(body_text); |
569 | } else { | 567 | } else { |
570 | QString id(""); | 568 | QString id(""); |
571 | for (unsigned int j = 0; j < countlist.count();++j) { | 569 | for (unsigned int j = 0; j < countlist.count();++j) { |
572 | id+=(j>0?" ":""); | 570 | id+=(j>0?" ":""); |
573 | id+=QString("%1").arg(countlist[j]); | 571 | id+=QString("%1").arg(countlist[j]); |
574 | } | 572 | } |
575 | qDebug("ID= %s",id.latin1()); | 573 | qDebug("ID= %s",id.latin1()); |
576 | currentPart.setIdentifier(id); | 574 | currentPart.setIdentifier(id); |
577 | currentPart.setPositionlist(countlist); | 575 | currentPart.setPositionlist(countlist); |
578 | target_body.addPart(currentPart); | 576 | target_body.addPart(currentPart); |
579 | } | 577 | } |
580 | } | 578 | } |
581 | } | 579 | } |
582 | } | 580 | } |
583 | 581 | ||
584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 582 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
585 | { | 583 | { |
586 | if (!Description) { | 584 | if (!Description) { |
587 | return; | 585 | return; |
588 | } | 586 | } |
589 | switch (Description->bd_type) { | 587 | switch (Description->bd_type) { |
590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 588 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
591 | target_part.setType("text"); | 589 | target_part.setType("text"); |
592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 590 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
593 | break; | 591 | break; |
594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 592 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 593 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
596 | break; | 594 | break; |
597 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 595 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 596 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
599 | break; | 597 | break; |
600 | default: | 598 | default: |
601 | break; | 599 | break; |
602 | } | 600 | } |
603 | } | 601 | } |
604 | 602 | ||
605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 603 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
606 | { | 604 | { |
607 | if (!which) { | 605 | if (!which) { |
608 | return; | 606 | return; |
609 | } | 607 | } |
610 | QString sub; | 608 | QString sub; |
611 | sub = which->bd_media_text; | 609 | sub = which->bd_media_text; |
612 | target_part.setSubtype(sub.lower()); | 610 | target_part.setSubtype(sub.lower()); |
613 | target_part.setLines(which->bd_lines); | 611 | target_part.setLines(which->bd_lines); |
614 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
615 | } | 613 | } |
616 | 614 | ||
617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 615 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
618 | { | 616 | { |
619 | if (!which) { | 617 | if (!which) { |
620 | return; | 618 | return; |
621 | } | 619 | } |
622 | // QString sub; | 620 | // QString sub; |
623 | // sub = which->bd_media_text; | 621 | // sub = which->bd_media_text; |
624 | // target_part.setSubtype(sub.lower()); | 622 | // target_part.setSubtype(sub.lower()); |
625 | qDebug("Message part"); | 623 | qDebug("Message part"); |
626 | /* we set this type to text/plain */ | 624 | /* we set this type to text/plain */ |
627 | target_part.setType("text"); | 625 | target_part.setType("text"); |
628 | target_part.setSubtype("plain"); | 626 | target_part.setSubtype("plain"); |
629 | target_part.setLines(which->bd_lines); | 627 | target_part.setLines(which->bd_lines); |
630 | fillBodyFields(target_part,which->bd_fields); | 628 | fillBodyFields(target_part,which->bd_fields); |
631 | } | 629 | } |
632 | 630 | ||
633 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 631 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
634 | { | 632 | { |
635 | if (!which) { | 633 | if (!which) { |
636 | return; | 634 | return; |
637 | } | 635 | } |
638 | QString type,sub; | 636 | QString type,sub; |
639 | switch (which->bd_media_basic->med_type) { | 637 | switch (which->bd_media_basic->med_type) { |
640 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 638 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
641 | type = "application"; | 639 | type = "application"; |
642 | break; | 640 | break; |
643 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 641 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
644 | type = "audio"; | 642 | type = "audio"; |
645 | break; | 643 | break; |
646 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 644 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
647 | type = "image"; | 645 | type = "image"; |
648 | break; | 646 | break; |
649 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 647 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
650 | type = "message"; | 648 | type = "message"; |
651 | break; | 649 | break; |
652 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 650 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
653 | type = "video"; | 651 | type = "video"; |
654 | break; | 652 | break; |
655 | case MAILIMAP_MEDIA_BASIC_OTHER: | 653 | case MAILIMAP_MEDIA_BASIC_OTHER: |
656 | default: | 654 | default: |
657 | if (which->bd_media_basic->med_basic_type) { | 655 | if (which->bd_media_basic->med_basic_type) { |
658 | type = which->bd_media_basic->med_basic_type; | 656 | type = which->bd_media_basic->med_basic_type; |
659 | } else { | 657 | } else { |
660 | type = ""; | 658 | type = ""; |
661 | } | 659 | } |
662 | break; | 660 | break; |
663 | } | 661 | } |
664 | if (which->bd_media_basic->med_subtype) { | 662 | if (which->bd_media_basic->med_subtype) { |
665 | sub = which->bd_media_basic->med_subtype; | 663 | sub = which->bd_media_basic->med_subtype; |
666 | } else { | 664 | } else { |
667 | sub = ""; | 665 | sub = ""; |
668 | } | 666 | } |
669 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 667 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
670 | target_part.setType(type.lower()); | 668 | target_part.setType(type.lower()); |
671 | target_part.setSubtype(sub.lower()); | 669 | target_part.setSubtype(sub.lower()); |
672 | fillBodyFields(target_part,which->bd_fields); | 670 | fillBodyFields(target_part,which->bd_fields); |
673 | } | 671 | } |
674 | 672 | ||
675 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 673 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
676 | { | 674 | { |
677 | if (!which) return; | 675 | if (!which) return; |
678 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 676 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
679 | clistcell*cur; | 677 | clistcell*cur; |
680 | mailimap_single_body_fld_param*param=0; | 678 | mailimap_single_body_fld_param*param=0; |
681 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 679 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
682 | param = (mailimap_single_body_fld_param*)cur->data; | 680 | param = (mailimap_single_body_fld_param*)cur->data; |
683 | if (param) { | 681 | if (param) { |
684 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 682 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
685 | } | 683 | } |
686 | } | 684 | } |
687 | } | 685 | } |
688 | mailimap_body_fld_enc*enc = which->bd_encoding; | 686 | mailimap_body_fld_enc*enc = which->bd_encoding; |
689 | QString encoding(""); | 687 | QString encoding(""); |
690 | switch (enc->enc_type) { | 688 | switch (enc->enc_type) { |
691 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 689 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
692 | encoding = "7bit"; | 690 | encoding = "7bit"; |
693 | break; | 691 | break; |
694 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 692 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
695 | encoding = "8bit"; | 693 | encoding = "8bit"; |
696 | break; | 694 | break; |
697 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 695 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
698 | encoding="binary"; | 696 | encoding="binary"; |
699 | break; | 697 | break; |
700 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 698 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
701 | encoding="base64"; | 699 | encoding="base64"; |
702 | break; | 700 | break; |
703 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 701 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
704 | encoding="quoted-printable"; | 702 | encoding="quoted-printable"; |
705 | break; | 703 | break; |
706 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 704 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
707 | default: | 705 | default: |
708 | if (enc->enc_value) { | 706 | if (enc->enc_value) { |
709 | char*t=enc->enc_value; | 707 | char*t=enc->enc_value; |
710 | encoding=QString(enc->enc_value); | 708 | encoding=QString(enc->enc_value); |
711 | enc->enc_value=0L; | 709 | enc->enc_value=0L; |
712 | free(t); | 710 | free(t); |
713 | } | 711 | } |
714 | } | 712 | } |
715 | if (which->bd_description) { | 713 | if (which->bd_description) { |
716 | target_part.setDescription(QString(which->bd_description)); | 714 | target_part.setDescription(QString(which->bd_description)); |
717 | } | 715 | } |
718 | target_part.setEncoding(encoding); | 716 | target_part.setEncoding(encoding); |
719 | target_part.setSize(which->bd_size); | 717 | target_part.setSize(which->bd_size); |
720 | } | 718 | } |
721 | 719 | ||
722 | void IMAPwrapper::deleteMail(const RecMail&mail) | 720 | void IMAPwrapper::deleteMail(const RecMail&mail) |
723 | { | 721 | { |
724 | mailimap_flag_list*flist; | 722 | mailimap_flag_list*flist; |
725 | mailimap_set *set; | 723 | mailimap_set *set; |
726 | mailimap_store_att_flags * store_flags; | 724 | mailimap_store_att_flags * store_flags; |
727 | int err; | 725 | int err; |
728 | login(); | 726 | login(); |
729 | if (!m_imap) { | 727 | if (!m_imap) { |
730 | return; | 728 | return; |
731 | } | 729 | } |
732 | const char *mb = mail.getMbox().latin1(); | 730 | const char *mb = mail.getMbox().latin1(); |
733 | err = mailimap_select( m_imap, (char*)mb); | 731 | err = mailimap_select( m_imap, (char*)mb); |
734 | if ( err != MAILIMAP_NO_ERROR ) { | 732 | if ( err != MAILIMAP_NO_ERROR ) { |
735 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 733 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
736 | return; | 734 | return; |
737 | } | 735 | } |
738 | flist = mailimap_flag_list_new_empty(); | 736 | flist = mailimap_flag_list_new_empty(); |
739 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 737 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
740 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 738 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
741 | set = mailimap_set_new_single(mail.getNumber()); | 739 | set = mailimap_set_new_single(mail.getNumber()); |
742 | err = mailimap_store(m_imap,set,store_flags); | 740 | err = mailimap_store(m_imap,set,store_flags); |
743 | mailimap_set_free( set ); | 741 | mailimap_set_free( set ); |
744 | mailimap_store_att_flags_free(store_flags); | 742 | mailimap_store_att_flags_free(store_flags); |
745 | 743 | ||
746 | if (err != MAILIMAP_NO_ERROR) { | 744 | if (err != MAILIMAP_NO_ERROR) { |
747 | qDebug("error deleting mail: %s",m_imap->imap_response); | 745 | qDebug("error deleting mail: %s",m_imap->imap_response); |
748 | return; | 746 | return; |
749 | } | 747 | } |
750 | qDebug("deleting mail: %s",m_imap->imap_response); | 748 | qDebug("deleting mail: %s",m_imap->imap_response); |
751 | /* should we realy do that at this moment? */ | 749 | /* should we realy do that at this moment? */ |
752 | err = mailimap_expunge(m_imap); | 750 | err = mailimap_expunge(m_imap); |
753 | if (err != MAILIMAP_NO_ERROR) { | 751 | if (err != MAILIMAP_NO_ERROR) { |
754 | qDebug("error deleting mail: %s",m_imap->imap_response); | 752 | qDebug("error deleting mail: %s",m_imap->imap_response); |
755 | } | 753 | } |
756 | qDebug("Delete successfull %s",m_imap->imap_response); | 754 | qDebug("Delete successfull %s",m_imap->imap_response); |
757 | } | 755 | } |
758 | 756 | ||
759 | void IMAPwrapper::answeredMail(const RecMail&mail) | 757 | void IMAPwrapper::answeredMail(const RecMail&mail) |
760 | { | 758 | { |
761 | mailimap_flag_list*flist; | 759 | mailimap_flag_list*flist; |
762 | mailimap_set *set; | 760 | mailimap_set *set; |
763 | mailimap_store_att_flags * store_flags; | 761 | mailimap_store_att_flags * store_flags; |
764 | int err; | 762 | int err; |
765 | login(); | 763 | login(); |
766 | if (!m_imap) { | 764 | if (!m_imap) { |
767 | return; | 765 | return; |
768 | } | 766 | } |
769 | const char *mb = mail.getMbox().latin1(); | 767 | const char *mb = mail.getMbox().latin1(); |
770 | err = mailimap_select( m_imap, (char*)mb); | 768 | err = mailimap_select( m_imap, (char*)mb); |
771 | if ( err != MAILIMAP_NO_ERROR ) { | 769 | if ( err != MAILIMAP_NO_ERROR ) { |
772 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 770 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
773 | return; | 771 | return; |
774 | } | 772 | } |
775 | flist = mailimap_flag_list_new_empty(); | 773 | flist = mailimap_flag_list_new_empty(); |
776 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 774 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
777 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 775 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
778 | set = mailimap_set_new_single(mail.getNumber()); | 776 | set = mailimap_set_new_single(mail.getNumber()); |
779 | err = mailimap_store(m_imap,set,store_flags); | 777 | err = mailimap_store(m_imap,set,store_flags); |
780 | mailimap_set_free( set ); | 778 | mailimap_set_free( set ); |
781 | mailimap_store_att_flags_free(store_flags); | 779 | mailimap_store_att_flags_free(store_flags); |
782 | 780 | ||
783 | if (err != MAILIMAP_NO_ERROR) { | 781 | if (err != MAILIMAP_NO_ERROR) { |
784 | qDebug("error marking mail: %s",m_imap->imap_response); | 782 | qDebug("error marking mail: %s",m_imap->imap_response); |
785 | return; | 783 | return; |
786 | } | 784 | } |
787 | } | 785 | } |
788 | 786 | ||
789 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 787 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
790 | { | 788 | { |
791 | QString body(""); | 789 | QString body(""); |
792 | encodedString*res = fetchRawPart(mail,path,internal_call); | 790 | encodedString*res = fetchRawPart(mail,path,internal_call); |
793 | encodedString*r = decode_String(res,enc); | 791 | encodedString*r = decode_String(res,enc); |
794 | delete res; | 792 | delete res; |
795 | if (r) { | 793 | if (r) { |
796 | if (r->Length()>0) { | 794 | if (r->Length()>0) { |
797 | body = r->Content(); | 795 | body = r->Content(); |
798 | } | 796 | } |
799 | delete r; | 797 | delete r; |
800 | } | 798 | } |
801 | return body; | 799 | return body; |
802 | } | 800 | } |
803 | 801 | ||
804 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 802 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
805 | { | 803 | { |
806 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 804 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
807 | } | 805 | } |
808 | 806 | ||
809 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 807 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
810 | { | 808 | { |
811 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 809 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
812 | encodedString*r = decode_String(res,part.Encoding()); | 810 | encodedString*r = decode_String(res,part.Encoding()); |
813 | delete res; | 811 | delete res; |
814 | return r; | 812 | return r; |
815 | } | 813 | } |
816 | 814 | ||
817 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 815 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
818 | { | 816 | { |
819 | return fetchRawPart(mail,part.Positionlist(),false); | 817 | return fetchRawPart(mail,part.Positionlist(),false); |
820 | } | 818 | } |
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,285 +1,293 @@ | |||
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 | { |
202 | } | 210 | } |
203 | 211 | ||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 212 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
205 | { | 213 | { |
206 | QString p = MBOXPath+"/"; | 214 | QString p = MBOXPath+"/"; |
207 | p+=folder; | 215 | p+=folder; |
208 | mailmbox_folder*f = 0; | 216 | mailmbox_folder*f = 0; |
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 217 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
210 | if (r != MAIL_NO_ERROR) { | 218 | if (r != MAIL_NO_ERROR) { |
211 | qDebug("Error init folder"); | 219 | qDebug("Error init folder"); |
212 | return; | 220 | return; |
213 | } | 221 | } |
214 | r = mailmbox_append_message(f,msg,length); | 222 | r = mailmbox_append_message(f,msg,length); |
215 | if (r != MAIL_NO_ERROR) { | 223 | if (r != MAIL_NO_ERROR) { |
216 | qDebug("Error writing message folder"); | 224 | qDebug("Error writing message folder"); |
217 | } | 225 | } |
218 | mailmbox_done(f); | 226 | mailmbox_done(f); |
219 | } | 227 | } |
220 | 228 | ||
221 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | 229 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) |
222 | { | 230 | { |
223 | RecBody body; | 231 | RecBody body; |
224 | mailstorage*storage = mailstorage_new(NULL); | 232 | mailstorage*storage = mailstorage_new(NULL); |
225 | QString p = MBOXPath+"/"; | 233 | QString p = MBOXPath+"/"; |
226 | p+=mail.getMbox(); | 234 | p+=mail.getMbox(); |
227 | mailmessage * msg; | 235 | mailmessage * msg; |
228 | char*data=0; | 236 | char*data=0; |
229 | size_t size; | 237 | size_t size; |
230 | 238 | ||
231 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 239 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
232 | mailfolder*folder; | 240 | mailfolder*folder; |
233 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 241 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
234 | r = mailfolder_connect(folder); | 242 | r = mailfolder_connect(folder); |
235 | if (r != MAIL_NO_ERROR) { | 243 | if (r != MAIL_NO_ERROR) { |
236 | qDebug("Error initializing mbox"); | 244 | qDebug("Error initializing mbox"); |
237 | mailfolder_free(folder); | 245 | mailfolder_free(folder); |
238 | mailstorage_free(storage); | 246 | mailstorage_free(storage); |
239 | return; | 247 | return; |
240 | } | 248 | } |
241 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 249 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
242 | if (r != MAIL_NO_ERROR) { | 250 | if (r != MAIL_NO_ERROR) { |
243 | qDebug("Error fetching mail %i",mail.getNumber()); | 251 | qDebug("Error fetching mail %i",mail.getNumber()); |
244 | mailfolder_free(folder); | 252 | mailfolder_free(folder); |
245 | mailstorage_free(storage); | 253 | mailstorage_free(storage); |
246 | return; | 254 | return; |
247 | } | 255 | } |
248 | r = mailmessage_fetch(msg,&data,&size); | 256 | r = mailmessage_fetch(msg,&data,&size); |
249 | if (r != MAIL_NO_ERROR) { | 257 | if (r != MAIL_NO_ERROR) { |
250 | qDebug("Error fetching mail %i",mail.getNumber()); | 258 | qDebug("Error fetching mail %i",mail.getNumber()); |
251 | mailfolder_free(folder); | 259 | mailfolder_free(folder); |
252 | mailstorage_free(storage); | 260 | mailstorage_free(storage); |
253 | mailmessage_free(msg); | 261 | mailmessage_free(msg); |
254 | return; | 262 | return; |
255 | } | 263 | } |
256 | *target = data; | 264 | *target = data; |
257 | *length = size; | 265 | *length = size; |
258 | mailfolder_free(folder); | 266 | mailfolder_free(folder); |
259 | mailstorage_free(storage); | 267 | mailstorage_free(storage); |
260 | mailmessage_free(msg); | 268 | mailmessage_free(msg); |
261 | } | 269 | } |
262 | 270 | ||
263 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 271 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
264 | { | 272 | { |
265 | QString p = MBOXPath+"/"; | 273 | QString p = MBOXPath+"/"; |
266 | p+=mailbox; | 274 | p+=mailbox; |
267 | mailmbox_folder*f = 0; | 275 | mailmbox_folder*f = 0; |
268 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 276 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
269 | if (r != MAIL_NO_ERROR) { | 277 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("Error init folder"); | 278 | qDebug("Error init folder"); |
271 | return; | 279 | return; |
272 | } | 280 | } |
273 | for (unsigned int i=0; i < target.count();++i) { | 281 | for (unsigned int i=0; i < target.count();++i) { |
274 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 282 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
275 | if (r!=MAILMBOX_NO_ERROR) { | 283 | if (r!=MAILMBOX_NO_ERROR) { |
276 | qDebug("error delete mail"); | 284 | qDebug("error delete mail"); |
277 | } | 285 | } |
278 | } | 286 | } |
279 | r = mailmbox_expunge(f); | 287 | r = mailmbox_expunge(f); |
280 | if (r != MAILMBOX_NO_ERROR) { | 288 | if (r != MAILMBOX_NO_ERROR) { |
281 | qDebug("error expunge mailbox"); | 289 | qDebug("error expunge mailbox"); |
282 | } | 290 | } |
283 | mailmbox_done(f); | 291 | mailmbox_done(f); |
284 | } | 292 | } |
285 | 293 | ||
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 | |||
@@ -1,744 +1,757 @@ | |||
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 | #include <qt.h> | 8 | #include <qt.h> |
9 | 9 | ||
10 | #include <libetpan/libetpan.h> | 10 | #include <libetpan/libetpan.h> |
11 | 11 | ||
12 | #include "smtpwrapper.h" | 12 | #include "smtpwrapper.h" |
13 | #include "mailwrapper.h" | 13 | #include "mailwrapper.h" |
14 | #include "mboxwrapper.h" | 14 | #include "mboxwrapper.h" |
15 | #include "logindialog.h" | 15 | #include "logindialog.h" |
16 | #include "mailtypes.h" | 16 | #include "mailtypes.h" |
17 | #include "defines.h" | 17 | #include "defines.h" |
18 | #include "sendmailprogress.h" | 18 | #include "sendmailprogress.h" |
19 | 19 | ||
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 20 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 21 | ||
22 | SMTPwrapper::SMTPwrapper( Settings *s ) | 22 | SMTPwrapper::SMTPwrapper( Settings *s ) |
23 | : QObject() | 23 | : QObject() |
24 | { | 24 | { |
25 | settings = s; | 25 | settings = s; |
26 | } | 26 | } |
27 | 27 | ||
28 | QString SMTPwrapper::mailsmtpError( int errnum ) | 28 | QString SMTPwrapper::mailsmtpError( int errnum ) |
29 | { | 29 | { |
30 | switch ( errnum ) { | 30 | switch ( errnum ) { |
31 | case MAILSMTP_NO_ERROR: | 31 | case MAILSMTP_NO_ERROR: |
32 | return tr( "No error" ); | 32 | return tr( "No error" ); |
33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
34 | return tr( "Unexpected error code" ); | 34 | return tr( "Unexpected error code" ); |
35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
36 | return tr( "Service not available" ); | 36 | return tr( "Service not available" ); |
37 | case MAILSMTP_ERROR_STREAM: | 37 | case MAILSMTP_ERROR_STREAM: |
38 | return tr( "Stream error" ); | 38 | return tr( "Stream error" ); |
39 | case MAILSMTP_ERROR_HOSTNAME: | 39 | case MAILSMTP_ERROR_HOSTNAME: |
40 | return tr( "gethostname() failed" ); | 40 | return tr( "gethostname() failed" ); |
41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
42 | return tr( "Not implemented" ); | 42 | return tr( "Not implemented" ); |
43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
44 | return tr( "Error, action not taken" ); | 44 | return tr( "Error, action not taken" ); |
45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
46 | return tr( "Data exceeds storage allocation" ); | 46 | return tr( "Data exceeds storage allocation" ); |
47 | case MAILSMTP_ERROR_IN_PROCESSING: | 47 | case MAILSMTP_ERROR_IN_PROCESSING: |
48 | return tr( "Error in processing" ); | 48 | return tr( "Error in processing" ); |
49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
50 | // return tr( "Insufficient system storage" ); | 50 | // return tr( "Insufficient system storage" ); |
51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
52 | return tr( "Mailbox unavailable" ); | 52 | return tr( "Mailbox unavailable" ); |
53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
54 | return tr( "Mailbox name not allowed" ); | 54 | return tr( "Mailbox name not allowed" ); |
55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
56 | return tr( "Bad command sequence" ); | 56 | return tr( "Bad command sequence" ); |
57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
58 | return tr( "User not local" ); | 58 | return tr( "User not local" ); |
59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
60 | return tr( "Transaction failed" ); | 60 | return tr( "Transaction failed" ); |
61 | case MAILSMTP_ERROR_MEMORY: | 61 | case MAILSMTP_ERROR_MEMORY: |
62 | return tr( "Memory error" ); | 62 | return tr( "Memory error" ); |
63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
64 | return tr( "Connection refused" ); | 64 | return tr( "Connection refused" ); |
65 | default: | 65 | default: |
66 | return tr( "Unknown error code" ); | 66 | return tr( "Unknown error code" ); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
71 | { | 71 | { |
72 | return mailimf_mailbox_new( strdup( name.latin1() ), | 72 | return mailimf_mailbox_new( strdup( name.latin1() ), |
73 | strdup( mail.latin1() ) ); | 73 | strdup( mail.latin1() ) ); |
74 | } | 74 | } |
75 | 75 | ||
76 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 76 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
77 | { | 77 | { |
78 | mailimf_address_list *addresses; | 78 | mailimf_address_list *addresses; |
79 | 79 | ||
80 | if ( addr.isEmpty() ) return NULL; | 80 | if ( addr.isEmpty() ) return NULL; |
81 | 81 | ||
82 | addresses = mailimf_address_list_new_empty(); | 82 | addresses = mailimf_address_list_new_empty(); |
83 | 83 | ||
84 | QStringList list = QStringList::split( ',', addr ); | 84 | QStringList list = QStringList::split( ',', addr ); |
85 | QStringList::Iterator it; | 85 | QStringList::Iterator it; |
86 | for ( it = list.begin(); it != list.end(); it++ ) { | 86 | for ( it = list.begin(); it != list.end(); it++ ) { |
87 | char *str = strdup( (*it).latin1() ); | 87 | char *str = strdup( (*it).latin1() ); |
88 | int err = mailimf_address_list_add_parse( addresses, str ); | 88 | int err = mailimf_address_list_add_parse( addresses, str ); |
89 | if ( err != MAILIMF_NO_ERROR ) { | 89 | if ( err != MAILIMF_NO_ERROR ) { |
90 | qDebug( "Error parsing" ); | 90 | qDebug( "Error parsing" ); |
91 | qDebug( *it ); | 91 | qDebug( *it ); |
92 | free( str ); | 92 | free( str ); |
93 | } else { | 93 | } else { |
94 | qDebug( "Parse success! :)" ); | 94 | qDebug( "Parse success! :)" ); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | return addresses; | 98 | return addresses; |
99 | } | 99 | } |
100 | 100 | ||
101 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 101 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
102 | { | 102 | { |
103 | mailimf_fields *fields; | 103 | mailimf_fields *fields; |
104 | mailimf_field *xmailer; | 104 | mailimf_field *xmailer; |
105 | mailimf_mailbox *sender, *fromBox; | 105 | mailimf_mailbox *sender, *fromBox; |
106 | mailimf_mailbox_list *from; | 106 | mailimf_mailbox_list *from; |
107 | mailimf_address_list *to, *cc, *bcc, *reply; | 107 | mailimf_address_list *to, *cc, *bcc, *reply; |
108 | char *subject = strdup( mail.getSubject().latin1() ); | 108 | char *subject = strdup( mail.getSubject().latin1() ); |
109 | int err; | 109 | int err; |
110 | 110 | ||
111 | sender = newMailbox( mail.getName(), mail.getMail() ); | 111 | sender = newMailbox( mail.getName(), mail.getMail() ); |
112 | if ( sender == NULL ) goto err_free; | 112 | if ( sender == NULL ) goto err_free; |
113 | 113 | ||
114 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 114 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
115 | if ( fromBox == NULL ) goto err_free_sender; | 115 | if ( fromBox == NULL ) goto err_free_sender; |
116 | 116 | ||
117 | from = mailimf_mailbox_list_new_empty(); | 117 | from = mailimf_mailbox_list_new_empty(); |
118 | if ( from == NULL ) goto err_free_fromBox; | 118 | if ( from == NULL ) goto err_free_fromBox; |
119 | 119 | ||
120 | err = mailimf_mailbox_list_add( from, fromBox ); | 120 | err = mailimf_mailbox_list_add( from, fromBox ); |
121 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 121 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
122 | 122 | ||
123 | to = parseAddresses( mail.getTo() ); | 123 | to = parseAddresses( mail.getTo() ); |
124 | if ( to == NULL ) goto err_free_from; | 124 | if ( to == NULL ) goto err_free_from; |
125 | 125 | ||
126 | cc = parseAddresses( mail.getCC() ); | 126 | cc = parseAddresses( mail.getCC() ); |
127 | bcc = parseAddresses( mail.getBCC() ); | 127 | bcc = parseAddresses( mail.getBCC() ); |
128 | reply = parseAddresses( mail.getReply() ); | 128 | reply = parseAddresses( mail.getReply() ); |
129 | 129 | ||
130 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 130 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
131 | NULL, NULL, subject ); | 131 | NULL, NULL, subject ); |
132 | if ( fields == NULL ) goto err_free_reply; | 132 | if ( fields == NULL ) goto err_free_reply; |
133 | 133 | ||
134 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 134 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
135 | strdup( USER_AGENT ) ); | 135 | strdup( USER_AGENT ) ); |
136 | if ( xmailer == NULL ) goto err_free_fields; | 136 | if ( xmailer == NULL ) goto err_free_fields; |
137 | 137 | ||
138 | err = mailimf_fields_add( fields, xmailer ); | 138 | err = mailimf_fields_add( fields, xmailer ); |
139 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 139 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
140 | 140 | ||
141 | return fields; // Success :) | 141 | return fields; // Success :) |
142 | 142 | ||
143 | err_free_xmailer: | 143 | err_free_xmailer: |
144 | mailimf_field_free( xmailer ); | 144 | mailimf_field_free( xmailer ); |
145 | err_free_fields: | 145 | err_free_fields: |
146 | mailimf_fields_free( fields ); | 146 | mailimf_fields_free( fields ); |
147 | err_free_reply: | 147 | err_free_reply: |
148 | mailimf_address_list_free( reply ); | 148 | mailimf_address_list_free( reply ); |
149 | mailimf_address_list_free( bcc ); | 149 | mailimf_address_list_free( bcc ); |
150 | mailimf_address_list_free( cc ); | 150 | mailimf_address_list_free( cc ); |
151 | mailimf_address_list_free( to ); | 151 | mailimf_address_list_free( to ); |
152 | err_free_from: | 152 | err_free_from: |
153 | mailimf_mailbox_list_free( from ); | 153 | mailimf_mailbox_list_free( from ); |
154 | err_free_fromBox: | 154 | err_free_fromBox: |
155 | mailimf_mailbox_free( fromBox ); | 155 | mailimf_mailbox_free( fromBox ); |
156 | err_free_sender: | 156 | err_free_sender: |
157 | mailimf_mailbox_free( sender ); | 157 | mailimf_mailbox_free( sender ); |
158 | err_free: | 158 | err_free: |
159 | free( subject ); | 159 | free( subject ); |
160 | qDebug( "createImfFields - error" ); | 160 | qDebug( "createImfFields - error" ); |
161 | 161 | ||
162 | return NULL; // Error :( | 162 | return NULL; // Error :( |
163 | } | 163 | } |
164 | 164 | ||
165 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 165 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
166 | { | 166 | { |
167 | mailmime *txtPart; | 167 | mailmime *txtPart; |
168 | mailmime_fields *fields; | 168 | mailmime_fields *fields; |
169 | mailmime_content *content; | 169 | mailmime_content *content; |
170 | mailmime_parameter *param; | 170 | mailmime_parameter *param; |
171 | char *txt = strdup( str.latin1() ); | 171 | char *txt = strdup( str.latin1() ); |
172 | int err; | 172 | int err; |
173 | 173 | ||
174 | param = mailmime_parameter_new( strdup( "charset" ), | 174 | param = mailmime_parameter_new( strdup( "charset" ), |
175 | strdup( "iso-8859-1" ) ); | 175 | strdup( "iso-8859-1" ) ); |
176 | if ( param == NULL ) goto err_free; | 176 | if ( param == NULL ) goto err_free; |
177 | 177 | ||
178 | content = mailmime_content_new_with_str( "text/plain" ); | 178 | content = mailmime_content_new_with_str( "text/plain" ); |
179 | if ( content == NULL ) goto err_free_param; | 179 | if ( content == NULL ) goto err_free_param; |
180 | 180 | ||
181 | err = clist_append( content->ct_parameters, param ); | 181 | err = clist_append( content->ct_parameters, param ); |
182 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 182 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
183 | 183 | ||
184 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 184 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
185 | if ( fields == NULL ) goto err_free_content; | 185 | if ( fields == NULL ) goto err_free_content; |
186 | 186 | ||
187 | txtPart = mailmime_new_empty( content, fields ); | 187 | txtPart = mailmime_new_empty( content, fields ); |
188 | if ( txtPart == NULL ) goto err_free_fields; | 188 | if ( txtPart == NULL ) goto err_free_fields; |
189 | 189 | ||
190 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 190 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
191 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 191 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
192 | 192 | ||
193 | return txtPart; // Success :) | 193 | return txtPart; // Success :) |
194 | 194 | ||
195 | err_free_txtPart: | 195 | err_free_txtPart: |
196 | mailmime_free( txtPart ); | 196 | mailmime_free( txtPart ); |
197 | err_free_fields: | 197 | err_free_fields: |
198 | mailmime_fields_free( fields ); | 198 | mailmime_fields_free( fields ); |
199 | err_free_content: | 199 | err_free_content: |
200 | mailmime_content_free( content ); | 200 | mailmime_content_free( content ); |
201 | err_free_param: | 201 | err_free_param: |
202 | mailmime_parameter_free( param ); | 202 | mailmime_parameter_free( param ); |
203 | err_free: | 203 | err_free: |
204 | free( txt ); | 204 | free( txt ); |
205 | qDebug( "buildTxtPart - error" ); | 205 | qDebug( "buildTxtPart - error" ); |
206 | 206 | ||
207 | return NULL; // Error :( | 207 | return NULL; // Error :( |
208 | } | 208 | } |
209 | 209 | ||
210 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) | 210 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
211 | { | 211 | { |
212 | mailmime * filePart = 0; | 212 | mailmime * filePart = 0; |
213 | mailmime_fields * fields = 0; | 213 | mailmime_fields * fields = 0; |
214 | mailmime_content * content = 0; | 214 | mailmime_content * content = 0; |
215 | mailmime_parameter * param = 0; | 215 | mailmime_parameter * param = 0; |
216 | char*name = 0; | 216 | char*name = 0; |
217 | char*file = 0; | 217 | char*file = 0; |
218 | int err; | 218 | int err; |
219 | 219 | ||
220 | int pos = filename.findRev( '/' ); | 220 | int pos = filename.findRev( '/' ); |
221 | 221 | ||
222 | if (filename.length()>0) { | 222 | if (filename.length()>0) { |
223 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 223 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
224 | name = strdup( tmp.latin1() ); // just filename | 224 | name = strdup( tmp.latin1() ); // just filename |
225 | file = strdup( filename.latin1() ); // full name with path | 225 | file = strdup( filename.latin1() ); // full name with path |
226 | } | 226 | } |
227 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 227 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
228 | 228 | ||
229 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 229 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
230 | int mechanism = MAILMIME_MECHANISM_BASE64; | 230 | int mechanism = MAILMIME_MECHANISM_BASE64; |
231 | 231 | ||
232 | if ( mimetype.startsWith( "text/" ) ) { | 232 | if ( mimetype.startsWith( "text/" ) ) { |
233 | param = mailmime_parameter_new( strdup( "charset" ), | 233 | param = mailmime_parameter_new( strdup( "charset" ), |
234 | strdup( "iso-8859-1" ) ); | 234 | strdup( "iso-8859-1" ) ); |
235 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; | 235 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; |
236 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 236 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
237 | } | 237 | } |
238 | 238 | ||
239 | fields = mailmime_fields_new_filename( | 239 | fields = mailmime_fields_new_filename( |
240 | disptype, name, | 240 | disptype, name, |
241 | mechanism ); | 241 | mechanism ); |
242 | content = mailmime_content_new_with_str( mime ); | 242 | content = mailmime_content_new_with_str( mime ); |
243 | if (content!=0 && fields != 0) { | 243 | if (content!=0 && fields != 0) { |
244 | if (param) { | 244 | if (param) { |
245 | clist_append(content->ct_parameters,param); | 245 | clist_append(content->ct_parameters,param); |
246 | param = 0; | 246 | param = 0; |
247 | } | 247 | } |
248 | if (filename.length()>0) { | 248 | if (filename.length()>0) { |
249 | QFileInfo f(filename); | 249 | QFileInfo f(filename); |
250 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 250 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
251 | clist_append(content->ct_parameters,param); | 251 | clist_append(content->ct_parameters,param); |
252 | param = 0; | 252 | param = 0; |
253 | } | 253 | } |
254 | filePart = mailmime_new_empty( content, fields ); | 254 | filePart = mailmime_new_empty( content, fields ); |
255 | } | 255 | } |
256 | if (filePart) { | 256 | if (filePart) { |
257 | if (filename.length()>0) { | 257 | if (filename.length()>0) { |
258 | err = mailmime_set_body_file( filePart, file ); | 258 | err = mailmime_set_body_file( filePart, file ); |
259 | } else { | 259 | } else { |
260 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); | 260 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); |
261 | } | 261 | } |
262 | if (err != MAILIMF_NO_ERROR) { | 262 | if (err != MAILIMF_NO_ERROR) { |
263 | qDebug("Error setting body with file %s",file); | 263 | qDebug("Error setting body with file %s",file); |
264 | mailmime_free( filePart ); | 264 | mailmime_free( filePart ); |
265 | filePart = 0; | 265 | filePart = 0; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | if (!filePart) { | 269 | if (!filePart) { |
270 | if ( param != NULL ) { | 270 | if ( param != NULL ) { |
271 | mailmime_parameter_free( param ); | 271 | mailmime_parameter_free( param ); |
272 | } | 272 | } |
273 | if (content) { | 273 | if (content) { |
274 | mailmime_content_free( content ); | 274 | mailmime_content_free( content ); |
275 | } else { | 275 | } else { |
276 | if (mime) { | 276 | if (mime) { |
277 | free( mime ); | 277 | free( mime ); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | if (fields) { | 280 | if (fields) { |
281 | mailmime_fields_free( fields ); | 281 | mailmime_fields_free( fields ); |
282 | } else { | 282 | } else { |
283 | if (name) { | 283 | if (name) { |
284 | free( name ); | 284 | free( name ); |
285 | } | 285 | } |
286 | if (file) { | 286 | if (file) { |
287 | free( file ); | 287 | free( file ); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | } | 290 | } |
291 | return filePart; // Success :) | 291 | return filePart; // Success :) |
292 | 292 | ||
293 | } | 293 | } |
294 | 294 | ||
295 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 295 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
296 | { | 296 | { |
297 | const Attachment *it; | 297 | const Attachment *it; |
298 | unsigned int count = files.count(); | 298 | unsigned int count = files.count(); |
299 | qDebug("List contains %i values",count); | 299 | qDebug("List contains %i values",count); |
300 | for ( unsigned int i = 0; i < count; ++i ) { | 300 | for ( unsigned int i = 0; i < count; ++i ) { |
301 | qDebug( "Adding file" ); | 301 | qDebug( "Adding file" ); |
302 | mailmime *filePart; | 302 | mailmime *filePart; |
303 | int err; | 303 | int err; |
304 | it = ((QList<Attachment>)files).at(i); | 304 | it = ((QList<Attachment>)files).at(i); |
305 | 305 | ||
306 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 306 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
307 | if ( filePart == NULL ) { | 307 | if ( filePart == NULL ) { |
308 | qDebug( "addFileParts: error adding file:" ); | 308 | qDebug( "addFileParts: error adding file:" ); |
309 | qDebug( it->getFileName() ); | 309 | qDebug( it->getFileName() ); |
310 | continue; | 310 | continue; |
311 | } | 311 | } |
312 | err = mailmime_smart_add_part( message, filePart ); | 312 | err = mailmime_smart_add_part( message, filePart ); |
313 | if ( err != MAILIMF_NO_ERROR ) { | 313 | if ( err != MAILIMF_NO_ERROR ) { |
314 | mailmime_free( filePart ); | 314 | mailmime_free( filePart ); |
315 | qDebug("error smart add"); | 315 | qDebug("error smart add"); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | } | 318 | } |
319 | 319 | ||
320 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 320 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
321 | { | 321 | { |
322 | mailmime *message, *txtPart; | 322 | mailmime *message, *txtPart; |
323 | mailimf_fields *fields; | 323 | mailimf_fields *fields; |
324 | int err; | 324 | int err; |
325 | 325 | ||
326 | fields = createImfFields( mail ); | 326 | fields = createImfFields( mail ); |
327 | if ( fields == NULL ) goto err_free; | 327 | if ( fields == NULL ) goto err_free; |
328 | 328 | ||
329 | message = mailmime_new_message_data( NULL ); | 329 | message = mailmime_new_message_data( NULL ); |
330 | if ( message == NULL ) goto err_free_fields; | 330 | if ( message == NULL ) goto err_free_fields; |
331 | 331 | ||
332 | mailmime_set_imf_fields( message, fields ); | 332 | mailmime_set_imf_fields( message, fields ); |
333 | 333 | ||
334 | if (mail.getAttachments().count()==0) { | 334 | if (mail.getAttachments().count()==0) { |
335 | txtPart = buildTxtPart( mail.getMessage() ); | 335 | txtPart = buildTxtPart( mail.getMessage() ); |
336 | } else { | 336 | } else { |
337 | txtPart = buildFilePart("","text/plain",mail.getMessage()); | 337 | txtPart = buildFilePart("","text/plain",mail.getMessage()); |
338 | } | 338 | } |
339 | if ( txtPart == NULL ) goto err_free_message; | 339 | if ( txtPart == NULL ) goto err_free_message; |
340 | 340 | ||
341 | err = mailmime_smart_add_part( message, txtPart ); | 341 | err = mailmime_smart_add_part( message, txtPart ); |
342 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 342 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
343 | 343 | ||
344 | addFileParts( message, mail.getAttachments() ); | 344 | addFileParts( message, mail.getAttachments() ); |
345 | 345 | ||
346 | return message; // Success :) | 346 | return message; // Success :) |
347 | 347 | ||
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,285 +1,293 @@ | |||
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 | { |
202 | } | 210 | } |
203 | 211 | ||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 212 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
205 | { | 213 | { |
206 | QString p = MBOXPath+"/"; | 214 | QString p = MBOXPath+"/"; |
207 | p+=folder; | 215 | p+=folder; |
208 | mailmbox_folder*f = 0; | 216 | mailmbox_folder*f = 0; |
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 217 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
210 | if (r != MAIL_NO_ERROR) { | 218 | if (r != MAIL_NO_ERROR) { |
211 | qDebug("Error init folder"); | 219 | qDebug("Error init folder"); |
212 | return; | 220 | return; |
213 | } | 221 | } |
214 | r = mailmbox_append_message(f,msg,length); | 222 | r = mailmbox_append_message(f,msg,length); |
215 | if (r != MAIL_NO_ERROR) { | 223 | if (r != MAIL_NO_ERROR) { |
216 | qDebug("Error writing message folder"); | 224 | qDebug("Error writing message folder"); |
217 | } | 225 | } |
218 | mailmbox_done(f); | 226 | mailmbox_done(f); |
219 | } | 227 | } |
220 | 228 | ||
221 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | 229 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) |
222 | { | 230 | { |
223 | RecBody body; | 231 | RecBody body; |
224 | mailstorage*storage = mailstorage_new(NULL); | 232 | mailstorage*storage = mailstorage_new(NULL); |
225 | QString p = MBOXPath+"/"; | 233 | QString p = MBOXPath+"/"; |
226 | p+=mail.getMbox(); | 234 | p+=mail.getMbox(); |
227 | mailmessage * msg; | 235 | mailmessage * msg; |
228 | char*data=0; | 236 | char*data=0; |
229 | size_t size; | 237 | size_t size; |
230 | 238 | ||
231 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 239 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
232 | mailfolder*folder; | 240 | mailfolder*folder; |
233 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 241 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
234 | r = mailfolder_connect(folder); | 242 | r = mailfolder_connect(folder); |
235 | if (r != MAIL_NO_ERROR) { | 243 | if (r != MAIL_NO_ERROR) { |
236 | qDebug("Error initializing mbox"); | 244 | qDebug("Error initializing mbox"); |
237 | mailfolder_free(folder); | 245 | mailfolder_free(folder); |
238 | mailstorage_free(storage); | 246 | mailstorage_free(storage); |
239 | return; | 247 | return; |
240 | } | 248 | } |
241 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 249 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
242 | if (r != MAIL_NO_ERROR) { | 250 | if (r != MAIL_NO_ERROR) { |
243 | qDebug("Error fetching mail %i",mail.getNumber()); | 251 | qDebug("Error fetching mail %i",mail.getNumber()); |
244 | mailfolder_free(folder); | 252 | mailfolder_free(folder); |
245 | mailstorage_free(storage); | 253 | mailstorage_free(storage); |
246 | return; | 254 | return; |
247 | } | 255 | } |
248 | r = mailmessage_fetch(msg,&data,&size); | 256 | r = mailmessage_fetch(msg,&data,&size); |
249 | if (r != MAIL_NO_ERROR) { | 257 | if (r != MAIL_NO_ERROR) { |
250 | qDebug("Error fetching mail %i",mail.getNumber()); | 258 | qDebug("Error fetching mail %i",mail.getNumber()); |
251 | mailfolder_free(folder); | 259 | mailfolder_free(folder); |
252 | mailstorage_free(storage); | 260 | mailstorage_free(storage); |
253 | mailmessage_free(msg); | 261 | mailmessage_free(msg); |
254 | return; | 262 | return; |
255 | } | 263 | } |
256 | *target = data; | 264 | *target = data; |
257 | *length = size; | 265 | *length = size; |
258 | mailfolder_free(folder); | 266 | mailfolder_free(folder); |
259 | mailstorage_free(storage); | 267 | mailstorage_free(storage); |
260 | mailmessage_free(msg); | 268 | mailmessage_free(msg); |
261 | } | 269 | } |
262 | 270 | ||
263 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 271 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
264 | { | 272 | { |
265 | QString p = MBOXPath+"/"; | 273 | QString p = MBOXPath+"/"; |
266 | p+=mailbox; | 274 | p+=mailbox; |
267 | mailmbox_folder*f = 0; | 275 | mailmbox_folder*f = 0; |
268 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 276 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
269 | if (r != MAIL_NO_ERROR) { | 277 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("Error init folder"); | 278 | qDebug("Error init folder"); |
271 | return; | 279 | return; |
272 | } | 280 | } |
273 | for (unsigned int i=0; i < target.count();++i) { | 281 | for (unsigned int i=0; i < target.count();++i) { |
274 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 282 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
275 | if (r!=MAILMBOX_NO_ERROR) { | 283 | if (r!=MAILMBOX_NO_ERROR) { |
276 | qDebug("error delete mail"); | 284 | qDebug("error delete mail"); |
277 | } | 285 | } |
278 | } | 286 | } |
279 | r = mailmbox_expunge(f); | 287 | r = mailmbox_expunge(f); |
280 | if (r != MAILMBOX_NO_ERROR) { | 288 | if (r != MAILMBOX_NO_ERROR) { |
281 | qDebug("error expunge mailbox"); | 289 | qDebug("error expunge mailbox"); |
282 | } | 290 | } |
283 | mailmbox_done(f); | 291 | mailmbox_done(f); |
284 | } | 292 | } |
285 | 293 | ||
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 | |||
@@ -1,744 +1,757 @@ | |||
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 | #include <qt.h> | 8 | #include <qt.h> |
9 | 9 | ||
10 | #include <libetpan/libetpan.h> | 10 | #include <libetpan/libetpan.h> |
11 | 11 | ||
12 | #include "smtpwrapper.h" | 12 | #include "smtpwrapper.h" |
13 | #include "mailwrapper.h" | 13 | #include "mailwrapper.h" |
14 | #include "mboxwrapper.h" | 14 | #include "mboxwrapper.h" |
15 | #include "logindialog.h" | 15 | #include "logindialog.h" |
16 | #include "mailtypes.h" | 16 | #include "mailtypes.h" |
17 | #include "defines.h" | 17 | #include "defines.h" |
18 | #include "sendmailprogress.h" | 18 | #include "sendmailprogress.h" |
19 | 19 | ||
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 20 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 21 | ||
22 | SMTPwrapper::SMTPwrapper( Settings *s ) | 22 | SMTPwrapper::SMTPwrapper( Settings *s ) |
23 | : QObject() | 23 | : QObject() |
24 | { | 24 | { |
25 | settings = s; | 25 | settings = s; |
26 | } | 26 | } |
27 | 27 | ||
28 | QString SMTPwrapper::mailsmtpError( int errnum ) | 28 | QString SMTPwrapper::mailsmtpError( int errnum ) |
29 | { | 29 | { |
30 | switch ( errnum ) { | 30 | switch ( errnum ) { |
31 | case MAILSMTP_NO_ERROR: | 31 | case MAILSMTP_NO_ERROR: |
32 | return tr( "No error" ); | 32 | return tr( "No error" ); |
33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
34 | return tr( "Unexpected error code" ); | 34 | return tr( "Unexpected error code" ); |
35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
36 | return tr( "Service not available" ); | 36 | return tr( "Service not available" ); |
37 | case MAILSMTP_ERROR_STREAM: | 37 | case MAILSMTP_ERROR_STREAM: |
38 | return tr( "Stream error" ); | 38 | return tr( "Stream error" ); |
39 | case MAILSMTP_ERROR_HOSTNAME: | 39 | case MAILSMTP_ERROR_HOSTNAME: |
40 | return tr( "gethostname() failed" ); | 40 | return tr( "gethostname() failed" ); |
41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
42 | return tr( "Not implemented" ); | 42 | return tr( "Not implemented" ); |
43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
44 | return tr( "Error, action not taken" ); | 44 | return tr( "Error, action not taken" ); |
45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
46 | return tr( "Data exceeds storage allocation" ); | 46 | return tr( "Data exceeds storage allocation" ); |
47 | case MAILSMTP_ERROR_IN_PROCESSING: | 47 | case MAILSMTP_ERROR_IN_PROCESSING: |
48 | return tr( "Error in processing" ); | 48 | return tr( "Error in processing" ); |
49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
50 | // return tr( "Insufficient system storage" ); | 50 | // return tr( "Insufficient system storage" ); |
51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
52 | return tr( "Mailbox unavailable" ); | 52 | return tr( "Mailbox unavailable" ); |
53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
54 | return tr( "Mailbox name not allowed" ); | 54 | return tr( "Mailbox name not allowed" ); |
55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
56 | return tr( "Bad command sequence" ); | 56 | return tr( "Bad command sequence" ); |
57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
58 | return tr( "User not local" ); | 58 | return tr( "User not local" ); |
59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
60 | return tr( "Transaction failed" ); | 60 | return tr( "Transaction failed" ); |
61 | case MAILSMTP_ERROR_MEMORY: | 61 | case MAILSMTP_ERROR_MEMORY: |
62 | return tr( "Memory error" ); | 62 | return tr( "Memory error" ); |
63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
64 | return tr( "Connection refused" ); | 64 | return tr( "Connection refused" ); |
65 | default: | 65 | default: |
66 | return tr( "Unknown error code" ); | 66 | return tr( "Unknown error code" ); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
71 | { | 71 | { |
72 | return mailimf_mailbox_new( strdup( name.latin1() ), | 72 | return mailimf_mailbox_new( strdup( name.latin1() ), |
73 | strdup( mail.latin1() ) ); | 73 | strdup( mail.latin1() ) ); |
74 | } | 74 | } |
75 | 75 | ||
76 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 76 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
77 | { | 77 | { |
78 | mailimf_address_list *addresses; | 78 | mailimf_address_list *addresses; |
79 | 79 | ||
80 | if ( addr.isEmpty() ) return NULL; | 80 | if ( addr.isEmpty() ) return NULL; |
81 | 81 | ||
82 | addresses = mailimf_address_list_new_empty(); | 82 | addresses = mailimf_address_list_new_empty(); |
83 | 83 | ||
84 | QStringList list = QStringList::split( ',', addr ); | 84 | QStringList list = QStringList::split( ',', addr ); |
85 | QStringList::Iterator it; | 85 | QStringList::Iterator it; |
86 | for ( it = list.begin(); it != list.end(); it++ ) { | 86 | for ( it = list.begin(); it != list.end(); it++ ) { |
87 | char *str = strdup( (*it).latin1() ); | 87 | char *str = strdup( (*it).latin1() ); |
88 | int err = mailimf_address_list_add_parse( addresses, str ); | 88 | int err = mailimf_address_list_add_parse( addresses, str ); |
89 | if ( err != MAILIMF_NO_ERROR ) { | 89 | if ( err != MAILIMF_NO_ERROR ) { |
90 | qDebug( "Error parsing" ); | 90 | qDebug( "Error parsing" ); |
91 | qDebug( *it ); | 91 | qDebug( *it ); |
92 | free( str ); | 92 | free( str ); |
93 | } else { | 93 | } else { |
94 | qDebug( "Parse success! :)" ); | 94 | qDebug( "Parse success! :)" ); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | return addresses; | 98 | return addresses; |
99 | } | 99 | } |
100 | 100 | ||
101 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 101 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
102 | { | 102 | { |
103 | mailimf_fields *fields; | 103 | mailimf_fields *fields; |
104 | mailimf_field *xmailer; | 104 | mailimf_field *xmailer; |
105 | mailimf_mailbox *sender, *fromBox; | 105 | mailimf_mailbox *sender, *fromBox; |
106 | mailimf_mailbox_list *from; | 106 | mailimf_mailbox_list *from; |
107 | mailimf_address_list *to, *cc, *bcc, *reply; | 107 | mailimf_address_list *to, *cc, *bcc, *reply; |
108 | char *subject = strdup( mail.getSubject().latin1() ); | 108 | char *subject = strdup( mail.getSubject().latin1() ); |
109 | int err; | 109 | int err; |
110 | 110 | ||
111 | sender = newMailbox( mail.getName(), mail.getMail() ); | 111 | sender = newMailbox( mail.getName(), mail.getMail() ); |
112 | if ( sender == NULL ) goto err_free; | 112 | if ( sender == NULL ) goto err_free; |
113 | 113 | ||
114 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 114 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
115 | if ( fromBox == NULL ) goto err_free_sender; | 115 | if ( fromBox == NULL ) goto err_free_sender; |
116 | 116 | ||
117 | from = mailimf_mailbox_list_new_empty(); | 117 | from = mailimf_mailbox_list_new_empty(); |
118 | if ( from == NULL ) goto err_free_fromBox; | 118 | if ( from == NULL ) goto err_free_fromBox; |
119 | 119 | ||
120 | err = mailimf_mailbox_list_add( from, fromBox ); | 120 | err = mailimf_mailbox_list_add( from, fromBox ); |
121 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 121 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
122 | 122 | ||
123 | to = parseAddresses( mail.getTo() ); | 123 | to = parseAddresses( mail.getTo() ); |
124 | if ( to == NULL ) goto err_free_from; | 124 | if ( to == NULL ) goto err_free_from; |
125 | 125 | ||
126 | cc = parseAddresses( mail.getCC() ); | 126 | cc = parseAddresses( mail.getCC() ); |
127 | bcc = parseAddresses( mail.getBCC() ); | 127 | bcc = parseAddresses( mail.getBCC() ); |
128 | reply = parseAddresses( mail.getReply() ); | 128 | reply = parseAddresses( mail.getReply() ); |
129 | 129 | ||
130 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 130 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
131 | NULL, NULL, subject ); | 131 | NULL, NULL, subject ); |
132 | if ( fields == NULL ) goto err_free_reply; | 132 | if ( fields == NULL ) goto err_free_reply; |
133 | 133 | ||
134 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 134 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
135 | strdup( USER_AGENT ) ); | 135 | strdup( USER_AGENT ) ); |
136 | if ( xmailer == NULL ) goto err_free_fields; | 136 | if ( xmailer == NULL ) goto err_free_fields; |
137 | 137 | ||
138 | err = mailimf_fields_add( fields, xmailer ); | 138 | err = mailimf_fields_add( fields, xmailer ); |
139 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 139 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
140 | 140 | ||
141 | return fields; // Success :) | 141 | return fields; // Success :) |
142 | 142 | ||
143 | err_free_xmailer: | 143 | err_free_xmailer: |
144 | mailimf_field_free( xmailer ); | 144 | mailimf_field_free( xmailer ); |
145 | err_free_fields: | 145 | err_free_fields: |
146 | mailimf_fields_free( fields ); | 146 | mailimf_fields_free( fields ); |
147 | err_free_reply: | 147 | err_free_reply: |
148 | mailimf_address_list_free( reply ); | 148 | mailimf_address_list_free( reply ); |
149 | mailimf_address_list_free( bcc ); | 149 | mailimf_address_list_free( bcc ); |
150 | mailimf_address_list_free( cc ); | 150 | mailimf_address_list_free( cc ); |
151 | mailimf_address_list_free( to ); | 151 | mailimf_address_list_free( to ); |
152 | err_free_from: | 152 | err_free_from: |
153 | mailimf_mailbox_list_free( from ); | 153 | mailimf_mailbox_list_free( from ); |
154 | err_free_fromBox: | 154 | err_free_fromBox: |
155 | mailimf_mailbox_free( fromBox ); | 155 | mailimf_mailbox_free( fromBox ); |
156 | err_free_sender: | 156 | err_free_sender: |
157 | mailimf_mailbox_free( sender ); | 157 | mailimf_mailbox_free( sender ); |
158 | err_free: | 158 | err_free: |
159 | free( subject ); | 159 | free( subject ); |
160 | qDebug( "createImfFields - error" ); | 160 | qDebug( "createImfFields - error" ); |
161 | 161 | ||
162 | return NULL; // Error :( | 162 | return NULL; // Error :( |
163 | } | 163 | } |
164 | 164 | ||
165 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 165 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
166 | { | 166 | { |
167 | mailmime *txtPart; | 167 | mailmime *txtPart; |
168 | mailmime_fields *fields; | 168 | mailmime_fields *fields; |
169 | mailmime_content *content; | 169 | mailmime_content *content; |
170 | mailmime_parameter *param; | 170 | mailmime_parameter *param; |
171 | char *txt = strdup( str.latin1() ); | 171 | char *txt = strdup( str.latin1() ); |
172 | int err; | 172 | int err; |
173 | 173 | ||
174 | param = mailmime_parameter_new( strdup( "charset" ), | 174 | param = mailmime_parameter_new( strdup( "charset" ), |
175 | strdup( "iso-8859-1" ) ); | 175 | strdup( "iso-8859-1" ) ); |
176 | if ( param == NULL ) goto err_free; | 176 | if ( param == NULL ) goto err_free; |
177 | 177 | ||
178 | content = mailmime_content_new_with_str( "text/plain" ); | 178 | content = mailmime_content_new_with_str( "text/plain" ); |
179 | if ( content == NULL ) goto err_free_param; | 179 | if ( content == NULL ) goto err_free_param; |
180 | 180 | ||
181 | err = clist_append( content->ct_parameters, param ); | 181 | err = clist_append( content->ct_parameters, param ); |
182 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 182 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
183 | 183 | ||
184 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 184 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
185 | if ( fields == NULL ) goto err_free_content; | 185 | if ( fields == NULL ) goto err_free_content; |
186 | 186 | ||
187 | txtPart = mailmime_new_empty( content, fields ); | 187 | txtPart = mailmime_new_empty( content, fields ); |
188 | if ( txtPart == NULL ) goto err_free_fields; | 188 | if ( txtPart == NULL ) goto err_free_fields; |
189 | 189 | ||
190 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 190 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
191 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 191 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
192 | 192 | ||
193 | return txtPart; // Success :) | 193 | return txtPart; // Success :) |
194 | 194 | ||
195 | err_free_txtPart: | 195 | err_free_txtPart: |
196 | mailmime_free( txtPart ); | 196 | mailmime_free( txtPart ); |
197 | err_free_fields: | 197 | err_free_fields: |
198 | mailmime_fields_free( fields ); | 198 | mailmime_fields_free( fields ); |
199 | err_free_content: | 199 | err_free_content: |
200 | mailmime_content_free( content ); | 200 | mailmime_content_free( content ); |
201 | err_free_param: | 201 | err_free_param: |
202 | mailmime_parameter_free( param ); | 202 | mailmime_parameter_free( param ); |
203 | err_free: | 203 | err_free: |
204 | free( txt ); | 204 | free( txt ); |
205 | qDebug( "buildTxtPart - error" ); | 205 | qDebug( "buildTxtPart - error" ); |
206 | 206 | ||
207 | return NULL; // Error :( | 207 | return NULL; // Error :( |
208 | } | 208 | } |
209 | 209 | ||
210 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) | 210 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
211 | { | 211 | { |
212 | mailmime * filePart = 0; | 212 | mailmime * filePart = 0; |
213 | mailmime_fields * fields = 0; | 213 | mailmime_fields * fields = 0; |
214 | mailmime_content * content = 0; | 214 | mailmime_content * content = 0; |
215 | mailmime_parameter * param = 0; | 215 | mailmime_parameter * param = 0; |
216 | char*name = 0; | 216 | char*name = 0; |
217 | char*file = 0; | 217 | char*file = 0; |
218 | int err; | 218 | int err; |
219 | 219 | ||
220 | int pos = filename.findRev( '/' ); | 220 | int pos = filename.findRev( '/' ); |
221 | 221 | ||
222 | if (filename.length()>0) { | 222 | if (filename.length()>0) { |
223 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 223 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
224 | name = strdup( tmp.latin1() ); // just filename | 224 | name = strdup( tmp.latin1() ); // just filename |
225 | file = strdup( filename.latin1() ); // full name with path | 225 | file = strdup( filename.latin1() ); // full name with path |
226 | } | 226 | } |
227 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 227 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
228 | 228 | ||
229 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 229 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
230 | int mechanism = MAILMIME_MECHANISM_BASE64; | 230 | int mechanism = MAILMIME_MECHANISM_BASE64; |
231 | 231 | ||
232 | if ( mimetype.startsWith( "text/" ) ) { | 232 | if ( mimetype.startsWith( "text/" ) ) { |
233 | param = mailmime_parameter_new( strdup( "charset" ), | 233 | param = mailmime_parameter_new( strdup( "charset" ), |
234 | strdup( "iso-8859-1" ) ); | 234 | strdup( "iso-8859-1" ) ); |
235 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; | 235 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; |
236 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 236 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
237 | } | 237 | } |
238 | 238 | ||
239 | fields = mailmime_fields_new_filename( | 239 | fields = mailmime_fields_new_filename( |
240 | disptype, name, | 240 | disptype, name, |
241 | mechanism ); | 241 | mechanism ); |
242 | content = mailmime_content_new_with_str( mime ); | 242 | content = mailmime_content_new_with_str( mime ); |
243 | if (content!=0 && fields != 0) { | 243 | if (content!=0 && fields != 0) { |
244 | if (param) { | 244 | if (param) { |
245 | clist_append(content->ct_parameters,param); | 245 | clist_append(content->ct_parameters,param); |
246 | param = 0; | 246 | param = 0; |
247 | } | 247 | } |
248 | if (filename.length()>0) { | 248 | if (filename.length()>0) { |
249 | QFileInfo f(filename); | 249 | QFileInfo f(filename); |
250 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 250 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
251 | clist_append(content->ct_parameters,param); | 251 | clist_append(content->ct_parameters,param); |
252 | param = 0; | 252 | param = 0; |
253 | } | 253 | } |
254 | filePart = mailmime_new_empty( content, fields ); | 254 | filePart = mailmime_new_empty( content, fields ); |
255 | } | 255 | } |
256 | if (filePart) { | 256 | if (filePart) { |
257 | if (filename.length()>0) { | 257 | if (filename.length()>0) { |
258 | err = mailmime_set_body_file( filePart, file ); | 258 | err = mailmime_set_body_file( filePart, file ); |
259 | } else { | 259 | } else { |
260 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); | 260 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); |
261 | } | 261 | } |
262 | if (err != MAILIMF_NO_ERROR) { | 262 | if (err != MAILIMF_NO_ERROR) { |
263 | qDebug("Error setting body with file %s",file); | 263 | qDebug("Error setting body with file %s",file); |
264 | mailmime_free( filePart ); | 264 | mailmime_free( filePart ); |
265 | filePart = 0; | 265 | filePart = 0; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | if (!filePart) { | 269 | if (!filePart) { |
270 | if ( param != NULL ) { | 270 | if ( param != NULL ) { |
271 | mailmime_parameter_free( param ); | 271 | mailmime_parameter_free( param ); |
272 | } | 272 | } |
273 | if (content) { | 273 | if (content) { |
274 | mailmime_content_free( content ); | 274 | mailmime_content_free( content ); |
275 | } else { | 275 | } else { |
276 | if (mime) { | 276 | if (mime) { |
277 | free( mime ); | 277 | free( mime ); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | if (fields) { | 280 | if (fields) { |
281 | mailmime_fields_free( fields ); | 281 | mailmime_fields_free( fields ); |
282 | } else { | 282 | } else { |
283 | if (name) { | 283 | if (name) { |
284 | free( name ); | 284 | free( name ); |
285 | } | 285 | } |
286 | if (file) { | 286 | if (file) { |
287 | free( file ); | 287 | free( file ); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | } | 290 | } |
291 | return filePart; // Success :) | 291 | return filePart; // Success :) |
292 | 292 | ||
293 | } | 293 | } |
294 | 294 | ||
295 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 295 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
296 | { | 296 | { |
297 | const Attachment *it; | 297 | const Attachment *it; |
298 | unsigned int count = files.count(); | 298 | unsigned int count = files.count(); |
299 | qDebug("List contains %i values",count); | 299 | qDebug("List contains %i values",count); |
300 | for ( unsigned int i = 0; i < count; ++i ) { | 300 | for ( unsigned int i = 0; i < count; ++i ) { |
301 | qDebug( "Adding file" ); | 301 | qDebug( "Adding file" ); |
302 | mailmime *filePart; | 302 | mailmime *filePart; |
303 | int err; | 303 | int err; |
304 | it = ((QList<Attachment>)files).at(i); | 304 | it = ((QList<Attachment>)files).at(i); |
305 | 305 | ||
306 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 306 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
307 | if ( filePart == NULL ) { | 307 | if ( filePart == NULL ) { |
308 | qDebug( "addFileParts: error adding file:" ); | 308 | qDebug( "addFileParts: error adding file:" ); |
309 | qDebug( it->getFileName() ); | 309 | qDebug( it->getFileName() ); |
310 | continue; | 310 | continue; |
311 | } | 311 | } |
312 | err = mailmime_smart_add_part( message, filePart ); | 312 | err = mailmime_smart_add_part( message, filePart ); |
313 | if ( err != MAILIMF_NO_ERROR ) { | 313 | if ( err != MAILIMF_NO_ERROR ) { |
314 | mailmime_free( filePart ); | 314 | mailmime_free( filePart ); |
315 | qDebug("error smart add"); | 315 | qDebug("error smart add"); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | } | 318 | } |
319 | 319 | ||
320 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 320 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
321 | { | 321 | { |
322 | mailmime *message, *txtPart; | 322 | mailmime *message, *txtPart; |
323 | mailimf_fields *fields; | 323 | mailimf_fields *fields; |
324 | int err; | 324 | int err; |
325 | 325 | ||
326 | fields = createImfFields( mail ); | 326 | fields = createImfFields( mail ); |
327 | if ( fields == NULL ) goto err_free; | 327 | if ( fields == NULL ) goto err_free; |
328 | 328 | ||
329 | message = mailmime_new_message_data( NULL ); | 329 | message = mailmime_new_message_data( NULL ); |
330 | if ( message == NULL ) goto err_free_fields; | 330 | if ( message == NULL ) goto err_free_fields; |
331 | 331 | ||
332 | mailmime_set_imf_fields( message, fields ); | 332 | mailmime_set_imf_fields( message, fields ); |
333 | 333 | ||
334 | if (mail.getAttachments().count()==0) { | 334 | if (mail.getAttachments().count()==0) { |
335 | txtPart = buildTxtPart( mail.getMessage() ); | 335 | txtPart = buildTxtPart( mail.getMessage() ); |
336 | } else { | 336 | } else { |
337 | txtPart = buildFilePart("","text/plain",mail.getMessage()); | 337 | txtPart = buildFilePart("","text/plain",mail.getMessage()); |
338 | } | 338 | } |
339 | if ( txtPart == NULL ) goto err_free_message; | 339 | if ( txtPart == NULL ) goto err_free_message; |
340 | 340 | ||
341 | err = mailmime_smart_add_part( message, txtPart ); | 341 | err = mailmime_smart_add_part( message, txtPart ); |
342 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 342 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
343 | 343 | ||
344 | addFileParts( message, mail.getAttachments() ); | 344 | addFileParts( message, mail.getAttachments() ); |
345 | 345 | ||
346 | return message; // Success :) | 346 | return message; // Success :) |
347 | 347 | ||
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 | } |