meetingrequest/mrtasks/src/cesmrsendmrfsmailreplytask.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for ESMR send MR via fs email task
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrsendmrfsmailreplytask.h"
       
    20 
       
    21 #include <utf.h>
       
    22 #include <bautils.h>
       
    23 #include <caluser.h>
       
    24 #include <cmrmailboxutils.h>
       
    25 #include <calentry.h>
       
    26 //<cmail>
       
    27 #include "CFSMailMessage.h"
       
    28 #include <coemain.h>
       
    29 #include <coeaui.h>
       
    30 #include "FreestyleEmailUiConstants.h"
       
    31 //</cmail>
       
    32 
       
    33 #include "cesmrcaldbmgr.h"
       
    34 #include "mesmrmeetingrequestentry.h"
       
    35 #include "cesmrfsemailmanager.h"
       
    36 #include "cesmrmailplaitextformatter.h"
       
    37 #include "cesmrcalimportexporter.h"
       
    38 #include "cesmrcaluserutil.h"
       
    39 #include "tesmrinputparams.h"
       
    40 #include "esmrhelper.h"
       
    41 
       
    42 // Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 #ifdef _DEBUG
       
    46 
       
    47 // Literal for panics
       
    48 _LIT( ESMRSendMRRespMailPanicTxt, "ESMRSendMRFSEMailTask" );
       
    49 
       
    50 // Panic codes
       
    51 enum TESMRSendMRFSMailTaskPanic
       
    52     {
       
    53     EESMRSendMRFSAttendeesMissing,
       
    54     EESMRCannotBeTriggeredFromMail
       
    55     };
       
    56 
       
    57 // ======== LOCAL FUNCTIONS ========
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Panic wrapper method
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void Panic( TESMRSendMRFSMailTaskPanic aPanic )
       
    64     {
       
    65 
       
    66     User::Panic( ESMRSendMRRespMailPanicTxt, aPanic );
       
    67     }
       
    68 
       
    69 #endif // _DEBUG
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Leave wrapper method
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 inline void DoLeaveIfErrorL( TInt aLeaveCode )
       
    76     {
       
    77     if ( KErrNone != aLeaveCode )
       
    78         {
       
    79 
       
    80         User::Leave( aLeaveCode );
       
    81         }
       
    82     }
       
    83 } // namespace
       
    84 
       
    85 // ======== MEMBER FUNCTIONS ========
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CESMRSendMRFSMailReplyTask::CESMRSendMRFSMailReplyTask
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CESMRSendMRFSMailReplyTask::CESMRSendMRFSMailReplyTask(
       
    92         MESMRCalDbMgr& aCalDbMgr,
       
    93         MESMRMeetingRequestEntry& aEntry,
       
    94         CMRMailboxUtils& aMRMailboxUtils,
       
    95         TBool aReplyAll)
       
    96 :   CESMRTaskBase( aCalDbMgr, aEntry, aMRMailboxUtils ),
       
    97     iReplyAll(aReplyAll)
       
    98     {
       
    99     FUNC_LOG;
       
   100     //do nothing
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CESMRSendMRFSMailReplyTask::~CESMRSendMRFSMailReplyTask
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CESMRSendMRFSMailReplyTask::~CESMRSendMRFSMailReplyTask()
       
   108     {
       
   109     FUNC_LOG;
       
   110     delete iEntryToSend;
       
   111     delete iCaluserUtil;
       
   112     delete iEmailMgr;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CESMRSendMRFSMailReplyTask::NewL
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CESMRSendMRFSMailReplyTask* CESMRSendMRFSMailReplyTask::NewL(
       
   120         MESMRCalDbMgr& aCalDbMgr,
       
   121         MESMRMeetingRequestEntry& aEntry,
       
   122         CMRMailboxUtils& aMRMailboxUtils,
       
   123         TBool aReplyAll)
       
   124     {
       
   125     FUNC_LOG;
       
   126 
       
   127     CESMRSendMRFSMailReplyTask* self =
       
   128         new (ELeave) CESMRSendMRFSMailReplyTask(
       
   129                 aCalDbMgr,
       
   130                 aEntry,
       
   131                 aMRMailboxUtils,
       
   132                 aReplyAll);
       
   133 
       
   134     CleanupStack::PushL(self);
       
   135     self->ConstructL();
       
   136     CleanupStack::Pop(self);
       
   137 
       
   138     return self;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CESMRSendMRFSMailReplyTask::ConstructL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CESMRSendMRFSMailReplyTask::ConstructL()
       
   146     {
       
   147     FUNC_LOG;
       
   148     BaseConstructL();
       
   149     iEmailMgr = CESMRFSEMailManager::NewL( MailboxUtils() );
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CESMRSendMRFSMailReplyTask::ExecuteTaskL
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CESMRSendMRFSMailReplyTask::ExecuteTaskL()
       
   157     {
       
   158     FUNC_LOG;
       
   159 
       
   160     iEntryToSend = ESMREntry().ValidateEntryL();
       
   161     iCaluserUtil = CESMRCalUserUtil::NewL( *iEntryToSend );
       
   162 
       
   163     ConstructMailL();
       
   164 
       
   165     iEmailMgr->StoreMessageToDraftsFolderL();
       
   166 
       
   167     LaunchFSEmailEditorL(iReplyAll);
       
   168 
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CESMRSendMRRespFSMailTask::ConstructMailL
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CESMRSendMRFSMailReplyTask::ConstructMailL()
       
   176     {
       
   177     FUNC_LOG;
       
   178 
       
   179     // create text formatter:
       
   180     CESMRMailPlainTextFormatter* textFormatter =
       
   181             CESMRMailPlainTextFormatter::NewLC( MailboxUtils() );
       
   182 
       
   183     TESMRInputParams startupparams;
       
   184     TBool isEmail = ESMREntry().StartupParameters(startupparams);
       
   185 
       
   186     // This command cannot be triggered from email
       
   187     __ASSERT_DEBUG( !isEmail, Panic(EESMRCannotBeTriggeredFromMail) );
       
   188 
       
   189     if(isEmail)
       
   190         {
       
   191         // This command cannot be triggered from email
       
   192         User::Leave( KErrNotSupported );
       
   193         }
       
   194     else
       
   195         {
       
   196         //launched from calendar, mail id available for mr
       
   197 
       
   198         // Prepare email manager for sending
       
   199         CCalUser* mailboxUser = iEntryToSend->PhoneOwnerL();
       
   200         iEmailMgr->PrepareForSendingL(
       
   201                 ESMRHelper::AddressWithoutMailtoPrefix(
       
   202                         mailboxUser->Address() ) );
       
   203 
       
   204         // set the email subject:
       
   205         HBufC* subject =
       
   206             textFormatter->ReplyStringLC( *iEntryToSend );
       
   207         
       
   208         iEmailMgr->SetSubjectL(*subject);
       
   209         CleanupStack::PopAndDestroy(subject);
       
   210 
       
   211         CCalUser* organizer = iEntryToSend->OrganizerL();
       
   212 
       
   213         //Add organizer as sender
       
   214         iEmailMgr->SetSenderL(
       
   215                             organizer->Address(),
       
   216                             organizer->CommonName() );
       
   217 
       
   218         if(iReplyAll)
       
   219             {
       
   220             //Add also required and optional attendees
       
   221             AddAttendeesL();
       
   222             }
       
   223         }
       
   224 
       
   225     CleanupStack::PopAndDestroy(textFormatter);
       
   226 
       
   227     }
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CESMRSendMRFSMailReplyTask::AddAttendeesL
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CESMRSendMRFSMailReplyTask::AddAttendeesL()
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     RArray<CCalAttendee*> requiredAttendees;
       
   239     CleanupClosePushL( requiredAttendees );
       
   240 
       
   241     RArray<CCalAttendee*> optionalAttendees;
       
   242     CleanupClosePushL( optionalAttendees );
       
   243 
       
   244     iCaluserUtil->GetAttendeesL(
       
   245             requiredAttendees,
       
   246             EESMRRoleRequiredAttendee );
       
   247     iCaluserUtil->GetAttendeesL(
       
   248             optionalAttendees,
       
   249             EESMRRoleOptionalAttendee );
       
   250 
       
   251     // Add recipients and cc-recipients
       
   252     TInt attendeeCount( requiredAttendees.Count() );
       
   253 
       
   254     __ASSERT_DEBUG( attendeeCount, Panic(EESMRSendMRFSAttendeesMissing) );
       
   255 
       
   256     if ( !attendeeCount )
       
   257         {
       
   258         DoLeaveIfErrorL( KErrArgument );
       
   259         }
       
   260 
       
   261     for (TInt i(0); i < attendeeCount; ++i)
       
   262         {
       
   263         iEmailMgr->AppendToRecipientL(
       
   264                 requiredAttendees[i]->Address(),
       
   265                 requiredAttendees[i]->CommonName() );
       
   266         }
       
   267 
       
   268     TInt optAttendeeCount( optionalAttendees.Count() );
       
   269     for (TInt i(0); i < optAttendeeCount; ++i)
       
   270         {
       
   271         iEmailMgr->AppendToRecipientL(
       
   272                 optionalAttendees[i]->Address(),
       
   273                 optionalAttendees[i]->CommonName() );
       
   274         }
       
   275 
       
   276     CleanupStack::PopAndDestroy(2, &requiredAttendees );
       
   277 
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CESMRSendMRFSMailReplyTask::ResolveUsedMailboxUserAddressLC
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 HBufC* CESMRSendMRFSMailReplyTask::ResolveUsedMailboxUserAddressLC()
       
   285     {
       
   286     FUNC_LOG;
       
   287 
       
   288     HBufC* mailboxUserAddress = NULL;
       
   289     MESMRMeetingRequestEntry& mrEntry( ESMREntry());
       
   290     if ( mrEntry.IsForwardedL() )
       
   291         {
       
   292         // Entry is forwarder --> Use default mailbox
       
   293         CMRMailboxUtils::TMailboxInfo mbInfo;
       
   294         CMRMailboxUtils& mbUtils( MailboxUtils() );
       
   295         mbUtils.GetDefaultMRMailBoxL( mbInfo );
       
   296         mailboxUserAddress = mbInfo.iEmailAddress.AllocLC();
       
   297         }
       
   298     else
       
   299         {
       
   300         CCalUser *mailboxUser = iEntryToSend->PhoneOwnerL();
       
   301         mailboxUserAddress = mailboxUser->Address().AllocLC();
       
   302         }
       
   303 
       
   304     return mailboxUserAddress;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CESMRSendMRFSMailReplyTask::LaunchFSEmailEditorL
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 TInt CESMRSendMRFSMailReplyTask::LaunchFSEmailEditorL(TBool aReplAll)
       
   312     {
       
   313     FUNC_LOG;
       
   314     CCoeEnv* coe = CCoeEnv::Static();
       
   315 
       
   316     CCoeAppUi* appui = coe->AppUi();
       
   317 
       
   318     // fill params
       
   319     TEditorLaunchParams params;
       
   320     params.iActivatedExternally = ETrue;
       
   321     params.iMailboxId = iEmailMgr->MailboxId();
       
   322     params.iFolderId = iEmailMgr->MessageFolderId();
       
   323     params.iMsgId = iEmailMgr->MessageId();
       
   324 
       
   325     TVwsViewId viewId(
       
   326             KFSEmailUiUid,
       
   327             MailEditorId );
       
   328 
       
   329     TUid editorCommand;
       
   330 
       
   331     if(aReplAll)
       
   332         {
       
   333         editorCommand = TUid::Uid( KEditorCmdReplyAll );
       
   334         }
       
   335     else
       
   336         {
       
   337         editorCommand = TUid::Uid( KEditorCmdReply );
       
   338         }
       
   339 
       
   340     TPckgC<TEditorLaunchParams> buf( params );
       
   341 
       
   342     appui->ActivateViewL(
       
   343             viewId,
       
   344             editorCommand,
       
   345             buf );
       
   346 
       
   347     return KErrNone;
       
   348     }
       
   349 
       
   350 //EOF
       
   351