emailservices/nmailbase/src/nmmessagepart.cpp
changeset 43 99bcbff212ad
parent 23 2dc6caa42ec3
child 66 084b5b1f02a7
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    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     	}
    54     Checks the content type for the text type
    60     Checks the content type for the text type
    55     @return bool result
    61     @return bool result
    56  */
    62  */
    57 bool NmMessagePartPrivate::isTextContent() const
    63 bool NmMessagePartPrivate::isTextContent() const
    58 {
    64 {
       
    65     NM_FUNCTION;
       
    66     
    59 	bool isText = false;
    67 	bool isText = false;
    60 	if (!mContentType.isEmpty()) {
    68 	if (!mContentType.isEmpty()) {
    61 		if (mContentType.contains(NmContentTypeTextPlain, Qt::CaseInsensitive) ||
    69 		if (mContentType.contains(NmContentTypeTextPlain, Qt::CaseInsensitive) ||
    62 				mContentType.contains(NmContentTypeTextHtml, Qt::CaseInsensitive)) {
    70 				mContentType.contains(NmContentTypeTextHtml, Qt::CaseInsensitive)) {
    63 			isText = true;
    71 			isText = true;
    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 }
   119 /*!
   136 /*!
   120     Destructor of message part
   137     Destructor of message part
   121  */
   138  */
   122 NmMessagePart::~NmMessagePart()
   139 NmMessagePart::~NmMessagePart()
   123 {
   140 {
       
   141     NM_FUNCTION;
       
   142     
   124 	for (int i = 0; i < d->mChildParts.count(); i++) {
   143 	for (int i = 0; i < d->mChildParts.count(); i++) {
   125 		delete d->mChildParts[i];
   144 		delete d->mChildParts[i];
   126 	}
   145 	}
   127 	d->mChildParts.clear();
   146 	d->mChildParts.clear();
   128 }
   147 }
   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();
   293     Returns reference to child part list. NOTE: child part objects are
   347     Returns reference to child part list. NOTE: child part objects are
   294     modifiable
   348     modifiable
   295  */
   349  */
   296 QList<NmMessagePart*>& NmMessagePart::childParts() const
   350 QList<NmMessagePart*>& NmMessagePart::childParts() const
   297 {
   351 {
       
   352     NM_FUNCTION;
       
   353     
   298     return d->mChildParts;
   354     return d->mChildParts;
   299 }
   355 }
   300 
   356 
   301 /*!
   357 /*!
   302     Adds one child part obeject end of child parts list. Ownership of part object
   358     Adds one child part obeject end of child parts list. Ownership of part object
   303     is transferred to this part and part object is deleted in this part's
   359     is transferred to this part and part object is deleted in this part's
   304     destructor
   360     destructor
   305  */
   361  */
   306 void NmMessagePart::addChildPart(NmMessagePart *part)
   362 void NmMessagePart::addChildPart(NmMessagePart *part)
   307 {
   363 {
       
   364     NM_FUNCTION;
       
   365     
   308     if (!part) {
   366     if (!part) {
   309         return;
   367         return;
   310     }
   368     }
   311     d->mChildParts.append(part);
   369     d->mChildParts.append(part);
   312 }
   370 }
   315     Removes and deletes child part which id is \a partId. If id is not found
   373     Removes and deletes child part which id is \a partId. If id is not found
   316     simply returns
   374     simply returns
   317  */
   375  */
   318 void NmMessagePart::removeChildPart(const NmId &partId)
   376 void NmMessagePart::removeChildPart(const NmId &partId)
   319 {
   377 {
       
   378     NM_FUNCTION;
       
   379     
   320     for (int i = 0; i < d->mChildParts.count(); i++) {
   380     for (int i = 0; i < d->mChildParts.count(); i++) {
   321         if (d->mChildParts[i]->partId() == partId) {
   381         if (d->mChildParts[i]->partId() == partId) {
   322             delete d->mChildParts[i];
   382             delete d->mChildParts[i];
   323             d->mChildParts.removeAt(i);
   383             d->mChildParts.removeAt(i);
   324             return;
   384             return;
   329 /*!
   389 /*!
   330     Removes and deletes all child part.
   390     Removes and deletes all child part.
   331  */
   391  */
   332 void NmMessagePart::removeAllChildParts()
   392 void NmMessagePart::removeAllChildParts()
   333 {
   393 {
       
   394     NM_FUNCTION;
       
   395     
   334     while (!d->mChildParts.isEmpty()) {
   396     while (!d->mChildParts.isEmpty()) {
   335         delete d->mChildParts.takeFirst();
   397         delete d->mChildParts.takeFirst();
   336     }
   398     }
   337 }
   399 }
   338 
   400 
   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);
   398 /*!
   468 /*!
   399     Recursive child part finder for NmMessage class (non-modifying).
   469     Recursive child part finder for NmMessage class (non-modifying).
   400  */
   470  */
   401 const NmMessagePart *NmMessagePart::findContentPart(const QString &contentType) const
   471 const NmMessagePart *NmMessagePart::findContentPart(const QString &contentType) const
   402 {
   472 {
       
   473     NM_FUNCTION;
       
   474     
   403     const NmMessagePart *ret = NULL;
   475     const NmMessagePart *ret = NULL;
   404 
   476 
   405     if (!d->mContentType.isEmpty() && d->mContentType.startsWith(contentType)) {
   477     if (!d->mContentType.isEmpty() && d->mContentType.startsWith(contentType)) {
   406         ret = this;
   478         ret = this;
   407     } else {
   479     } else {
   415 /*!
   487 /*!
   416     Recursive child part finder for NmMessage class
   488     Recursive child part finder for NmMessage class
   417  */
   489  */
   418 NmMessagePart *NmMessagePart::findContentPart(const QString &contentType)
   490 NmMessagePart *NmMessagePart::findContentPart(const QString &contentType)
   419 {
   491 {
       
   492     NM_FUNCTION;
       
   493     
   420     NmMessagePart *ret = NULL;
   494     NmMessagePart *ret = NULL;
   421 
   495 
   422     if (!d->mContentType.isEmpty() && d->mContentType.startsWith(contentType)) {
   496     if (!d->mContentType.isEmpty() && d->mContentType.startsWith(contentType)) {
   423         ret = this;
   497         ret = this;
   424     } else {
   498     } else {
   434  * 
   508  * 
   435  * @param email part list given/owned by user
   509  * @param email part list given/owned by user
   436  */
   510  */
   437 void NmMessagePart::appendAttachments(QList<NmMessagePart*> &attachments) const
   511 void NmMessagePart::appendAttachments(QList<NmMessagePart*> &attachments) const
   438 {
   512 {
       
   513     NM_FUNCTION;
       
   514     
   439     QList<NmMessagePart*> messageParts = childParts();
   515     QList<NmMessagePart*> messageParts = childParts();
   440 
   516 
   441     int messagePartCount = messageParts.count();
   517     int messagePartCount = messageParts.count();
   442     for ( int i = 0; i < messagePartCount; i++ ) {
   518     for ( int i = 0; i < messagePartCount; i++ ) {
   443         QString contentType = messageParts[i]->contentType();
   519         QString contentType = messageParts[i]->contentType();