|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "qmessage.h" |
|
42 #include "qmessage_p.h" |
|
43 #include "qmessageid_p.h" |
|
44 #include "qmessageaccountid_p.h" |
|
45 #include "qmessagemanager.h" |
|
46 #include "qmessagecontentcontainer_p.h" |
|
47 #include "qmessagefolderid_p.h" |
|
48 #include "winhelpers_p.h" |
|
49 #include <QCoreApplication> |
|
50 #include <QDebug> |
|
51 #include <QDir> |
|
52 #include <QFile> |
|
53 |
|
54 QTM_BEGIN_NAMESPACE |
|
55 |
|
56 namespace { |
|
57 |
|
58 QByteArray charsetFor(const QString &input) |
|
59 { |
|
60 QByteArray result(QMessage::preferredCharsetFor(input)); |
|
61 if (result.isEmpty()) { |
|
62 result = "UTF-16"; |
|
63 } |
|
64 |
|
65 return result; |
|
66 } |
|
67 |
|
68 } |
|
69 |
|
70 QMessage QMessagePrivate::from(const QMessageId &id) |
|
71 { |
|
72 QMessage result; |
|
73 result.d_ptr->_id = id; |
|
74 result.d_ptr->_parentAccountId = QMessageAccountIdPrivate::from(QMessageIdPrivate::storeRecordKey(id)); |
|
75 return result; |
|
76 } |
|
77 |
|
78 QString QMessagePrivate::senderName(const QMessage &message) |
|
79 { |
|
80 return message.d_ptr->_senderName; |
|
81 } |
|
82 |
|
83 void QMessagePrivate::setSenderName(const QMessage &message, const QString &senderName) |
|
84 { |
|
85 message.d_ptr->_senderName = senderName; |
|
86 } |
|
87 |
|
88 void QMessagePrivate::setSize(const QMessage &message, int size) |
|
89 { |
|
90 message.d_ptr->_size = size; |
|
91 } |
|
92 |
|
93 void QMessagePrivate::setParentFolderId(QMessage& message, const QMessageFolderId& id) |
|
94 { |
|
95 message.d_ptr->_parentFolderId = id; |
|
96 message.d_ptr->_modified = true; |
|
97 } |
|
98 |
|
99 void QMessagePrivate::setStandardFolder(QMessage& message, QMessage::StandardFolder sf) |
|
100 { |
|
101 message.d_ptr->_standardFolder = sf; |
|
102 message.d_ptr->_modified = true; |
|
103 } |
|
104 |
|
105 void QMessagePrivate::ensurePropertiesPresent(QMessage *msg) const |
|
106 { |
|
107 if (!_elementsPresent.properties && _id.isValid()) { |
|
108 QMessageManager::Error ignoredError(QMessageManager::NoError); |
|
109 MapiSessionPtr session(MapiSession::createSession(&ignoredError)); |
|
110 if (!session.isNull()) { |
|
111 session->updateMessageProperties(&ignoredError, msg); |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 void QMessagePrivate::ensureRecipientsPresent(QMessage *msg) const |
|
117 { |
|
118 if (!_elementsPresent.recipients && _id.isValid()) { |
|
119 QMessageManager::Error ignoredError(QMessageManager::NoError); |
|
120 MapiSessionPtr session(MapiSession::createSession(&ignoredError)); |
|
121 if (!session.isNull()) { |
|
122 session->updateMessageRecipients(&ignoredError, msg); |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 void QMessagePrivate::ensureBodyPresent(QMessage *msg) const |
|
128 { |
|
129 if (!_elementsPresent.body && _id.isValid()) { |
|
130 QMessageManager::Error ignoredError(QMessageManager::NoError); |
|
131 MapiSessionPtr session(MapiSession::createSession(&ignoredError)); |
|
132 if (!session.isNull()) { |
|
133 session->updateMessageBody(&ignoredError, msg); |
|
134 } |
|
135 } |
|
136 } |
|
137 |
|
138 void QMessagePrivate::ensureAttachmentsPresent(QMessage *msg) const |
|
139 { |
|
140 if (!_elementsPresent.attachments && _id.isValid()) { |
|
141 QMessageManager::Error ignoredError(QMessageManager::NoError); |
|
142 MapiSessionPtr session(MapiSession::createSession(&ignoredError)); |
|
143 if (!session.isNull()) { |
|
144 session->updateMessageAttachments(&ignoredError, msg); |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 |
|
150 QMessage::QMessage() |
|
151 : |
|
152 QMessageContentContainer(), |
|
153 d_ptr(new QMessagePrivate(this)) |
|
154 { |
|
155 d_ptr->_modified = false; |
|
156 d_ptr->_size = 0; |
|
157 setDerivedMessage(this); |
|
158 } |
|
159 |
|
160 QMessage::QMessage(const QMessageId& id) |
|
161 : |
|
162 QMessageContentContainer(), |
|
163 d_ptr(new QMessagePrivate(this)) |
|
164 { |
|
165 *this = QMessageManager().message(id); |
|
166 setDerivedMessage(this); |
|
167 } |
|
168 |
|
169 QMessage::QMessage(const QMessage &other) |
|
170 : |
|
171 QMessageContentContainer(other), |
|
172 d_ptr(new QMessagePrivate(this)) |
|
173 { |
|
174 this->operator=(other); |
|
175 setDerivedMessage(this); |
|
176 } |
|
177 |
|
178 QMessage& QMessage::operator=(const QMessage& other) |
|
179 { |
|
180 if (&other != this) { |
|
181 QMessageContentContainer::operator=(other); |
|
182 *d_ptr = *other.d_ptr; |
|
183 setDerivedMessage(this); |
|
184 } |
|
185 |
|
186 return *this; |
|
187 } |
|
188 |
|
189 QMessage::~QMessage() |
|
190 { |
|
191 delete d_ptr; |
|
192 d_ptr = 0; |
|
193 } |
|
194 |
|
195 QMessageId QMessage::id() const |
|
196 { |
|
197 return d_ptr->_id; |
|
198 } |
|
199 |
|
200 QMessage::Type QMessage::type() const |
|
201 { |
|
202 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
203 return d_ptr->_type; |
|
204 } |
|
205 |
|
206 void QMessage::setType(Type t) |
|
207 { |
|
208 d_ptr->_modified = true; |
|
209 d_ptr->_type = t; |
|
210 } |
|
211 |
|
212 QMessageAccountId QMessage::parentAccountId() const |
|
213 { |
|
214 return d_ptr->_parentAccountId; |
|
215 } |
|
216 |
|
217 void QMessage::setParentAccountId(const QMessageAccountId &accountId) |
|
218 { |
|
219 d_ptr->_modified = true; |
|
220 d_ptr->_parentAccountId = accountId; |
|
221 } |
|
222 |
|
223 QMessageFolderId QMessage::parentFolderId() const |
|
224 { |
|
225 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
226 return d_ptr->_parentFolderId; |
|
227 } |
|
228 |
|
229 QMessage::StandardFolder QMessage::standardFolder() const |
|
230 { |
|
231 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
232 return d_ptr->_standardFolder; |
|
233 } |
|
234 |
|
235 QMessageAddress QMessage::from() const |
|
236 { |
|
237 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
238 return d_ptr->_from; |
|
239 } |
|
240 |
|
241 void QMessage::setFrom(const QMessageAddress &address) |
|
242 { |
|
243 d_ptr->_modified = true; |
|
244 d_ptr->_from = address; |
|
245 } |
|
246 |
|
247 QString QMessage::subject() const |
|
248 { |
|
249 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
250 return d_ptr->_subject; |
|
251 } |
|
252 |
|
253 void QMessage::setSubject(const QString &s) |
|
254 { |
|
255 d_ptr->_modified = true; |
|
256 d_ptr->_subject = s; |
|
257 } |
|
258 |
|
259 QDateTime QMessage::date() const |
|
260 { |
|
261 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
262 return d_ptr->_date; |
|
263 } |
|
264 |
|
265 void QMessage::setDate(const QDateTime &d) |
|
266 { |
|
267 d_ptr->_modified = true; |
|
268 d_ptr->_date = d; |
|
269 } |
|
270 |
|
271 QDateTime QMessage::receivedDate() const |
|
272 { |
|
273 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
274 return d_ptr->_receivedDate; |
|
275 } |
|
276 |
|
277 void QMessage::setReceivedDate(const QDateTime &d) |
|
278 { |
|
279 d_ptr->_modified = true; |
|
280 d_ptr->_receivedDate = d; |
|
281 } |
|
282 |
|
283 QMessageAddressList QMessage::to() const |
|
284 { |
|
285 d_ptr->ensureRecipientsPresent(const_cast<QMessage*>(this)); |
|
286 return d_ptr->_to; |
|
287 } |
|
288 |
|
289 void QMessage::setTo(const QMessageAddressList& toList) |
|
290 { |
|
291 d_ptr->_modified = true; |
|
292 d_ptr->_to = toList; |
|
293 } |
|
294 |
|
295 void QMessage::setTo(const QMessageAddress& address) |
|
296 { |
|
297 d_ptr->_modified = true; |
|
298 d_ptr->_to = QMessageAddressList() << address; |
|
299 } |
|
300 |
|
301 QMessageAddressList QMessage::cc() const |
|
302 { |
|
303 d_ptr->ensureRecipientsPresent(const_cast<QMessage*>(this)); |
|
304 return d_ptr->_cc; |
|
305 } |
|
306 |
|
307 void QMessage::setCc(const QMessageAddressList& ccList) |
|
308 { |
|
309 d_ptr->_modified = true; |
|
310 d_ptr->_cc = ccList; |
|
311 } |
|
312 |
|
313 QMessageAddressList QMessage::bcc() const |
|
314 { |
|
315 d_ptr->ensureRecipientsPresent(const_cast<QMessage*>(this)); |
|
316 return d_ptr->_bcc; |
|
317 } |
|
318 |
|
319 void QMessage::setBcc(const QMessageAddressList& bccList) |
|
320 { |
|
321 d_ptr->_modified = true; |
|
322 d_ptr->_bcc = bccList; |
|
323 } |
|
324 |
|
325 QMessage::StatusFlags QMessage::status() const |
|
326 { |
|
327 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
328 return d_ptr->_status; |
|
329 } |
|
330 |
|
331 void QMessage::setStatus(QMessage::StatusFlags newStatus) |
|
332 { |
|
333 d_ptr->_modified = true; |
|
334 d_ptr->_status = newStatus; |
|
335 } |
|
336 |
|
337 void QMessage::setStatus(QMessage::Status flag, bool set) |
|
338 { |
|
339 d_ptr->_modified = true; |
|
340 if (set) { |
|
341 d_ptr->_status |= flag; |
|
342 } else { |
|
343 d_ptr->_status &= ~flag; |
|
344 } |
|
345 } |
|
346 |
|
347 QMessage::Priority QMessage::priority() const |
|
348 { |
|
349 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
350 return d_ptr->_priority; |
|
351 } |
|
352 |
|
353 void QMessage::setPriority(Priority newPriority) |
|
354 { |
|
355 d_ptr->_modified = true; |
|
356 d_ptr->_priority = newPriority; |
|
357 } |
|
358 |
|
359 int QMessage::size() const |
|
360 { |
|
361 int size = 0; |
|
362 |
|
363 d_ptr->ensurePropertiesPresent(const_cast<QMessage*>(this)); |
|
364 if (d_ptr->_size != 0) { |
|
365 size = d_ptr->_size; |
|
366 } else { |
|
367 QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr); |
|
368 if (container->_size != 0) { |
|
369 size += ((container->_size / 1024) + 1) * 1024; |
|
370 } |
|
371 foreach (const QMessageContentContainer &attachment, container->_attachments) { |
|
372 // Round size to a multiple of 1KB |
|
373 size += ((attachment.size() / 1024) + 1) * 1024; |
|
374 } |
|
375 |
|
376 // Allow for header |
|
377 size += 1024; |
|
378 } |
|
379 |
|
380 return size; |
|
381 } |
|
382 |
|
383 QMessageContentContainerId QMessage::bodyId() const |
|
384 { |
|
385 d_ptr->ensureBodyPresent(const_cast<QMessage*>(this)); |
|
386 return d_ptr->_bodyId; |
|
387 } |
|
388 |
|
389 void QMessage::setBody(const QString &bodyText, const QByteArray &mimeType) |
|
390 { |
|
391 QByteArray mainType("text"); |
|
392 QByteArray subType("plain"); |
|
393 QByteArray charset; |
|
394 |
|
395 int index = mimeType.indexOf("/"); |
|
396 if (index != -1) { |
|
397 mainType = mimeType.left(index).trimmed(); |
|
398 |
|
399 subType = mimeType.mid(index + 1).trimmed(); |
|
400 index = subType.indexOf(";"); |
|
401 if (index != -1) { |
|
402 QString remainder = subType.mid(index + 1); |
|
403 subType = subType.left(index).trimmed(); |
|
404 |
|
405 QRegExp charsetPattern("charset=(\\S+)"); |
|
406 index = charsetPattern.indexIn(remainder); |
|
407 if (index != -1) { |
|
408 charset = charsetPattern.cap(1).toLatin1(); |
|
409 } |
|
410 } |
|
411 } |
|
412 |
|
413 if (charset.isEmpty()) { |
|
414 charset = charsetFor(bodyText); |
|
415 } |
|
416 |
|
417 QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr); |
|
418 |
|
419 QMessageContentContainerId existingBodyId(bodyId()); |
|
420 if (existingBodyId.isValid()) { |
|
421 if (existingBodyId == container->bodyContentId()) { |
|
422 // The body content is in the message itself |
|
423 container->setContent(bodyText, mainType, subType, charset); |
|
424 } else { |
|
425 // The body content is in the first attachment |
|
426 QMessageContentContainerPrivate *attachmentContainer(container->attachment(existingBodyId)->d_ptr); |
|
427 attachmentContainer->setContent(bodyText, mainType, subType, charset); |
|
428 } |
|
429 } else { |
|
430 if (container->_attachments.isEmpty()) { |
|
431 // Put the content directly into the message |
|
432 container->setContent(bodyText, mainType, subType, charset); |
|
433 d_ptr->_bodyId = container->bodyContentId(); |
|
434 } else { |
|
435 // Add the body as the first attachment |
|
436 QMessageContentContainer newBody; |
|
437 newBody.d_ptr->setContent(bodyText, mainType, subType, charset); |
|
438 d_ptr->_bodyId = container->prependContent(newBody); |
|
439 } |
|
440 } |
|
441 } |
|
442 |
|
443 void QMessage::setBody(QTextStream &in, const QByteArray &mimeType) |
|
444 { |
|
445 setBody(in.readAll(), mimeType); |
|
446 } |
|
447 |
|
448 QMessageContentContainerIdList QMessage::attachmentIds() const |
|
449 { |
|
450 d_ptr->ensureAttachmentsPresent(const_cast<QMessage*>(this)); |
|
451 |
|
452 QMessageContentContainerIdList result; |
|
453 |
|
454 QMessageContentContainerId bodyId(bodyId()); |
|
455 foreach (const QMessageContentContainerId &contentId, contentIds()) { |
|
456 if (contentId != bodyId) { |
|
457 result.append(contentId); |
|
458 } |
|
459 } |
|
460 |
|
461 return result; |
|
462 } |
|
463 |
|
464 void QMessage::appendAttachments(const QStringList &fileNames) |
|
465 { |
|
466 if (!fileNames.isEmpty()) { |
|
467 d_ptr->_modified = true; |
|
468 |
|
469 QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr); |
|
470 |
|
471 if (container->_attachments.isEmpty()) { |
|
472 QMessageContentContainerId existingBodyId(bodyId()); |
|
473 if (existingBodyId == container->bodyContentId()) { |
|
474 // The body content is in the message itself - move it to become the first attachment |
|
475 QMessageContentContainer newBody(*this); |
|
476 newBody.setDerivedMessage(0); |
|
477 |
|
478 container->setContentType("multipart", "mixed", ""); |
|
479 d_ptr->_bodyId = container->prependContent(newBody); |
|
480 } else { |
|
481 // This message is now multipart |
|
482 container->setContentType("multipart", "mixed", ""); |
|
483 } |
|
484 |
|
485 container->_available = true; |
|
486 } |
|
487 |
|
488 foreach (const QString &filename, fileNames) { |
|
489 QMessageContentContainer attachment; |
|
490 if (attachment.d_ptr->createAttachment(filename)) { |
|
491 container->appendContent(attachment); |
|
492 } |
|
493 } |
|
494 |
|
495 bool haveAttachments = !container->_attachments.isEmpty(); |
|
496 setStatus(QMessage::HasAttachments,haveAttachments); |
|
497 } |
|
498 } |
|
499 |
|
500 void QMessage::clearAttachments() |
|
501 { |
|
502 d_ptr->_modified = true; |
|
503 |
|
504 QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr); |
|
505 container->_attachments.clear(); |
|
506 |
|
507 bool haveAttachments = !container->_attachments.isEmpty(); |
|
508 setStatus(QMessage::HasAttachments,haveAttachments); |
|
509 } |
|
510 |
|
511 bool QMessage::isModified() const |
|
512 { |
|
513 return d_ptr->_modified; |
|
514 } |
|
515 |
|
516 QMessage QMessage::createResponseMessage(ResponseType type) const |
|
517 { |
|
518 QMessage response; |
|
519 response.setType(this->type()); |
|
520 |
|
521 if (type == Forward) { |
|
522 response.setSubject("Fwd:" + subject()); |
|
523 |
|
524 if (contentType().toLower() == "text") { |
|
525 // Forward the text content inline |
|
526 QStringList addresses; |
|
527 foreach (const QMessageAddress &address, to()) { |
|
528 addresses.append(address.addressee()); |
|
529 } |
|
530 |
|
531 QString existingText(textContent()); |
|
532 |
|
533 QString prefix(QString("\r\n----- %1 -----\r\n\r\n").arg(qApp->translate("QMessage", "Forwarded Message"))); |
|
534 prefix.append(QString("%1: %2\r\n").arg(qApp->translate("QMessage", "Subject")).arg(subject())); |
|
535 prefix.append(QString("%1: %2\r\n").arg(qApp->translate("QMessage", "Date")).arg(date().toString())); |
|
536 prefix.append(QString("%1: %2\r\n").arg(qApp->translate("QMessage", "From")).arg(from().addressee())); |
|
537 prefix.append(QString("%1: %2\r\n").arg(qApp->translate("QMessage", "To")).arg(addresses.join(","))); |
|
538 |
|
539 QString postfix("\r\n\r\n-----------------------------\r\n"); |
|
540 |
|
541 response.setBody(prefix + existingText + postfix); |
|
542 } else { |
|
543 // Add an empty text body to be composed into |
|
544 response.setBody(QString(), "text/plain"); |
|
545 |
|
546 // We can only forward the original content if it is a single part |
|
547 if (contentType().toLower() != "multipart") { |
|
548 QByteArray fileName(suggestedFileName()); |
|
549 if (!fileName.isEmpty()) { |
|
550 // Write the content to a file that we can attach to our response |
|
551 QString path(QDir::tempPath() + "/qtmobility/messaging/" + fileName); |
|
552 if (QFile::exists(path)) { |
|
553 if (!QFile::remove(path)) { |
|
554 qWarning() << "Unable to remove temporary file:" << path; |
|
555 } |
|
556 } |
|
557 |
|
558 QFile out(path); |
|
559 if (!out.open(QFile::WriteOnly)) { |
|
560 qWarning() << "Unable to open temporary file:" << path; |
|
561 } else { |
|
562 out.write(content()); |
|
563 out.flush(); |
|
564 out.close(); |
|
565 } |
|
566 |
|
567 response.appendAttachments(QStringList() << path); |
|
568 } |
|
569 } |
|
570 } |
|
571 } else { |
|
572 // Prefer to reply to the trply-to address, if present |
|
573 QString replyTo(headerFieldValue("Reply-To")); |
|
574 if (!replyTo.isEmpty()) { |
|
575 response.setTo(QMessageAddressList() << QMessageAddress(QMessageAddress::Email, replyTo)); |
|
576 } else { |
|
577 response.setTo(QMessageAddressList() << from()); |
|
578 } |
|
579 |
|
580 if (type == ReplyToAll) { |
|
581 response.setCc(to() + cc()); |
|
582 } |
|
583 |
|
584 response.setSubject("Re:" + subject()); |
|
585 |
|
586 // Put the existing text into the reply body |
|
587 QString existingText; |
|
588 QMessageContentContainerIdList attachments; |
|
589 if (contentType().toLower() == "text") { |
|
590 existingText = textContent(); |
|
591 } else { |
|
592 QMessageContentContainerId textId(bodyId()); |
|
593 if (textId.isValid()) { |
|
594 existingText = find(textId).textContent(); |
|
595 } |
|
596 |
|
597 attachments = attachmentIds(); |
|
598 } |
|
599 |
|
600 if (!existingText.isEmpty()) { |
|
601 existingText = existingText.replace("\n", "\n> "); |
|
602 |
|
603 QString prefix(qApp->translate("QMessage", "On %1 you wrote:\n> ")); |
|
604 response.setBody(prefix.arg(date().toLocalTime().toString()) + existingText); |
|
605 } |
|
606 |
|
607 // Add any attachment parts as attachments |
|
608 QStringList attachmentPaths; |
|
609 foreach (const QMessageContentContainerId &attachmentId, attachments) { |
|
610 QMessageContentContainer attachment(find(attachmentId)); |
|
611 |
|
612 QByteArray fileName(attachment.suggestedFileName()); |
|
613 if (!fileName.isEmpty()) { |
|
614 QString path(QDir::tempPath() + "/qtmobility/messaging/" + fileName); |
|
615 if (QFile::exists(path)) { |
|
616 if (!QFile::remove(path)) { |
|
617 qWarning() << "Unable to remove temporary file:" << path; |
|
618 } |
|
619 } |
|
620 |
|
621 QString partialPath(QDir::tempPath() + "/qtmobility"); |
|
622 if (!QFile::exists(partialPath)) { |
|
623 if (!QDir::temp().mkdir("qtmobility")) { |
|
624 qWarning() << "Unable to create temporary directory:" << partialPath; |
|
625 } |
|
626 } |
|
627 partialPath.append("/messaging"); |
|
628 if (!QFile::exists(partialPath)) { |
|
629 if (!QDir(QDir::tempPath() + "/qtmobility").mkdir("messaging")) { |
|
630 qWarning() << "Unable to create temporary directory:" << partialPath; |
|
631 } |
|
632 } |
|
633 |
|
634 QFile out(path); |
|
635 if (!out.open(QFile::WriteOnly)) { |
|
636 qWarning() << "Unable to open temporary file:" << path; |
|
637 } else { |
|
638 out.write(attachment.content()); |
|
639 out.flush(); |
|
640 out.close(); |
|
641 |
|
642 attachmentPaths.append(path); |
|
643 } |
|
644 } |
|
645 } |
|
646 |
|
647 response.appendAttachments(attachmentPaths); |
|
648 } |
|
649 |
|
650 return response; |
|
651 } |
|
652 |
|
653 QTM_END_NAMESPACE |