email/pop3andsmtpmtm/clientmtms/src/IMCMUTIL.CPP
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Client MTM utilities for POP3, SMTP and IMAP4 protocols
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <mtmdef.h>		//KUidMtmQueryxxx & TMsvPartList flags
       
    19 #include <mtclreg.h>
       
    20 #include "MIUTSET.H"
       
    21 #include "MIUT_ERR.H"
       
    22 #include "IMCMMAIN.H"
       
    23 #include "IMCMUTIL.H"
       
    24 #include "SMTPCMDS.H"
       
    25 
       
    26 /**
       
    27 Allocates and constructs a new CImClientMTMUtils object.
       
    28 @return New CImClientMTMUtils object
       
    29 */
       
    30 EXPORT_C CImClientMTMUtils* CImClientMTMUtils::NewL()
       
    31 	{
       
    32 	CImClientMTMUtils* self = new (ELeave) CImClientMTMUtils;
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop();
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 /**
       
    40 Destructor.
       
    41 */
       
    42 EXPORT_C CImClientMTMUtils::~CImClientMTMUtils()
       
    43 	{
       
    44 	delete iFindText;
       
    45 	}
       
    46 
       
    47 void CImClientMTMUtils::ConstructL()
       
    48 	{
       
    49 	iFindText = CMsvFindText::NewL();
       
    50 	}
       
    51 
       
    52 /**
       
    53 Searches a message for some specified text.
       
    54 
       
    55 @param aTextToFind Text to find
       
    56 @param aRichText Message body to search
       
    57 @param aHeader Message header to search
       
    58 @param aPartList Bitmask of the parts of the message to search for the text, and 
       
    59 flags which modify the way the search works. See KMsvMessagePartBody etc.
       
    60 in mtmdef.h for message part flags. Search flags are: KMsvFindCaseSensitive 
       
    61 means the search is successful only if there is an exact case match for the 
       
    62 text; KMsvFindWholeWord means the search is successful only if the matching 
       
    63 text is not delimited by alphanumeric characters.
       
    64 
       
    65 @param rReturnList On return, bitmask of the message parts in which the text was found
       
    66 */
       
    67 EXPORT_C void CImClientMTMUtils::FindL(const TDesC& aTextToFind, CRichText& aRichText, CImHeader& aHeader, TMsvPartList aPartList, TMsvPartList& rReturnList)
       
    68 	{
       
    69 	if (aPartList & KMsvMessagePartBody)
       
    70 		rReturnList = FindInBodyL(aTextToFind, aRichText, aPartList);
       
    71 	// run for all others as FindInHeaderL() will check the TMsvPartList
       
    72 	rReturnList |= FindInHeaderL(aTextToFind, aHeader, aPartList);
       
    73 	}
       
    74 
       
    75 /**
       
    76 Searches a message body for some specified text.
       
    77 
       
    78 @param aTextToFind Text to find
       
    79 @param aRichText Message body to search
       
    80 @param aPartList Bitmask of flags which modify the way the search works: KMsvFindCaseSensitive 
       
    81 means the search is successful only if there is an exact case match for the 
       
    82 text. KMsvFindWholeWord means the search is successful only if the matching 
       
    83 text is not delimited by alphanumeric characters.
       
    84 @return KMsvMessagePartBody if the text was found, KMsvMessagePartNone if not.
       
    85 */
       
    86 EXPORT_C TMsvPartList CImClientMTMUtils::FindInBodyL(const TDesC& aTextToFind, CRichText& aRichText, TMsvPartList aPartList)
       
    87 	{
       
    88 	TMsvPartList foundList = KMsvMessagePartNone;
       
    89 	if (iFindText->FindRichTextL(aTextToFind, aRichText, aPartList))
       
    90 		foundList |= KMsvMessagePartBody;
       
    91 	return foundList;
       
    92 	}
       
    93 
       
    94 /**
       
    95 Searches a message header for some specified text.
       
    96 
       
    97 @param aTextToFind Text to find
       
    98 @param aHeader Message header to search
       
    99 @param aPartList Bitmask of the parts of the message to search for the text, and 
       
   100 flags which modify the way the search works. See KMsvMessagePartRecipient etc.
       
   101 in mtmdef.h for message part flags. Search flags are: KMsvFindCaseSensitive 
       
   102 means the search is successful only if there is an exact case match for the 
       
   103 text; KMsvFindWholeWord means the search is successful only if the matching 
       
   104 text is not delimited by alphanumeric characters. Wild cards can also be specified as part of the search.
       
   105 The supported wild characters are * and ?
       
   106 @return Bitmask of the message parts in which the text was found
       
   107 */
       
   108 EXPORT_C TMsvPartList CImClientMTMUtils::FindInHeaderL(const TDesC& aTextToFind, CImHeader& aHeader, TMsvPartList aPartList)
       
   109 	{
       
   110 	TMsvPartList foundList = KMsvMessagePartNone;
       
   111 	if (aPartList & KMsvMessagePartRecipient)
       
   112 		{ 
       
   113 		//search in To field, if not found then search in CC and if not found then search Bcc.
       
   114 		if (FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.ToRecipients()))
       
   115 			foundList |= KMsvMessagePartRecipient;
       
   116 		else if (FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.CcRecipients()))
       
   117 			foundList |= KMsvMessagePartRecipient;
       
   118 		else 
       
   119 			(FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.BccRecipients())) ? foundList|=KMsvMessagePartRecipient : foundList;
       
   120 		}
       
   121 	if (aPartList & KMsvMessagePartOriginator)
       
   122 		iFindText->FindTextL(aTextToFind, aHeader.From(), aPartList) ? foundList|=KMsvMessagePartOriginator : foundList;
       
   123 	
       
   124 	if (aPartList & KMsvMessagePartDescription)
       
   125 		iFindText->FindTextL(aTextToFind, aHeader.Subject(), aPartList) ? foundList|=KMsvMessagePartDescription : foundList;
       
   126 	
       
   127 	// Search based on new message parts that are introduced. The search only looks in the  specified message part
       
   128 	// To search
       
   129 	if (aPartList & KMsvMessagePartTo)
       
   130 		{
       
   131 		FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.ToRecipients()) ? foundList|=KMsvMessagePartTo : foundList;
       
   132 		}
       
   133 	// Cc search	
       
   134 	else if (aPartList & KMsvMessagePartCc)
       
   135 		{
       
   136 		FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.CcRecipients()) ? foundList|=KMsvMessagePartCc : foundList;
       
   137 		}
       
   138 	// Bcc search
       
   139 	else if (aPartList & KMsvMessagePartBcc)
       
   140 		{
       
   141 		FindInMessagePartRecipientL(aTextToFind, aPartList, aHeader.BccRecipients()) ? foundList|=KMsvMessagePartCc : foundList;
       
   142 		}
       
   143 	// From search	
       
   144 	else if (aPartList & KMsvMessagePartFrom)
       
   145 		{
       
   146 		iFindText->FindTextL(aTextToFind, aHeader.From(), aPartList) ? foundList|=KMsvMessagePartFrom : foundList;
       
   147 		}
       
   148 	// Subject search	
       
   149 	else if (aPartList & KMsvMessagePartSubject)
       
   150 		{
       
   151 		iFindText->FindTextL(aTextToFind, aHeader.Subject(), aPartList) ? foundList|=KMsvMessagePartSubject : foundList;
       
   152 		}
       
   153 	return foundList;
       
   154 	}
       
   155 
       
   156 TBool CImClientMTMUtils::FindInMessagePartRecipientL(const TDesC& aTextToFind, TMsvPartList aPartList, CDesCArray& aRecipients)
       
   157 	{
       
   158 	TInt count = aRecipients.Count();
       
   159 	TBool found = EFalse;
       
   160 	for (TInt i=0;i<count;i++)
       
   161 		{			
       
   162 		if (iFindText->FindTextL(aTextToFind, aRecipients[i], aPartList))
       
   163 			{
       
   164 			found = ETrue;
       
   165 			break;			
       
   166 			}
       
   167 		}
       
   168 	return found;
       
   169 	}
       
   170