serviceproviders/sapi_messaging/tsrc/dev/tmessagingtest/tmsg_getheaderlistiter1/src/tgetheaderlistmms2.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 24 Nov 2009 08:56:33 +0200
changeset 33 50974a8b132e
parent 19 989d2f495d90
permissions -rw-r--r--
Revision: 200945 Kit: 200948

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  
*
*/

 

#include <e32base.h>
////#include <senduiconsts.h>
#include "messagingservice.h"
#include <badesca.h>
#include "getheader.h"
#include <f32file.h>
#include "messageheader.h"
#ifdef MAIN
#define getheadermms_test2 main
#endif

int getheadermms_test2(int, char**)
	{

    __UHEAP_MARK;
    CMessagingService* test = (CMessagingService* ) CMessagingService::NewL() ; 
	CleanupStack::PushL(test);	

     CFilterParamInfo* filterParams = CFilterParamInfo::NewL();
    CleanupStack::PushL(filterParams);

	_LIT(Kaddr1, "9008032761");
    filterParams->AddFromL(Kaddr1);

    filterParams->SetSortType(EMsvSortByDate);
 
    filterParams->AddMtmL(_L("MMS"));
 
   _LIT(KSubject, "MMS Subject");
    filterParams->SetSubjectL(KSubject);

    TDateTime start(2007,EMarch,22,0,0,0,0);
    TInt startyear = start.Year();
    TInt startmonth = start.Month();
    TInt startday = start.Day();
    
    TTime startdate(start);
    
    filterParams->SetStartDateFilter(startdate);

    TDateTime end(2007,EJune,23,0,0,0,0);
    TInt endyear = end.Year();
    TInt endmonth = end.Month();
    TInt endday = end.Day();


    TTime enddate(end) ;       

	filterParams->SetEndDate(enddate);

    
    CMsvEntrySelection* entryselection = NULL ;
   
  
  
   TRAPD(errcode, test->GetIdListL(filterParams,0,NULL,entryselection));

   if(errcode != KErrNone)
      return errcode;

  
   if(entryselection)
		CleanupStack::PushL(entryselection);
   

    	
	TInt index = 0;
	TInt val = 0;
	TInt iter=0;
	for(;;)
	{
		CMessageHeader* header = NULL;
		test->GetNextHeaderL(filterParams, entryselection, index, NULL, header);
		if(header)
			{
		     iter++;
		     TTime temp = header->Time();
		 
		     if((header->Mtm().FindF(_L("MMS")) != KErrNotFound ) && (header->From().FindF(_L("9008032761")) != KErrNotFound )
		     && (header->Subject().FindF(_L("MMS Subject")) != KErrNotFound) && (startdate <= temp && temp <= enddate ) )	
		        val++;
		      
			delete header;
			}
		else
		    break;	
		
	}
	
	

    if(entryselection)
    	CleanupStack::PopAndDestroy(entryselection);
    	     
	CleanupStack::PopAndDestroy(filterParams);
    CleanupStack::PopAndDestroy(test);
     __UHEAP_MARKEND;  
	
	if(iter == val)
		return KErrNone;
	else
		return KErrGeneral;

  

	}