13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include "emailtrace.h" |
|
19 |
18 #include "nmmessagepart.h" |
20 #include "nmmessagepart.h" |
19 #include "nmmessageenvelope.h" |
21 #include "nmmessageenvelope.h" |
20 |
22 |
21 |
23 |
22 /*! |
24 /*! |
23 Constructs message part private with null id |
25 Constructs message part private with null id |
24 */ |
26 */ |
25 NmMessagePartPrivate::NmMessagePartPrivate() |
27 NmMessagePartPrivate::NmMessagePartPrivate() |
26 : mPartId(0), mSize(0), mFetchedSize(0), |
28 : mPartId(0), mSize(0), mFetchedSize(0), |
27 mTextContent(0) |
29 mTextContent() |
28 { |
30 { |
|
31 NM_FUNCTION; |
29 } |
32 } |
30 |
33 |
31 /*! |
34 /*! |
32 Destructor of message part private |
35 Destructor of message part private |
33 */ |
36 */ |
34 NmMessagePartPrivate::~NmMessagePartPrivate() |
37 NmMessagePartPrivate::~NmMessagePartPrivate() |
35 { |
38 { |
|
39 NM_FUNCTION; |
36 } |
40 } |
37 |
41 |
38 /*! |
42 /*! |
39 Checks the content type for the message type |
43 Checks the content type for the message type |
40 @return bool result |
44 @return bool result |
41 */ |
45 */ |
42 bool NmMessagePartPrivate::isMessage() const |
46 bool NmMessagePartPrivate::isMessage() const |
43 { |
47 { |
|
48 NM_FUNCTION; |
|
49 |
44 bool isMessage = false; |
50 bool isMessage = false; |
45 if (!mContentType.isEmpty()) { |
51 if (!mContentType.isEmpty()) { |
46 if (mContentType.contains(NmContentTypeTypeMessage, Qt::CaseInsensitive)) { |
52 if (mContentType.contains(NmContentTypeTypeMessage, Qt::CaseInsensitive)) { |
47 isMessage = true; |
53 isMessage = true; |
48 } |
54 } |
75 /*! |
83 /*! |
76 Constructs message part with null id |
84 Constructs message part with null id |
77 */ |
85 */ |
78 NmMessagePart::NmMessagePart() |
86 NmMessagePart::NmMessagePart() |
79 { |
87 { |
|
88 NM_FUNCTION; |
|
89 |
80 d = new NmMessagePartPrivate(); |
90 d = new NmMessagePartPrivate(); |
81 } |
91 } |
82 |
92 |
83 /*! |
93 /*! |
84 Constructs message part with id \a id, parent id and mailbox id is set null |
94 Constructs message part with id \a id, parent id and mailbox id is set null |
85 */ |
95 */ |
86 NmMessagePart::NmMessagePart(const NmId &partId) |
96 NmMessagePart::NmMessagePart(const NmId &partId) |
87 { |
97 { |
|
98 NM_FUNCTION; |
|
99 |
88 d = new NmMessagePartPrivate(); |
100 d = new NmMessagePartPrivate(); |
89 d->mPartId = partId; |
101 d->mPartId = partId; |
90 } |
102 } |
91 |
103 |
92 /*! |
104 /*! |
93 Constructs new NmMessagePart object from private message part data |
105 Constructs new NmMessagePart object from private message part data |
94 */ |
106 */ |
95 NmMessagePart::NmMessagePart( |
107 NmMessagePart::NmMessagePart( |
96 QExplicitlySharedDataPointer<NmMessagePartPrivate> nmPrivateMessagePart) |
108 QExplicitlySharedDataPointer<NmMessagePartPrivate> nmPrivateMessagePart) |
97 { |
109 { |
|
110 NM_FUNCTION; |
|
111 |
98 d = nmPrivateMessagePart; |
112 d = nmPrivateMessagePart; |
99 } |
113 } |
100 |
114 |
101 /*! |
115 /*! |
102 Copy constructor |
116 Copy constructor |
103 */ |
117 */ |
104 NmMessagePart::NmMessagePart(const NmMessagePart &part) : d(part.d) |
118 NmMessagePart::NmMessagePart(const NmMessagePart &part) : d(part.d) |
105 { |
119 { |
|
120 NM_FUNCTION; |
106 } |
121 } |
107 |
122 |
108 /*! |
123 /*! |
109 Assignment operator |
124 Assignment operator |
110 */ |
125 */ |
111 NmMessagePart &NmMessagePart::operator=(const NmMessagePart &part) |
126 NmMessagePart &NmMessagePart::operator=(const NmMessagePart &part) |
112 { |
127 { |
|
128 NM_FUNCTION; |
|
129 |
113 if (this != &part) { |
130 if (this != &part) { |
114 d = part.d; |
131 d = part.d; |
115 } |
132 } |
116 return *this; |
133 return *this; |
117 } |
134 } |
130 /*! |
149 /*! |
131 Retruns id of message part |
150 Retruns id of message part |
132 */ |
151 */ |
133 NmId NmMessagePart::partId() const |
152 NmId NmMessagePart::partId() const |
134 { |
153 { |
|
154 NM_FUNCTION; |
|
155 |
135 return d->mPartId; |
156 return d->mPartId; |
136 } |
157 } |
137 |
158 |
138 /*! |
159 /*! |
139 Sets id of message part from \a id |
160 Sets id of message part from \a id |
140 */ |
161 */ |
141 void NmMessagePart::setPartId(const NmId &id) |
162 void NmMessagePart::setPartId(const NmId &id) |
142 { |
163 { |
|
164 NM_FUNCTION; |
|
165 |
143 d->mPartId = id; |
166 d->mPartId = id; |
144 } |
167 } |
145 |
168 |
146 /*! |
169 /*! |
147 Returns message part size in bytes |
170 Returns message part size in bytes |
148 */ |
171 */ |
149 quint32 NmMessagePart::size() const |
172 quint32 NmMessagePart::size() const |
150 { |
173 { |
|
174 NM_FUNCTION; |
|
175 |
151 return d->mSize; |
176 return d->mSize; |
152 } |
177 } |
153 |
178 |
154 /*! |
179 /*! |
155 Sets message part size, \a size should be in bytes |
180 Sets message part size, \a size should be in bytes |
156 */ |
181 */ |
157 void NmMessagePart::setSize(quint32 size) |
182 void NmMessagePart::setSize(quint32 size) |
158 { |
183 { |
|
184 NM_FUNCTION; |
|
185 |
159 d->mSize = size; |
186 d->mSize = size; |
160 } |
187 } |
161 |
188 |
162 /*! |
189 /*! |
163 Returns fetched size of message part in bytes |
190 Returns fetched size of message part in bytes |
164 */ |
191 */ |
165 quint32 NmMessagePart::fetchedSize() const |
192 quint32 NmMessagePart::fetchedSize() const |
166 { |
193 { |
|
194 NM_FUNCTION; |
|
195 |
167 return d->mFetchedSize; |
196 return d->mFetchedSize; |
168 } |
197 } |
169 |
198 |
170 /*! |
199 /*! |
171 Sets fetched size of message part, \a fetchedSize should be in bytes |
200 Sets fetched size of message part, \a fetchedSize should be in bytes |
172 */ |
201 */ |
173 void NmMessagePart::setFetchedSize(quint32 fetchedSize) |
202 void NmMessagePart::setFetchedSize(quint32 fetchedSize) |
174 { |
203 { |
|
204 NM_FUNCTION; |
|
205 |
175 d->mFetchedSize = fetchedSize; |
206 d->mFetchedSize = fetchedSize; |
176 } |
207 } |
177 |
208 |
178 /*! |
209 /*! |
179 Returns true if message part contains mail message (message-in-message) |
210 Returns true if message part contains mail message (message-in-message) |
180 */ |
211 */ |
181 bool NmMessagePart::isMessage() const |
212 bool NmMessagePart::isMessage() const |
182 { |
213 { |
|
214 NM_FUNCTION; |
|
215 |
183 return d->isMessage(); |
216 return d->isMessage(); |
184 } |
217 } |
185 |
218 |
186 /*! |
219 /*! |
187 Sets textual content to part, \a contentType must be rfc 2045 (MIME) style |
220 Sets textual content to part, \a contentType must be rfc 2045 (MIME) style |
189 */ |
222 */ |
190 void NmMessagePart::setTextContent( |
223 void NmMessagePart::setTextContent( |
191 const QString &content, |
224 const QString &content, |
192 const QString &contentType) |
225 const QString &contentType) |
193 { |
226 { |
|
227 NM_FUNCTION; |
|
228 |
194 d->mTextContent = content; |
229 d->mTextContent = content; |
195 d->mContentType = contentType; |
230 d->mContentType = contentType; |
196 d->mBinaryContent.clear(); |
231 d->mBinaryContent.clear(); |
197 } |
232 } |
198 |
233 |
199 /*! |
234 /*! |
200 Returns reference to text content. |
235 Returns reference to text content. |
201 */ |
236 */ |
202 const QString &NmMessagePart::textContent() const |
237 const QString &NmMessagePart::textContent() const |
203 { |
238 { |
|
239 NM_FUNCTION; |
|
240 |
204 return d->mTextContent; |
241 return d->mTextContent; |
205 } |
242 } |
206 |
243 |
207 /*! |
244 /*! |
208 Sets content type string, \a contentType must be rfc 2045 (MIME) style |
245 Sets content type string, \a contentType must be rfc 2045 (MIME) style |
209 string eg. "multipart/mixed" |
246 string eg. "multipart/mixed" |
210 */ |
247 */ |
211 void NmMessagePart::setContentType(const QString &contentType) |
248 void NmMessagePart::setContentType(const QString &contentType) |
212 { |
249 { |
|
250 NM_FUNCTION; |
|
251 |
213 d->mContentType = contentType; |
252 d->mContentType = contentType; |
214 } |
253 } |
215 |
254 |
216 /*! |
255 /*! |
217 Returns rfc 2045 (MIME) style content type string of message part |
256 Returns rfc 2045 (MIME) style content type string of message part |
218 */ |
257 */ |
219 QString NmMessagePart::contentType() const |
258 QString NmMessagePart::contentType() const |
220 { |
259 { |
|
260 NM_FUNCTION; |
|
261 |
221 return d->mContentType; |
262 return d->mContentType; |
222 } |
263 } |
223 |
264 |
224 /*! |
265 /*! |
225 Sets rfc 2045 (MIME) content description string |
266 Sets rfc 2045 (MIME) content description string |
226 */ |
267 */ |
227 void NmMessagePart::setContentDescription(const QString &contentDescription) |
268 void NmMessagePart::setContentDescription(const QString &contentDescription) |
228 { |
269 { |
|
270 NM_FUNCTION; |
|
271 |
229 d->mContentDescription = contentDescription; |
272 d->mContentDescription = contentDescription; |
230 } |
273 } |
231 |
274 |
232 /*! |
275 /*! |
233 Returns rfc 2045 (MIME) content description string |
276 Returns rfc 2045 (MIME) content description string |
234 */ |
277 */ |
235 QString NmMessagePart::contentDescription() const |
278 QString NmMessagePart::contentDescription() const |
236 { |
279 { |
|
280 NM_FUNCTION; |
|
281 |
237 return d->mContentDescription; |
282 return d->mContentDescription; |
238 } |
283 } |
239 |
284 |
240 /*! |
285 /*! |
241 Sets rfc 2045 (MIME) content disposition string |
286 Sets rfc 2045 (MIME) content disposition string |
242 */ |
287 */ |
243 void NmMessagePart::setContentDisposition(const QString &contentDisposition) |
288 void NmMessagePart::setContentDisposition(const QString &contentDisposition) |
244 { |
289 { |
|
290 NM_FUNCTION; |
|
291 |
245 d->mContentDisposition = contentDisposition; |
292 d->mContentDisposition = contentDisposition; |
246 } |
293 } |
247 |
294 |
248 /*! |
295 /*! |
249 Returns rfc 2045 (MIME) content disposition string |
296 Returns rfc 2045 (MIME) content disposition string |
250 */ |
297 */ |
251 QString NmMessagePart::contentDisposition() const |
298 QString NmMessagePart::contentDisposition() const |
252 { |
299 { |
|
300 NM_FUNCTION; |
|
301 |
253 return d->mContentDisposition; |
302 return d->mContentDisposition; |
254 } |
303 } |
255 |
304 |
256 /*! |
305 /*! |
257 Sets rfc 2045 (MIME) content id string |
306 Sets rfc 2045 (MIME) content id string |
258 */ |
307 */ |
259 void NmMessagePart::setContentId(const QString &contentId) |
308 void NmMessagePart::setContentId(const QString &contentId) |
260 { |
309 { |
|
310 NM_FUNCTION; |
|
311 |
261 d->mContentId = contentId; |
312 d->mContentId = contentId; |
262 } |
313 } |
263 |
314 |
264 /*! |
315 /*! |
265 Returns rfc 2045 (MIME) content id string |
316 Returns rfc 2045 (MIME) content id string |
266 */ |
317 */ |
267 QString NmMessagePart::contentId() |
318 QString NmMessagePart::contentId() |
268 { |
319 { |
|
320 NM_FUNCTION; |
|
321 |
269 return d->mContentId; |
322 return d->mContentId; |
270 } |
323 } |
271 |
324 |
272 /*! |
325 /*! |
273 Sets list of child message part. Ownership of part objects is transferred |
326 Sets list of child message part. Ownership of part objects is transferred |
274 to this part object and child parts are deleted when this part is deleted |
327 to this part object and child parts are deleted when this part is deleted |
275 */ |
328 */ |
276 void NmMessagePart::setChildParts(QList<NmMessagePart*> parts) |
329 void NmMessagePart::setChildParts(QList<NmMessagePart*> parts) |
277 { |
330 { |
278 |
331 NM_FUNCTION; |
|
332 |
279 if (d->mChildParts.count() > 0) { |
333 if (d->mChildParts.count() > 0) { |
280 for (int i = 0; i < d->mChildParts.count(); i++) { |
334 for (int i = 0; i < d->mChildParts.count(); i++) { |
281 delete d->mChildParts[i]; |
335 delete d->mChildParts[i]; |
282 } |
336 } |
283 d->mChildParts.clear(); |
337 d->mChildParts.clear(); |
341 */ |
403 */ |
342 void NmMessagePart::setBinaryContent( |
404 void NmMessagePart::setBinaryContent( |
343 const QByteArray &content, |
405 const QByteArray &content, |
344 const QString &contentType) |
406 const QString &contentType) |
345 { |
407 { |
|
408 NM_FUNCTION; |
|
409 |
346 d->mBinaryContent = content; |
410 d->mBinaryContent = content; |
347 d->mContentType = contentType; |
411 d->mContentType = contentType; |
348 d->mTextContent.clear(); |
412 d->mTextContent.clear(); |
349 } |
413 } |
350 |
414 |
351 /*! |
415 /*! |
352 Returns reference to binary content. |
416 Returns reference to binary content. |
353 */ |
417 */ |
354 const QByteArray &NmMessagePart::binaryContent() const |
418 const QByteArray &NmMessagePart::binaryContent() const |
355 { |
419 { |
|
420 NM_FUNCTION; |
|
421 |
356 return d->mBinaryContent; |
422 return d->mBinaryContent; |
357 } |
423 } |
358 |
424 |
359 /** |
425 /** |
360 * Sets attachment name for email part. Full path can be |
426 * Sets attachment name for email part. Full path can be |
362 * |
428 * |
363 * @param filePath attachment name |
429 * @param filePath attachment name |
364 */ |
430 */ |
365 void NmMessagePart::setAttachmentName(const QString &filePath) |
431 void NmMessagePart::setAttachmentName(const QString &filePath) |
366 { |
432 { |
|
433 NM_FUNCTION; |
|
434 |
367 Q_UNUSED(filePath); |
435 Q_UNUSED(filePath); |
368 } |
436 } |
369 |
437 |
370 /*! |
438 /*! |
371 * returns email part attachment name |
439 * returns email part attachment name |
372 * @return attachment name |
440 * @return attachment name |
373 */ |
441 */ |
374 QString NmMessagePart::attachmentName() const |
442 QString NmMessagePart::attachmentName() const |
375 { |
443 { |
|
444 NM_FUNCTION; |
|
445 |
376 // Look first from Content-Type param "name" |
446 // Look first from Content-Type param "name" |
377 QString content = contentType(); |
447 QString content = contentType(); |
378 int ptr = content.indexOf(NmContentTypeParamName); |
448 int ptr = content.indexOf(NmContentTypeParamName); |
379 if(ptr >= 0) { |
449 if(ptr >= 0) { |
380 d->mAttachmentName = content.section('"',1,1); |
450 d->mAttachmentName = content.section('"',1,1); |