email/pop3andsmtpmtm/clientmtms/src/cimapsyncdownloadrules.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2007-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 "cimapsyncdownloadrules.h"
       
    17 #include "MIUT_ERR.H"
       
    18 
       
    19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    20 #include "miut_errconsts.h"
       
    21 #endif
       
    22 
       
    23 /**
       
    24 Factory constructor.
       
    25 */
       
    26 EXPORT_C CImapSyncDownloadRules* CImapSyncDownloadRules::NewL()
       
    27 	{
       
    28 	CImapSyncDownloadRules* self = NewLC();
       
    29 	CleanupStack::Pop();
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 /**
       
    34 Factory constructor.
       
    35 */
       
    36 EXPORT_C CImapSyncDownloadRules* CImapSyncDownloadRules::NewLC()
       
    37 	{
       
    38 	CImapSyncDownloadRules* self = new(ELeave) CImapSyncDownloadRules();
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Class constructor
       
    46 */
       
    47 CImapSyncDownloadRules::CImapSyncDownloadRules()
       
    48 	{
       
    49 	}
       
    50 
       
    51 /**
       
    52 Second phase constructor
       
    53 */
       
    54 void CImapSyncDownloadRules::ConstructL()
       
    55 	{
       
    56 	}
       
    57 
       
    58 /**
       
    59 Class destructor
       
    60 */
       
    61 CImapSyncDownloadRules::~CImapSyncDownloadRules()
       
    62 	{
       
    63 	Reset();
       
    64 	}
       
    65 
       
    66 /**
       
    67 Make copy of an instance of the class.
       
    68 
       
    69 @return Pointer to new class on the heap. Ownership is transferred to the caller.
       
    70 */
       
    71 EXPORT_C CImapSyncDownloadRules* CImapSyncDownloadRules::CopyL()
       
    72 	{
       
    73 	CImapSyncDownloadRules* dest = CopyLC();
       
    74 	CleanupStack::Pop();
       
    75 	return dest;
       
    76 	}
       
    77 
       
    78 /**
       
    79 Make new copy of an instance of the class.
       
    80 On return the copy will be on the cleanup stack.
       
    81 
       
    82 @return Pointer to new class on the heap. Ownership is transferred to the caller.
       
    83 */
       
    84 EXPORT_C CImapSyncDownloadRules* CImapSyncDownloadRules::CopyLC()
       
    85 	{
       
    86 	CImapSyncDownloadRules* dest = NewLC();
       
    87 
       
    88 	TImapSyncDownloadRules newRule;
       
    89 	TInt numRules;
       
    90 
       
    91 	for (TInt type = EInboxRulesType; type <= EFolderRulesType; ++type)
       
    92 		{
       
    93 		numRules = iRulesList[type].Count();
       
    94 
       
    95 		for (TInt rule = 0; rule < numRules; ++rule)
       
    96 			{
       
    97 			newRule.iBearerTypes = iRulesList[type][rule].iBearerTypes;
       
    98 			newRule.iMailInfo = iRulesList[type][rule].iMailInfo;
       
    99 
       
   100 			dest->iRulesList[type].AppendL(newRule);
       
   101 			}
       
   102 		}
       
   103 
       
   104 	return dest;
       
   105 	}
       
   106 
       
   107 /**
       
   108 Adds a new synchronisation download rule.
       
   109 
       
   110 The position for the new rule is specified in the parameter list. If the
       
   111 position is greater than the number of rules already in the list then the
       
   112 new rule is added at the end of the list. If the position is less than the
       
   113 number of rules already in the list, then the new rule is inserted at that
       
   114 position and all subsequent rules moved down by one position. The actual
       
   115 position where the rule was added is given by the return value.
       
   116 
       
   117 Invalid arguments passed to the routine will cause a panic on debug builds
       
   118 but a leave with KErrArgument on a release build.
       
   119 
       
   120 @param aType Type of folder the rule is for (inbox or other folder)
       
   121 @param aPos Position in the list to add the rule.
       
   122 @param aBearerTypes Bearer types that will use the rule.
       
   123 @param aMailInfo Partial mail info options to use during synchronisation
       
   124 
       
   125 @return The position in the list where the rule was added, or KErrOverflow
       
   126         if the list is full up, or KErrAlreadyExists if there is already a
       
   127         rule for one of the bearer types.
       
   128 
       
   129 @leave KErrArgument Argument passed in is invalid
       
   130 */
       
   131 EXPORT_C TInt CImapSyncDownloadRules::AddRuleL(TRulesType aType, TInt aPos, TUint32 aBearerTypes, const TImImap4GetPartialMailInfo& aMailInfo)
       
   132 	{
       
   133 	__ASSERT_DEBUG(aPos >= 0 && aPos < KMaxImapSyncDownloadRules, gPanic(EImcmSyncDownloadRulesInvalidPos1));
       
   134 	__ASSERT_DEBUG(aBearerTypes != 0, gPanic(EImcmSyncDownloadRulesInvalidBearerTypes1));
       
   135 
       
   136 	if (aPos < 0 || aPos >= KMaxImapSyncDownloadRules || aBearerTypes == 0)
       
   137 		{
       
   138 		User::Leave(KErrArgument);
       
   139 		}
       
   140 
       
   141 	TInt numRules = iRulesList[aType].Count();
       
   142 
       
   143 	if (numRules >= KMaxImapSyncDownloadRules)
       
   144 		{
       
   145 		return KErrOverflow;
       
   146 		}
       
   147 
       
   148 	for (TInt rule = 0; rule < numRules; ++rule)
       
   149 		{
       
   150 		if ((iRulesList[aType][rule].iBearerTypes & aBearerTypes) != 0)
       
   151 			{
       
   152 			return KErrAlreadyExists;
       
   153 			}
       
   154 		}
       
   155 
       
   156 	TImapSyncDownloadRules newRule;
       
   157 	newRule.iBearerTypes = aBearerTypes;
       
   158 	newRule.iMailInfo = aMailInfo;
       
   159 
       
   160 	TInt insertedPos = aPos;
       
   161 
       
   162 	if (aPos < numRules)
       
   163 		{
       
   164 		iRulesList[aType].InsertL(newRule, aPos);
       
   165 		}
       
   166 	else
       
   167 		{
       
   168 		iRulesList[aType].AppendL(newRule);
       
   169 		insertedPos = numRules;
       
   170 		}
       
   171 
       
   172 	return insertedPos;
       
   173 	}
       
   174 
       
   175 /**
       
   176 Deletes a synchronisation download rule from a given position
       
   177 
       
   178 Invalid arguments passed to the routine will cause a panic on debug builds
       
   179 but a leave with KErrArgument on a release build.
       
   180 
       
   181 @param aType Type of folder the rule is for (inbox or other folder)
       
   182 @param aPos Position in the list to add the rule.
       
   183 
       
   184 @return ETrue if the rule was deleted, EFalse otherwise
       
   185 
       
   186 @leave KErrArgument Argument passed in is invalid
       
   187 */
       
   188 EXPORT_C TBool CImapSyncDownloadRules::DeleteRuleL(TRulesType aType, TInt aPos)
       
   189 	{
       
   190 	__ASSERT_DEBUG(aPos >= 0 && aPos < KMaxImapSyncDownloadRules, gPanic(EImcmSyncDownloadRulesInvalidPos2));
       
   191 
       
   192 	if (aPos < 0 || aPos >= KMaxImapSyncDownloadRules)
       
   193 		{
       
   194 		User::Leave(KErrArgument);
       
   195 		}
       
   196 
       
   197 	if (aPos < iRulesList[aType].Count())
       
   198 		{
       
   199 		iRulesList[aType].Remove(aPos);
       
   200 		return ETrue;
       
   201 		}
       
   202 	
       
   203 	return EFalse;
       
   204 	}
       
   205 
       
   206 /**
       
   207 Deletes bearer types from the synchronisation download rules.
       
   208 
       
   209 Every rule is examined to see if the bearer types associated with that rule
       
   210 contain all of the passed in bearer types. If there is a match then the bearer
       
   211 types are removed from the rule. If this results in all the bearer types for
       
   212 the rule being removed then the rule is deleted and all subsequent rules
       
   213 are moved up one position.
       
   214 
       
   215 Invalid arguments passed to the routine will cause a panic on debug builds
       
   216 but a leave with KErrArgument on a release build.
       
   217 
       
   218 @param aType Type of folder the rule is for (inbox or other folder)
       
   219 @param aBearerTypes Bearer types to remove.
       
   220 @param aRuleRemoved If the bearer types are removed, this flag indicates if
       
   221        the removal resulted in the rule being removed as well.
       
   222 
       
   223 @return The position of the rule in the list that contained all the bearer types,
       
   224         or KErrNotFound if no rule was found.
       
   225 
       
   226 @leave KErrArgument Argument passed in is invalid
       
   227 */
       
   228 EXPORT_C TInt CImapSyncDownloadRules::DeleteBearerTypesL(TRulesType aType, TUint32 aBearerTypes, TBool& aRuleRemoved)
       
   229 	{
       
   230 	__ASSERT_DEBUG(aBearerTypes != 0, gPanic(EImcmSyncDownloadRulesInvalidBearerTypes2));
       
   231 
       
   232 	if (aBearerTypes == 0)
       
   233 		{
       
   234 		User::Leave(KErrArgument);
       
   235 		}
       
   236 
       
   237 	aRuleRemoved = EFalse;
       
   238 	
       
   239 	TInt numRules = iRulesList[aType].Count();
       
   240 
       
   241 	for (TInt rule = 0; rule < numRules; ++rule)
       
   242 		{
       
   243 		if ((iRulesList[aType][rule].iBearerTypes & aBearerTypes) == aBearerTypes)
       
   244 			{
       
   245 			iRulesList[aType][rule].iBearerTypes &= ~aBearerTypes;
       
   246 
       
   247 			if (iRulesList[aType][rule].iBearerTypes == 0)
       
   248 				{
       
   249 				iRulesList[aType].Remove(rule);
       
   250 				aRuleRemoved = ETrue;
       
   251 				}
       
   252 
       
   253 			return rule;
       
   254 			}
       
   255 		}
       
   256 
       
   257 	return KErrNotFound;
       
   258 	}
       
   259 
       
   260 /**
       
   261 Gets the synchronisation download rule at a given position.
       
   262 
       
   263 Invalid arguments passed to the routine will cause a panic on debug builds
       
   264 but a leave with KErrArgument on a release build.
       
   265 
       
   266 @param aType Type of folder the rule is for (inbox or other folder)
       
   267 @param aPos Position of the rule in the list
       
   268 @param aBearerTypes On successful completion, this holds the bearer types for the rule
       
   269 @param aMailInfo On successful completion, this holds the mail info for the rule
       
   270 
       
   271 @return ETrue if the rule was found, EFalse otherwise
       
   272 
       
   273 @leave KErrArgument Argument passed in is invalid
       
   274 */
       
   275 EXPORT_C TBool CImapSyncDownloadRules::GetRuleL(TRulesType aType, TInt aPos, TUint32& aBearerTypes, TImImap4GetPartialMailInfo& aMailInfo) const
       
   276 	{
       
   277 	__ASSERT_DEBUG(aPos >= 0 && aPos < KMaxImapSyncDownloadRules, gPanic(EImcmSyncDownloadRulesInvalidPos3));
       
   278 
       
   279 	if (aPos < 0 || aPos >= KMaxImapSyncDownloadRules)
       
   280 		{
       
   281 		User::Leave(KErrArgument);
       
   282 		}
       
   283 
       
   284 	if (aPos < iRulesList[aType].Count())
       
   285 		{
       
   286 		aBearerTypes = iRulesList[aType][aPos].iBearerTypes;
       
   287 		aMailInfo = iRulesList[aType][aPos].iMailInfo;
       
   288 		return ETrue;
       
   289 		}
       
   290 
       
   291 	return EFalse;
       
   292 	}
       
   293 
       
   294 /**
       
   295 Gets the partial mail info object from the synchronisation download rule for
       
   296 a given bearer type.
       
   297 
       
   298 The mail info is returned only if its associated bearer types contain all the
       
   299 bearer types specified in the passed in value.
       
   300 
       
   301 Invalid arguments passed to the routine will cause a panic on debug builds
       
   302 but a leave with KErrArgument on a release build.
       
   303 
       
   304 @param aType Type of folder the rule is for (inbox or other folder)
       
   305 @param aBearerTypes The bearer types to search for
       
   306 @param aMailInfo On successful completion, this holds the mail info for the rule
       
   307 
       
   308 @return The position of the rule in the list that matched the bearer types, or
       
   309         KErrNotFound if no matching bearer type was found.
       
   310 
       
   311 @leave KErrArgument Argument passed in is invalid
       
   312 */
       
   313 EXPORT_C TInt CImapSyncDownloadRules::GetMailInfoL(TRulesType aType, TUint32 aBearerTypes, TImImap4GetPartialMailInfo& aMailInfo) const
       
   314 	{
       
   315 	__ASSERT_DEBUG(aBearerTypes != 0, gPanic(EImcmSyncDownloadRulesInvalidBearerTypes3));
       
   316 
       
   317 	if (aBearerTypes == 0)
       
   318 		{
       
   319 		User::Leave(KErrArgument);
       
   320 		}
       
   321 
       
   322 	TInt numRules = iRulesList[aType].Count();
       
   323 
       
   324 	for (TInt rule = 0; rule < numRules; ++rule)
       
   325 		{
       
   326 		if ((iRulesList[aType][rule].iBearerTypes & aBearerTypes) == aBearerTypes)
       
   327 			{
       
   328 			aMailInfo = iRulesList[aType][rule].iMailInfo;
       
   329 			return rule;
       
   330 			}
       
   331 		}
       
   332 
       
   333 	return KErrNotFound;
       
   334 	}
       
   335 
       
   336 /**
       
   337 Reset the rules lists so that they are empty
       
   338 */
       
   339 EXPORT_C void CImapSyncDownloadRules::Reset()
       
   340 	{
       
   341 	iRulesList[EInboxRulesType].Reset();
       
   342 	iRulesList[EFolderRulesType].Reset();
       
   343 	}