email/imap4mtm/imapsession/src/tmessageflaginfo.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include "tmessageflaginfo.h"
       
    17 
       
    18 #include "cimapcommand.h"
       
    19 #include "cimapsessionconsts.h"
       
    20 
       
    21 /**
       
    22 Default constructor - initialises its data members to zero.
       
    23 Note this is not a CBase class, so this does not happen automatically.
       
    24 */
       
    25 TMessageFlagInfo::TMessageFlagInfo()
       
    26 	: iMessageUid(0), iFlags(0)
       
    27 	{}
       
    28 
       
    29 /**
       
    30 Set the flag identified by aFlagId to the value of aValue.
       
    31 @param aFlagId Identifies which flag to set.
       
    32 @param aValue The value to apply to the flag.
       
    33 */
       
    34 void TMessageFlagInfo::SetFlag(TImapMessageFlags aFlagId, TBool aValue)
       
    35 	{
       
    36 	if (aValue)
       
    37 		{
       
    38 		iFlags |= aFlagId;
       
    39 		}
       
    40 	else
       
    41 		{
       
    42 		iFlags &= ~aFlagId;
       
    43 		}
       
    44 	}
       
    45 	
       
    46 /**
       
    47 Retrieve the value of the flag identified by aFlagId.
       
    48 @param aFlagId Identifies which flag to query.
       
    49 @return The value of the querried flag.
       
    50 */
       
    51 EXPORT_C TBool TMessageFlagInfo::QueryFlag(TImapMessageFlags aFlagId)
       
    52 	{
       
    53 	return iFlags & aFlagId;
       
    54 	}
       
    55 
       
    56 /**
       
    57 Parse the flags data and update to iFlags.
       
    58 @param aFlagsData contains list of flags to be parsed.
       
    59 @return The remaining portion of the aFlagsData parameter that was not parsed.
       
    60 */
       
    61 TPtrC8 TMessageFlagInfo::ParseFlagsL(const TDesC8& aFlagsData)
       
    62 	{
       
    63 	// formal definition of the FLAGS data item of a FETCH FLAGS is
       
    64 	//
       
    65 	// msg-att-dynamic = "FLAGS" SP "(" [flag-fetch *(SP flag-fetch)] ")"
       
    66 	//
       
    67 	// flag-fetch = flag / "\Recent"
       
    68 	// flag = "\Answered" / "\Flagged" / "\Deleted" / "\Seen" / "\Draft" / flag-keyword / flag-extension
       
    69 	// flag-extension = "\" atom
       
    70 	// flag-keyword = atom
       
    71 	//
       
    72 	//
       
    73 
       
    74 	TPtrC8 parseData(aFlagsData);
       
    75 	
       
    76 	TInt start = aFlagsData.Locate('(');
       
    77 	TInt end = aFlagsData.Locate(')');
       
    78 
       
    79 	// Reset the flags, prior to setting them.
       
    80 	iFlags = 0;
       
    81 
       
    82 	// Now set them.
       
    83 	if ((start >= 0) && (end > start))
       
    84 		{
       
    85 		RDesParts flags;
       
    86 		CleanupClosePushL(flags);
       
    87 		
       
    88 		// lose the brackets
       
    89 		parseData.Set(aFlagsData.Mid(start+1, end-start-1));
       
    90 		
       
    91 		CImapCommand::GetDelimitedPartsL(' ', parseData, flags);
       
    92 		TInt flagsCount = flags.Count();
       
    93 		for (TInt i = 0; i < flagsCount; ++i)
       
    94 			{
       
    95 			TPtrC8 flag = flags[i];
       
    96 
       
    97 			if(flag.CompareF(KImapTxtFlagDeleted) == 0)
       
    98 				{
       
    99 				SetFlag(TMessageFlagInfo::EDeleted, ETrue);
       
   100 				}
       
   101 			else if (flag.CompareF(KImapTxtFlagSeen) == 0)
       
   102 				{
       
   103 				SetFlag(TMessageFlagInfo::ESeen, ETrue);
       
   104 				}
       
   105 			else if(flag.CompareF(KImapTxtFlagFlagged) == 0)
       
   106 				{
       
   107 				SetFlag(TMessageFlagInfo::EFlagged, ETrue);			
       
   108 				}
       
   109 			else if(flag.CompareF(KImapTxtFlagAnswered) == 0)
       
   110 				{
       
   111 				SetFlag(TMessageFlagInfo::EAnswered, ETrue);
       
   112 				}
       
   113 			else if(flag.CompareF(KImapTxtFlagDraft) == 0)
       
   114 				{
       
   115 				SetFlag(TMessageFlagInfo::EDraft, ETrue);
       
   116 				}
       
   117 			else if(flag.CompareF(KImapTxtFlagRecent) == 0)
       
   118 				{
       
   119 				SetFlag(TMessageFlagInfo::ERecent, ETrue);	
       
   120 				}
       
   121 			}
       
   122 
       
   123 		// return the remainder.
       
   124 		// if there is a space after the closing bracket, 
       
   125 		// then remainder should start after the space.
       
   126 		if (aFlagsData.Length() > end + 1)
       
   127 			{
       
   128 			if (aFlagsData[end+1] == ' ')
       
   129 				{
       
   130 				++end;
       
   131 				}
       
   132 			}		
       
   133 		
       
   134 		if (aFlagsData.Length() > end)
       
   135 			{
       
   136 			parseData.Set(aFlagsData.Mid(end + 1));
       
   137 			}
       
   138 		else
       
   139 			{
       
   140 			parseData.Set(aFlagsData.Right(0));
       
   141 			}
       
   142 			
       
   143 		CleanupStack::PopAndDestroy(&flags);
       
   144 		}
       
   145 
       
   146 	return parseData;
       
   147 	}
       
   148 
       
   149 /**
       
   150 Sets the Message UID by converting the given string value into an integer.
       
   151 @param aMessageUid string containing the UID value.
       
   152 @return KErrNone if the coversion was successful.  Otherwise a system-wide error code will be given.
       
   153 */
       
   154 TInt TMessageFlagInfo::SetMessageUid(const TDesC8& aMessageUid)
       
   155 	{
       
   156 	TLex8 lex(aMessageUid);
       
   157 	return lex.Val(iMessageUid);
       
   158 	}
       
   159 
       
   160 /**
       
   161 @return The UID for this message
       
   162 */
       
   163 EXPORT_C TUint TMessageFlagInfo::MessageUid() const
       
   164 	{
       
   165 	return iMessageUid;
       
   166 	}