emailservices/nmailagent/src/nmmailagent.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    17 
    17 
    18 #include "nmmailagentheaders.h"
    18 #include "nmmailagentheaders.h"
    19 #include "nmmailagent.h"
    19 #include "nmmailagent.h"
    20 
    20 
    21 // CONSTS
    21 // CONSTS
    22 const int NmAgentMaxUnreadCount = 1; // 1 is enough
       
    23 const int NmAgentIndicatorNotSet = -1;
    22 const int NmAgentIndicatorNotSet = -1;
       
    23 const int NmAgentAlertToneTimer = 60000; // 60s
    24 
    24 
    25 
    25 
    26 /*!
    26 /*!
    27     \class NmMailAgent
    27     \class NmMailAgent
    28 
    28 
    33 {
    33 {
    34     mId = 0;
    34     mId = 0;
    35     mIndicatorIndex = NmAgentIndicatorNotSet;
    35     mIndicatorIndex = NmAgentIndicatorNotSet;
    36     mSyncState = SyncComplete;
    36     mSyncState = SyncComplete;
    37     mConnectState = Disconnected;
    37     mConnectState = Disconnected;
    38     mUnreadMails = 0;
       
    39     mOutboxMails = 0;
    38     mOutboxMails = 0;
    40     mInboxFolderId = 0;
    39     mInboxFolderId = 0;
    41     mOutboxFolderId = 0;
    40     mOutboxFolderId = 0;
    42     mInboxCreatedMessages = 0;
    41     mInboxCreatedMessages = 0;
    43     mInboxChangedMessages = 0;
    42     mInboxChangedMessages = 0;
    45     mActive = false;
    44     mActive = false;
    46 }
    45 }
    47 
    46 
    48 NmMailAgent::NmMailAgent() :
    47 NmMailAgent::NmMailAgent() :
    49  mPluginFactory(NULL),
    48  mPluginFactory(NULL),
    50  mSendingState(false)
    49  mSendingState(false),
       
    50  mAlertToneAllowed(true)
    51 {
    51 {
    52     NMLOG("NmMailAgent::NmMailAgent");
    52     NMLOG("NmMailAgent::NmMailAgent");
    53 }
    53 }
    54 
    54 
    55 /*!
    55 /*!
   137         while (i.hasPrevious()) {
   137         while (i.hasPrevious()) {
   138             const NmMailbox *mailbox = i.previous();
   138             const NmMailbox *mailbox = i.previous();
   139             if (mailbox) {
   139             if (mailbox) {
   140                 NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox,plugin);
   140                 NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox,plugin);
   141                 if (mailboxInfo) {
   141                 if (mailboxInfo) {
   142                     mailboxInfo->mUnreadMails = getUnreadCount(mailbox->id(),NmAgentMaxUnreadCount);
   142                     bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo);
   143                     mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id());
   143                     mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id());
       
   144                     if (mailboxInfo->mOutboxMails > 0) {
       
   145                         activate = true;
       
   146                     }
   144 
   147 
   145                     // Create indicator for visible mailboxes
   148                     // Create indicator for visible mailboxes
   146                     updateMailboxState(mailbox->id(),
   149                     updateMailboxState(mailbox->id(),
   147                         isMailboxActive(*mailboxInfo),
   150                         activate, false);
   148                         false);
       
   149                 }
   151                 }
   150             }
   152             }
   151         }
   153         }
   152         qDeleteAll(mailboxes);
   154         qDeleteAll(mailboxes);
   153     }
   155     }
   154 }
   156 }
   155 
   157 
   156 /*!
   158 /*!
   157     Get mailbox unread count in inbox folder
   159     Get mailbox unread count in inbox folder
   158     \param mailboxId id of the mailbox
   160     \param mailboxId id of the mailbox
   159     \param maxCount max number of unread mails that is needed
   161     \param mailboxInfo contains the list of unread messages
   160     \return number of unread mails in the mailbox
   162     \return true if new unread mails was found
   161 */
   163 */
   162 int NmMailAgent::getUnreadCount(const NmId &mailboxId, int maxCount)
   164 bool NmMailAgent::updateUnreadCount(const NmId &mailboxId, NmMailboxInfo &mailboxInfo)
   163 {
   165 {
   164     NMLOG("NmMailAgent::getUnreadCount");
   166     NMLOG("NmMailAgent::getUnreadCount");
   165     int count(0);
   167     int newUnreadMessages(0);
   166 
   168 
   167     NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
   169     NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
   168 
   170 
   169     if (plugin) {
   171     if (plugin) {
   170 		// get inbox folder ID
   172 		// get inbox folder ID
   173 
   175 
   174 		// get list of messages in inbox
   176 		// get list of messages in inbox
   175 		QList<NmMessageEnvelope*> messageList;
   177 		QList<NmMessageEnvelope*> messageList;
   176 		plugin->listMessages(mailboxId, inboxId, messageList);
   178 		plugin->listMessages(mailboxId, inboxId, messageList);
   177 
   179 
       
   180 		QList<NmId> newUnreadMessageIdList;
   178 		foreach (const NmMessageEnvelope* envelope, messageList) {
   181 		foreach (const NmMessageEnvelope* envelope, messageList) {
   179 			// if the message is not read, it is "unread"
   182 		    // if the message is not read, it is "unread"
   180 			if (!envelope->isRead()) {
   183 			if (!envelope->isRead()) {
   181 				count++;
   184 		        quint64 messageId = envelope->messageId().id();
   182 
   185 			    newUnreadMessageIdList.append(envelope->messageId());
   183 				// No more unread mails are needed
   186 			    bool found(false);
   184 				if (count >= maxCount) {
   187 			    // Iterate through all known ids. If the id can't be found the mail is new.
   185 					break;
   188 			    foreach (const NmId id, mailboxInfo.mUnreadMailIdList) {
   186 				}
   189 			        if (id.id() == messageId) {
       
   190 			            found = true;
       
   191 			            break;
       
   192 			        }
       
   193 			    }
       
   194 
       
   195 			    if (!found) {
       
   196 			        newUnreadMessages++;
       
   197 			    }
   187 			}
   198 			}
   188 		}
   199 		}
   189 		qDeleteAll(messageList);
   200 		qDeleteAll(messageList);
   190     }
   201 
   191 	NMLOG(QString("NmMailAgent::getUnreadCount count=%1").arg(count));
   202 		// Save updated list of unread message IDs
   192 
   203         mailboxInfo.mUnreadMailIdList = newUnreadMessageIdList;
   193     return count;
   204     }
       
   205 	NMLOG(QString("NmMailAgent::getUnreadCount count=%1 new=%2").
       
   206 	    arg(mailboxInfo.mUnreadMailIdList.count()).arg(newUnreadMessages));
       
   207 
       
   208     return (newUnreadMessages > 0);
   194 }
   209 }
   195 
   210 
   196 /*!
   211 /*!
   197     Get mailbox count in outbox folder
   212     Get mailbox count in outbox folder
   198     \param mailboxId id of the mailbox
   213     \param mailboxId id of the mailbox
   264     }
   279     }
   265     return changed;
   280     return changed;
   266 }
   281 }
   267 
   282 
   268 /*!
   283 /*!
   269     Check if the mailbox indicator should be active, according to current state
       
   270     \param mailboxInfo information of the mailbox
       
   271     \return true if indicator should be now active
       
   272 */
       
   273 bool NmMailAgent::isMailboxActive(const NmMailboxInfo& mailboxInfo)
       
   274 {
       
   275     if (mailboxInfo.mUnreadMails>0 || mailboxInfo.mOutboxMails>0) {
       
   276         return true;
       
   277     }
       
   278     return false;
       
   279 }
       
   280 
       
   281 /*!
       
   282     Updates indicator status
   284     Updates indicator status
   283     \param mailboxIndex index of the item shown in indicator menu
   285     \param mailboxIndex index of the item shown in indicator menu
   284     \param active indicator visibility state
   286     \param active indicator visibility state
   285     \param mailboxInfo information of the mailbox
   287     \param mailboxInfo information of the mailbox
   286     \return true if indicator was updated with no errors
   288     \return true if indicator was updated with no errors
   287 */
   289 */
   288 bool NmMailAgent::updateIndicator(bool active,
   290 bool NmMailAgent::updateIndicator(bool active,
   289     const NmMailboxInfo& mailboxInfo)
   291     const NmMailboxInfo& mailboxInfo)
   290 {
   292 {
   291     NMLOG(QString("NmMailAgent::updateIndicator index=%1 active=%2 unread=%3").
   293     NMLOG(QString("NmMailAgent::updateIndicator index=%1 active=%2").
   292         arg(mailboxInfo.mIndicatorIndex).arg(active).arg(mailboxInfo.mUnreadMails));
   294         arg(mailboxInfo.mIndicatorIndex).arg(active));
   293 
   295 
   294     bool ok = false;
   296     bool ok = false;
   295     QString name = QString("com.nokia.nmail.indicatorplugin_%1/1.0").
   297     QString name = QString("com.nokia.nmail.indicatorplugin_%1/1.0").
   296         arg(mailboxInfo.mIndicatorIndex);
   298         arg(mailboxInfo.mIndicatorIndex);
   297 
   299 
   298     QList<QVariant> list;
   300     QList<QVariant> list;
   299     list.append(mailboxInfo.mId.id());
   301     list.append(mailboxInfo.mId.id());
   300     list.append(mailboxInfo.mName);
   302     list.append(mailboxInfo.mName);
   301     list.append(mailboxInfo.mUnreadMails);
   303     list.append(mailboxInfo.mUnreadMailIdList.count());
   302     list.append(mailboxInfo.mSyncState);
   304     list.append(mailboxInfo.mSyncState);
   303     list.append(mailboxInfo.mConnectState);
   305     list.append(mailboxInfo.mConnectState);
   304     list.append(mailboxInfo.mOutboxMails);
   306     list.append(mailboxInfo.mOutboxMails);
       
   307     list.append(mailboxInfo.mIconName);
   305     list.append(mSendingState);
   308     list.append(mSendingState);
   306 
   309 
   307     HbIndicator indicator;
   310     HbIndicator indicator;
   308     if (active) {
   311     if (active) {
   309         ok = indicator.activate(name,list);
   312         ok = indicator.activate(name,list);
   394             const QList<NmId> &messageIds,
   397             const QList<NmId> &messageIds,
   395             const NmId& mailboxId)
   398             const NmId& mailboxId)
   396 {
   399 {
   397     NMLOG(QString("NmMailAgent::handleMessageEvent %1 %2").arg(event).arg(mailboxId.id()));
   400     NMLOG(QString("NmMailAgent::handleMessageEvent %1 %2").arg(event).arg(mailboxId.id()));
   398     bool updateNeeded = false;
   401     bool updateNeeded = false;
       
   402     bool activate = false;
   399 
   403 
   400     switch (event) {
   404     switch (event) {
   401         case NmMessageCreated: {
   405         case NmMessageCreated: {
   402             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   406             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   403             
   407 
       
   408             // Check the new messages to make the indicator appear earlier
       
   409             if (mailboxInfo->mSyncState == Synchronizing &&
       
   410                 mailboxInfo->mUnreadMailIdList.count()==0) {
       
   411 
       
   412                 // Inbox folder ID may be still unknown
       
   413                 if (mailboxInfo->mInboxFolderId.id()==0) {
       
   414                     NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
       
   415                     if (plugin) {
       
   416                         mailboxInfo->mInboxFolderId =
       
   417                             plugin->getStandardFolderId(mailboxId, NmFolderInbox);
       
   418                     }
       
   419                 }
       
   420 
       
   421                 if (folderId == mailboxInfo->mInboxFolderId) {
       
   422                     bool messageUnread = false;
       
   423                     foreach (NmId messageId, messageIds) {
       
   424                         if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
       
   425                             if (messageUnread) {
       
   426                                 mailboxInfo->mUnreadMailIdList.append(messageId);
       
   427                                 updateMailboxState(mailboxId, true, false);
       
   428                             }
       
   429                         }
       
   430                     }
       
   431                 }
       
   432             }
   404             if (folderId==mailboxInfo->mInboxFolderId) {
   433             if (folderId==mailboxInfo->mInboxFolderId) {
   405                 mailboxInfo->mInboxCreatedMessages++;
   434                 mailboxInfo->mInboxCreatedMessages++;
   406             }
   435             }
   407             
   436 
   408             // When created a new mail in the outbox, we are in sending state
   437             // When created a new mail in the outbox, we are in sending state
   409             if (mailboxInfo->mOutboxFolderId == folderId) {
   438             if (mailboxInfo->mOutboxFolderId == folderId) {
   410                 // The first mail created in the outbox
   439                 // The first mail created in the outbox
   411                 if (mailboxInfo->mOutboxMails <= 0) {
   440                 if (mailboxInfo->mOutboxMails <= 0) {
   412                     updateNeeded = true;
   441                     updateNeeded = true;
   415             }
   444             }
   416             break;
   445             break;
   417         }
   446         }
   418         case NmMessageChanged: {
   447         case NmMessageChanged: {
   419             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   448             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   420             
   449 
   421             if (folderId==mailboxInfo->mInboxFolderId) {
   450             if (folderId==mailboxInfo->mInboxFolderId) {
   422                 mailboxInfo->mInboxChangedMessages++;
   451                 mailboxInfo->mInboxChangedMessages++;
   423             }
   452             }
   424             
   453 
   425             // If not currently syncronizing the mailbox, this may mean
   454             // If not currently syncronizing the mailbox, this may mean
   426             // that a message was read/unread
   455             // that a message was read/unread
   427             if (mailboxInfo && mailboxInfo->mSyncState==SyncComplete) {
   456             if (mailboxInfo && mailboxInfo->mSyncState==SyncComplete) {
   428                 // check the unread status again
   457                 // check the unread status again
   429                 mailboxInfo->mUnreadMails = getUnreadCount(mailboxId,NmAgentMaxUnreadCount);
   458                 int oldCount = mailboxInfo->mUnreadMailIdList.count();
   430                 updateNeeded = true;
   459                 activate = updateUnreadCount(mailboxId, *mailboxInfo);
       
   460 
       
   461                 // new unread mails found or no more unread mails in the mailbox
       
   462                 if (activate || (oldCount>0 && mailboxInfo->mUnreadMailIdList.count()==0)) {
       
   463                     updateNeeded = true;
       
   464                 }
   431             }
   465             }
   432 			break;
   466 			break;
   433 		}
   467 		}
   434         case NmMessageDeleted: {
   468         case NmMessageDeleted: {
   435             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   469             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   436 
   470 
   437             if (folderId==mailboxInfo->mInboxFolderId) {
   471             if (folderId==mailboxInfo->mInboxFolderId) {
   438                 mailboxInfo->mInboxDeletedMessages++;
   472                 mailboxInfo->mInboxDeletedMessages++;
   439             }
   473             }
   440             
   474 
   441             // Deleted mails from the outbox
   475             // Deleted mails from the outbox
   442             if (mailboxInfo->mOutboxFolderId == folderId) {
   476             if (mailboxInfo->mOutboxFolderId == folderId) {
   443                 mailboxInfo->mOutboxMails -= messageIds.count();
   477                 mailboxInfo->mOutboxMails -= messageIds.count();
   444 
   478 
   445                 // Sanity check for the outbox count
   479                 // Sanity check for the outbox count
   447                     mailboxInfo->mOutboxMails = 0;
   481                     mailboxInfo->mOutboxMails = 0;
   448                 }
   482                 }
   449 
   483 
   450                 // The last mail was now deleted
   484                 // The last mail was now deleted
   451                 if (mailboxInfo->mOutboxMails == 0) {
   485                 if (mailboxInfo->mOutboxMails == 0) {
       
   486                     // Keep it active if there is unread mails
       
   487                     activate = mailboxInfo->mUnreadMailIdList.count() > 0;
   452                     updateNeeded = true;
   488                     updateNeeded = true;
   453                 }
   489                 }
   454             }
   490             }
   455             break;
   491             break;
   456         }
   492         }
   459     }
   495     }
   460 
   496 
   461     if (updateNeeded) {
   497     if (updateNeeded) {
   462         NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   498         NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   463         updateMailboxState(mailboxId,
   499         updateMailboxState(mailboxId,
   464             isMailboxActive(*mailboxInfo), true /* force refresh */);
   500             activate, true /* force refresh */);
   465     }
   501     }
   466 }
   502 }
   467 
   503 
   468 /*!
   504 /*!
   469     Received from NmFrameworkAdapter syncStateEvent signal
   505     Received from NmFrameworkAdapter syncStateEvent signal
   475 {
   511 {
   476     NMLOG(QString("NmMailAgent::handleSyncStateEvent %1 %2").arg(state).arg(event.mMailboxId.id()));
   512     NMLOG(QString("NmMailAgent::handleSyncStateEvent %1 %2").arg(state).arg(event.mMailboxId.id()));
   477     NmMailboxInfo *info = getMailboxInfo(event.mMailboxId);
   513     NmMailboxInfo *info = getMailboxInfo(event.mMailboxId);
   478     if (info) {
   514     if (info) {
   479         info->mSyncState = state;
   515         info->mSyncState = state;
   480         
   516 
   481         if (state==Synchronizing) {
   517         if (state==Synchronizing) {
   482             // Reset counters when sync is started
   518             // Reset counters when sync is started
   483             info->mInboxCreatedMessages = 0;
   519             info->mInboxCreatedMessages = 0;
   484             info->mInboxChangedMessages = 0;
   520             info->mInboxChangedMessages = 0;
   485             info->mInboxDeletedMessages = 0;
   521             info->mInboxDeletedMessages = 0;
   486         } 
   522         }
   487         else if (state==SyncComplete) {
   523         else if (state==SyncComplete) {
   488             // Check the unread status here again
   524             // Check the unread status here again
   489             info->mUnreadMails = getUnreadCount(event.mMailboxId,NmAgentMaxUnreadCount);
   525             bool activate = updateUnreadCount(event.mMailboxId, *info);
       
   526             int oldOutboxCount = info->mOutboxMails;
       
   527             info->mOutboxMails = getOutboxCount(event.mMailboxId);
       
   528             if (info->mOutboxMails > oldOutboxCount) {
       
   529                 // new mails in outbox
       
   530                 activate = true;
       
   531             }
       
   532             bool active = info->mUnreadMailIdList.count() ||
       
   533                 info->mOutboxMails;
   490 
   534 
   491             // Refresh the indicator if messages created or changed
   535             // Refresh the indicator if messages created or changed
   492             NMLOG(QString(" created=%1, changed=%1, deleted=%1").
   536             NMLOG(QString(" created=%1, changed=%2, deleted=%3").
   493                 arg(info->mInboxCreatedMessages).
   537                 arg(info->mInboxCreatedMessages).
   494                 arg(info->mInboxChangedMessages).
   538                 arg(info->mInboxChangedMessages).
   495                 arg(info->mInboxDeletedMessages));
   539                 arg(info->mInboxDeletedMessages));
   496             bool refresh = (info->mInboxCreatedMessages > 0) || (info->mInboxChangedMessages > 0);
   540             bool refresh = (info->mInboxCreatedMessages > 0) || (info->mInboxChangedMessages > 0);
   497 
   541 
   498             updateMailboxState(event.mMailboxId, isMailboxActive(*info), refresh);
   542             if (activate) {
       
   543                 updateMailboxState(event.mMailboxId, active, refresh);
       
   544             }
   499         }
   545         }
   500     }
   546     }
   501 }
   547 }
   502 
   548 
   503 /*!
   549 /*!
   557 
   603 
   558 /*!
   604 /*!
   559     Create a new mailbox info with given parameters
   605     Create a new mailbox info with given parameters
   560     \return new mailbox info object
   606     \return new mailbox info object
   561 */
   607 */
   562 NmMailboxInfo *NmMailAgent::createMailboxInfo(const NmMailbox& mailbox,NmDataPluginInterface *plugin)
   608 NmMailboxInfo *NmMailAgent::createMailboxInfo(const NmMailbox &mailbox, NmDataPluginInterface *plugin)
   563 {
   609 {
   564     NmMailboxInfo *mailboxInfo = new NmMailboxInfo();
   610     NmMailboxInfo *mailboxInfo = new NmMailboxInfo();
   565     mailboxInfo->mId = mailbox.id();
   611     mailboxInfo->mId = mailbox.id();
   566     mailboxInfo->mName = mailbox.name();
   612     mailboxInfo->mName = mailbox.name();
   567 
   613 
   568     mMailboxes.append(mailboxInfo);
   614     mMailboxes.append(mailboxInfo);
   569 
   615 
   570     // Subscribe to get all mailbox events
   616     // Subscribe to get all mailbox events
   571     plugin->subscribeMailboxEvents(mailboxInfo->mId);
   617     plugin->subscribeMailboxEvents(mailboxInfo->mId);
   572 
   618 
   573     // get inbox folder ID
   619     // get inbox folder ID. It might be still unknown (=0).
   574     mailboxInfo->mInboxFolderId = plugin->getStandardFolderId(
   620     mailboxInfo->mInboxFolderId = plugin->getStandardFolderId(
   575         mailbox.id(), NmFolderInbox );
   621         mailbox.id(), NmFolderInbox );
   576 
   622 
   577     // get outbox folder ID
   623     // get outbox folder ID
   578     mailboxInfo->mOutboxFolderId = plugin->getStandardFolderId(
   624     mailboxInfo->mOutboxFolderId = plugin->getStandardFolderId(
   579         mailbox.id(), NmFolderOutbox );
   625         mailbox.id(), NmFolderOutbox );
   580 
   626 
       
   627     // Get branded mailbox icon
       
   628     NmMailbox mailbox2( mailbox );
       
   629     QString domainName = mailbox2.address().address();
       
   630     int delimIndex = domainName.indexOf('@');
       
   631     if( delimIndex >= 0 ) {
       
   632         domainName = domainName.mid(delimIndex+1);
       
   633         NMLOG(QString("Mailbox domain name: %1").arg(domainName));
       
   634     }
       
   635     EmailMailboxInfo emailMailboxInfo;
       
   636     mailboxInfo->mIconName =
       
   637         emailMailboxInfo.mailboxIcon(domainName);
       
   638     
   581     return mailboxInfo;
   639     return mailboxInfo;
   582 }
   640 }
   583 
   641 
   584 /*!
   642 /*!
   585     Return mailbox info class with mailbox id. If no class is found, create a new instance with given id.
   643     Return mailbox info class with mailbox id. If no class is found, create a new instance with given id.
   595 
   653 
   596     // Not found. Create a new mailbox info.
   654     // Not found. Create a new mailbox info.
   597     return createMailboxInfo(id);
   655     return createMailboxInfo(id);
   598 }
   656 }
   599 
   657 
       
   658 /*!
       
   659     Finds out if the message is unread.
       
   660     \param folderId the id of the folder that includes the message
       
   661     \param messageIds the message ids that are checked
       
   662     \param mailboxId the id of the mailbox that includes the message
       
   663     \param unreadMessage true if there was unread messages
       
   664     \return true if info fetching was successful
       
   665 */
       
   666 bool NmMailAgent::getMessageUnreadInfo(const NmId &folderId,
       
   667     const NmId &messageId, const NmId &mailboxId, bool &unreadMessage)
       
   668 {
       
   669     NMLOG("NmMailAgent::messageInfo");
       
   670 
       
   671     NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
       
   672     bool ok = false;
       
   673 
       
   674     if (plugin) {
       
   675         NmMessage *message=NULL;
       
   676         plugin->getMessageById(mailboxId, folderId, messageId, message);
       
   677         if (message) {
       
   678             ok = true;
       
   679             NmMessageEnvelope envelope = message->envelope();
       
   680             if (!envelope.isRead()) {
       
   681                 unreadMessage = true;
       
   682             }
       
   683             delete message;
       
   684         }
       
   685     }
       
   686     return ok;
       
   687 }
       
   688 
       
   689 /*!
       
   690     Plays email alert tune when new messages arrive
       
   691 */
       
   692 void NmMailAgent::playAlertTone()
       
   693 {
       
   694     if (mAlertToneAllowed) {
       
   695         // play alert
       
   696         mAlertToneAllowed = false;
       
   697         QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone()));
       
   698     }
       
   699 }
       
   700 
       
   701 /*!
       
   702     Allows alert tune to be played again
       
   703 */
       
   704 void NmMailAgent::enableAlertTone()
       
   705 {
       
   706     mAlertToneAllowed = true;
       
   707 }
       
   708 
   600 // End of file
   709 // End of file
   601 
   710