-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 13 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.cpp | 13 |
2 files changed, 2 insertions, 24 deletions
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index c7b27a0..62fa64f 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -145,144 +145,133 @@ void EmailHandler::messageArrived(const QString &message, int id, uint size, boo | |||
145 | mail.size = size; | 145 | mail.size = size; |
146 | mail.downloaded = complete; | 146 | mail.downloaded = complete; |
147 | 147 | ||
148 | emit mailArrived(mail, FALSE); | 148 | emit mailArrived(mail, FALSE); |
149 | } | 149 | } |
150 | 150 | ||
151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
152 | { | 152 | { |
153 | QString temp, boundary; | 153 | QString temp, boundary; |
154 | int pos; | 154 | int pos; |
155 | QString delimiter, header, body, mimeHeader, mimeBody; | 155 | QString delimiter, header, body, mimeHeader, mimeBody; |
156 | QString content, contentType, contentAttribute, id, encoding; | 156 | QString content, contentType, contentAttribute, id, encoding; |
157 | QString fileName, storedName; | 157 | QString fileName, storedName; |
158 | int enclosureId = 0; | 158 | int enclosureId = 0; |
159 | 159 | ||
160 | mail->rawMail = in; | 160 | mail->rawMail = in; |
161 | mail->received = TRUE; | 161 | mail->received = TRUE; |
162 | mail->files.setAutoDelete(TRUE); | 162 | mail->files.setAutoDelete(TRUE); |
163 | 163 | ||
164 | temp = lineShift + "." + lineShift; | 164 | temp = lineShift + "." + lineShift; |
165 | 165 | ||
166 | if (in.right(temp.length()) != temp) { | 166 | if (in.right(temp.length()) != temp) { |
167 | mail->rawMail += temp; | 167 | mail->rawMail += temp; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
172 | pos = in.find(delimiter, 0, FALSE); | 172 | pos = in.find(delimiter, 0, FALSE); |
173 | header = in.left(pos); | 173 | header = in.left(pos); |
174 | body = in.right(in.length() - pos - delimiter.length()); | 174 | body = in.right(in.length() - pos - delimiter.length()); |
175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
176 | body.truncate(body.length()-2); | 176 | body.truncate(body.length()-2); |
177 | 177 | ||
178 | TextParser p(header, lineShift); | 178 | TextParser p(header, lineShift); |
179 | 179 | ||
180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
181 | pos++; | 181 | pos++; |
182 | if (p.separatorAt(pos) == ' ') { | 182 | if (p.separatorAt(pos) == ' ') { |
183 | mail->from = p.getString(&pos, '<', false); | 183 | mail->from = p.getString(&pos, '<', false); |
184 | mail->from = mail->from.stripWhiteSpace(); | 184 | mail->from = mail->from.stripWhiteSpace(); |
185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
186 | mail->from = mail->from.left(mail->from.length() - 1); | 186 | mail->from = mail->from.left(mail->from.length() - 1); |
187 | mail->from = mail->from.right(mail->from.length() - 1); | 187 | mail->from = mail->from.right(mail->from.length() - 1); |
188 | } | 188 | } |
189 | pos++; | 189 | pos++; |
190 | mail->fromMail = p.getString(&pos, '>', false); | 190 | mail->fromMail = p.getString(&pos, '>', false); |
191 | } else { | 191 | } else { |
192 | if (p.separatorAt(pos) == '<') //No name.. nasty | 192 | if (p.separatorAt(pos) == '<') //No name.. nasty |
193 | pos++; | 193 | pos++; |
194 | //pos++; | 194 | //pos++; |
195 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
197 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
198 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | pos=0; | 202 | pos=0; |
203 | 203 | ||
204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
206 | { | 206 | { |
207 | QString rec; | 207 | QString rec; |
208 | 208 | ||
209 | if (p.separatorAt(pos-1)!='-') | 209 | if (p.separatorAt(pos-1)!='-')//The - separator means that this is a Delivered-To: or Reply-To: |
210 | { | 210 | { |
211 | pos++; | 211 | pos++; |
212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
213 | } | 213 | } |
214 | /*else { | ||
215 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty | ||
216 | pos++; | ||
217 | pos++; | ||
218 | mail->fromMail = p.getString(&pos, 'z', TRUE); | ||
219 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | ||
220 | mail->fromMail.truncate(mail->fromMail.length() - 1); | ||
221 | mail->from=mail->fromMail; | ||
222 | } | ||
223 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | ||
224 | }*/ | ||
225 | } | 214 | } |
226 | // | 215 | // |
227 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
228 | 217 | ||
229 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
230 | { | 219 | { |
231 | pos++; | 220 | pos++; |
232 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
233 | } | 222 | } |
234 | 223 | ||
235 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
236 | pos++; | 225 | pos++; |
237 | mail->subject = p.getString(&pos, 'z', TRUE); | 226 | mail->subject = p.getString(&pos, 'z', TRUE); |
238 | } | 227 | } |
239 | 228 | ||
240 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
241 | pos++; | 230 | pos++; |
242 | mail->date = p.getString(&pos, 'z', TRUE); | 231 | mail->date = p.getString(&pos, 'z', TRUE); |
243 | } | 232 | } |
244 | 233 | ||
245 | 234 | ||
246 | 235 | ||
247 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
248 | pos++; | 237 | pos++; |
249 | if ( (p.wordAt(pos).upper() == "ID") && | 238 | if ( (p.wordAt(pos).upper() == "ID") && |
250 | (p.separatorAt(pos) == ':') ) { | 239 | (p.separatorAt(pos) == ':') ) { |
251 | 240 | ||
252 | id = p.getString(&pos, 'z', TRUE); | 241 | id = p.getString(&pos, 'z', TRUE); |
253 | mail->id = id; | 242 | mail->id = id; |
254 | } | 243 | } |
255 | } | 244 | } |
256 | 245 | ||
257 | pos = 0; | 246 | pos = 0; |
258 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
259 | pos++; | 248 | pos++; |
260 | if ( (p.wordAt(pos).upper() == "VERSION") && | 249 | if ( (p.wordAt(pos).upper() == "VERSION") && |
261 | (p.separatorAt(pos) == ':') ) { | 250 | (p.separatorAt(pos) == ':') ) { |
262 | pos++; | 251 | pos++; |
263 | if (p.getString(&pos, 'z', true) == "1.0") { | 252 | if (p.getString(&pos, 'z', true) == "1.0") { |
264 | mail->mimeType = 1; | 253 | mail->mimeType = 1; |
265 | } | 254 | } |
266 | } | 255 | } |
267 | } | 256 | } |
268 | 257 | ||
269 | if (mail->mimeType == 1) { | 258 | if (mail->mimeType == 1) { |
270 | boundary = ""; | 259 | boundary = ""; |
271 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
272 | pos++; | 261 | pos++; |
273 | boundary = p.getString(&pos, 'z', true); | 262 | boundary = p.getString(&pos, 'z', true); |
274 | if (boundary[0] == '"') { | 263 | if (boundary[0] == '"') { |
275 | boundary = boundary.left(boundary.length() - 1); //strip " | 264 | boundary = boundary.left(boundary.length() - 1); //strip " |
276 | boundary = boundary.right(boundary.length() - 1); //strip " | 265 | boundary = boundary.right(boundary.length() - 1); //strip " |
277 | } | 266 | } |
278 | boundary = "--" + boundary; //create boundary field | 267 | boundary = "--" + boundary; //create boundary field |
279 | } | 268 | } |
280 | 269 | ||
281 | if (boundary == "") { //fooled by Mime-Version | 270 | if (boundary == "") { //fooled by Mime-Version |
282 | mail->body = body; | 271 | mail->body = body; |
283 | mail->bodyPlain = body; | 272 | mail->bodyPlain = body; |
284 | return mail; | 273 | return mail; |
285 | } | 274 | } |
286 | 275 | ||
287 | while (body.length() > 0) { | 276 | while (body.length() > 0) { |
288 | pos = body.find(boundary, 0, FALSE); | 277 | pos = body.find(boundary, 0, FALSE); |
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp index c7b27a0..62fa64f 100644 --- a/noncore/unsupported/mailit/emailhandler.cpp +++ b/noncore/unsupported/mailit/emailhandler.cpp | |||
@@ -145,144 +145,133 @@ void EmailHandler::messageArrived(const QString &message, int id, uint size, boo | |||
145 | mail.size = size; | 145 | mail.size = size; |
146 | mail.downloaded = complete; | 146 | mail.downloaded = complete; |
147 | 147 | ||
148 | emit mailArrived(mail, FALSE); | 148 | emit mailArrived(mail, FALSE); |
149 | } | 149 | } |
150 | 150 | ||
151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
152 | { | 152 | { |
153 | QString temp, boundary; | 153 | QString temp, boundary; |
154 | int pos; | 154 | int pos; |
155 | QString delimiter, header, body, mimeHeader, mimeBody; | 155 | QString delimiter, header, body, mimeHeader, mimeBody; |
156 | QString content, contentType, contentAttribute, id, encoding; | 156 | QString content, contentType, contentAttribute, id, encoding; |
157 | QString fileName, storedName; | 157 | QString fileName, storedName; |
158 | int enclosureId = 0; | 158 | int enclosureId = 0; |
159 | 159 | ||
160 | mail->rawMail = in; | 160 | mail->rawMail = in; |
161 | mail->received = TRUE; | 161 | mail->received = TRUE; |
162 | mail->files.setAutoDelete(TRUE); | 162 | mail->files.setAutoDelete(TRUE); |
163 | 163 | ||
164 | temp = lineShift + "." + lineShift; | 164 | temp = lineShift + "." + lineShift; |
165 | 165 | ||
166 | if (in.right(temp.length()) != temp) { | 166 | if (in.right(temp.length()) != temp) { |
167 | mail->rawMail += temp; | 167 | mail->rawMail += temp; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
172 | pos = in.find(delimiter, 0, FALSE); | 172 | pos = in.find(delimiter, 0, FALSE); |
173 | header = in.left(pos); | 173 | header = in.left(pos); |
174 | body = in.right(in.length() - pos - delimiter.length()); | 174 | body = in.right(in.length() - pos - delimiter.length()); |
175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
176 | body.truncate(body.length()-2); | 176 | body.truncate(body.length()-2); |
177 | 177 | ||
178 | TextParser p(header, lineShift); | 178 | TextParser p(header, lineShift); |
179 | 179 | ||
180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
181 | pos++; | 181 | pos++; |
182 | if (p.separatorAt(pos) == ' ') { | 182 | if (p.separatorAt(pos) == ' ') { |
183 | mail->from = p.getString(&pos, '<', false); | 183 | mail->from = p.getString(&pos, '<', false); |
184 | mail->from = mail->from.stripWhiteSpace(); | 184 | mail->from = mail->from.stripWhiteSpace(); |
185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
186 | mail->from = mail->from.left(mail->from.length() - 1); | 186 | mail->from = mail->from.left(mail->from.length() - 1); |
187 | mail->from = mail->from.right(mail->from.length() - 1); | 187 | mail->from = mail->from.right(mail->from.length() - 1); |
188 | } | 188 | } |
189 | pos++; | 189 | pos++; |
190 | mail->fromMail = p.getString(&pos, '>', false); | 190 | mail->fromMail = p.getString(&pos, '>', false); |
191 | } else { | 191 | } else { |
192 | if (p.separatorAt(pos) == '<') //No name.. nasty | 192 | if (p.separatorAt(pos) == '<') //No name.. nasty |
193 | pos++; | 193 | pos++; |
194 | //pos++; | 194 | //pos++; |
195 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
197 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
198 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | pos=0; | 202 | pos=0; |
203 | 203 | ||
204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
206 | { | 206 | { |
207 | QString rec; | 207 | QString rec; |
208 | 208 | ||
209 | if (p.separatorAt(pos-1)!='-') | 209 | if (p.separatorAt(pos-1)!='-')//The - separator means that this is a Delivered-To: or Reply-To: |
210 | { | 210 | { |
211 | pos++; | 211 | pos++; |
212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
213 | } | 213 | } |
214 | /*else { | ||
215 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty | ||
216 | pos++; | ||
217 | pos++; | ||
218 | mail->fromMail = p.getString(&pos, 'z', TRUE); | ||
219 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | ||
220 | mail->fromMail.truncate(mail->fromMail.length() - 1); | ||
221 | mail->from=mail->fromMail; | ||
222 | } | ||
223 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | ||
224 | }*/ | ||
225 | } | 214 | } |
226 | // | 215 | // |
227 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
228 | 217 | ||
229 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
230 | { | 219 | { |
231 | pos++; | 220 | pos++; |
232 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
233 | } | 222 | } |
234 | 223 | ||
235 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
236 | pos++; | 225 | pos++; |
237 | mail->subject = p.getString(&pos, 'z', TRUE); | 226 | mail->subject = p.getString(&pos, 'z', TRUE); |
238 | } | 227 | } |
239 | 228 | ||
240 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
241 | pos++; | 230 | pos++; |
242 | mail->date = p.getString(&pos, 'z', TRUE); | 231 | mail->date = p.getString(&pos, 'z', TRUE); |
243 | } | 232 | } |
244 | 233 | ||
245 | 234 | ||
246 | 235 | ||
247 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
248 | pos++; | 237 | pos++; |
249 | if ( (p.wordAt(pos).upper() == "ID") && | 238 | if ( (p.wordAt(pos).upper() == "ID") && |
250 | (p.separatorAt(pos) == ':') ) { | 239 | (p.separatorAt(pos) == ':') ) { |
251 | 240 | ||
252 | id = p.getString(&pos, 'z', TRUE); | 241 | id = p.getString(&pos, 'z', TRUE); |
253 | mail->id = id; | 242 | mail->id = id; |
254 | } | 243 | } |
255 | } | 244 | } |
256 | 245 | ||
257 | pos = 0; | 246 | pos = 0; |
258 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
259 | pos++; | 248 | pos++; |
260 | if ( (p.wordAt(pos).upper() == "VERSION") && | 249 | if ( (p.wordAt(pos).upper() == "VERSION") && |
261 | (p.separatorAt(pos) == ':') ) { | 250 | (p.separatorAt(pos) == ':') ) { |
262 | pos++; | 251 | pos++; |
263 | if (p.getString(&pos, 'z', true) == "1.0") { | 252 | if (p.getString(&pos, 'z', true) == "1.0") { |
264 | mail->mimeType = 1; | 253 | mail->mimeType = 1; |
265 | } | 254 | } |
266 | } | 255 | } |
267 | } | 256 | } |
268 | 257 | ||
269 | if (mail->mimeType == 1) { | 258 | if (mail->mimeType == 1) { |
270 | boundary = ""; | 259 | boundary = ""; |
271 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
272 | pos++; | 261 | pos++; |
273 | boundary = p.getString(&pos, 'z', true); | 262 | boundary = p.getString(&pos, 'z', true); |
274 | if (boundary[0] == '"') { | 263 | if (boundary[0] == '"') { |
275 | boundary = boundary.left(boundary.length() - 1); //strip " | 264 | boundary = boundary.left(boundary.length() - 1); //strip " |
276 | boundary = boundary.right(boundary.length() - 1); //strip " | 265 | boundary = boundary.right(boundary.length() - 1); //strip " |
277 | } | 266 | } |
278 | boundary = "--" + boundary; //create boundary field | 267 | boundary = "--" + boundary; //create boundary field |
279 | } | 268 | } |
280 | 269 | ||
281 | if (boundary == "") { //fooled by Mime-Version | 270 | if (boundary == "") { //fooled by Mime-Version |
282 | mail->body = body; | 271 | mail->body = body; |
283 | mail->bodyPlain = body; | 272 | mail->bodyPlain = body; |
284 | return mail; | 273 | return mail; |
285 | } | 274 | } |
286 | 275 | ||
287 | while (body.length() > 0) { | 276 | while (body.length() > 0) { |
288 | pos = body.find(boundary, 0, FALSE); | 277 | pos = body.find(boundary, 0, FALSE); |