74
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
* Send message operation implementation.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "nmapiheaders.h"
|
|
19 |
|
|
20 |
namespace EmailClientApi
|
|
21 |
{
|
|
22 |
|
|
23 |
NmApiOperationSendMessage::NmApiOperationSendMessage(const NmApiMessage &message, CFSMailBox &mailBox, QObject *parent)
|
|
24 |
:NmApiOperation(parent, Succeeded, SendMessage),
|
|
25 |
mMessage(message),
|
|
26 |
mMailBox(mailBox),
|
|
27 |
mRequestId(NmApiNoError)
|
|
28 |
|
|
29 |
{
|
|
30 |
NM_FUNCTION;
|
|
31 |
}
|
|
32 |
|
|
33 |
NmApiOperationSendMessage::~NmApiOperationSendMessage()
|
|
34 |
{
|
|
35 |
NM_FUNCTION;
|
|
36 |
}
|
|
37 |
|
|
38 |
void NmApiOperationSendMessage::start()
|
|
39 |
{
|
|
40 |
NM_FUNCTION;
|
|
41 |
|
|
42 |
NmId id(mMessage.envelope().id());
|
|
43 |
TFSMailMsgId fsId(id);
|
|
44 |
|
|
45 |
RPointerArray<CFSMailPlugin> mailPlugins;
|
|
46 |
NmApiEngine *engine = NmApiEngine::instance();
|
|
47 |
if (engine) {
|
|
48 |
engine->listMailPlugins(mailPlugins);
|
|
49 |
}
|
|
50 |
|
|
51 |
CFSMailPlugin *plugin = NULL;
|
|
52 |
CFSMailMessage *fsMessage = NULL;
|
|
53 |
TFSMailMsgId fsMailBoxId = mMailBox.GetId();
|
|
54 |
TFSMailMsgId fsFolderId = TFSMailMsgId();
|
|
55 |
TFSMailMsgId fsMessageId = TFSMailMsgId(fsId);
|
|
56 |
|
|
57 |
for (int i = 0; i < mailPlugins.Count() && !fsMessage; i++){
|
|
58 |
plugin = mailPlugins[i];
|
|
59 |
if (plugin && (plugin->Id() == fsMailBoxId.PluginId())) {
|
|
60 |
TRAPD(err, fsMessage = plugin->GetMessageByUidL(fsMailBoxId,
|
|
61 |
fsFolderId,
|
|
62 |
fsMessageId,
|
|
63 |
EFSMsgDataStructure));
|
|
64 |
Q_UNUSED(err);
|
|
65 |
if (fsMessage) {
|
|
66 |
break;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
if (fsMessage) {
|
|
72 |
TRAPD(mail_err, mMailBox.SendMessageL(*fsMessage, *this));
|
|
73 |
if (mail_err == KErrNone){
|
|
74 |
mStatus = Pending;
|
|
75 |
}
|
|
76 |
else {
|
|
77 |
mStatus = Failed;
|
|
78 |
emit operationComplete(NmApiGeneralError);
|
|
79 |
}
|
|
80 |
} else {
|
|
81 |
mStatus = Failed;
|
|
82 |
emit operationComplete(NmApiGeneralError);
|
|
83 |
}
|
|
84 |
if (fsMessage) {
|
|
85 |
delete fsMessage;
|
|
86 |
}
|
|
87 |
|
|
88 |
NmApiEngine::releaseInstance(engine);
|
|
89 |
}
|
|
90 |
|
|
91 |
void NmApiOperationSendMessage::cancel()
|
|
92 |
{
|
|
93 |
NM_FUNCTION;
|
|
94 |
}
|
|
95 |
|
|
96 |
void NmApiOperationSendMessage::RequestResponseL( TFSProgress aEvent, TInt aRequestId )
|
|
97 |
{
|
|
98 |
NM_FUNCTION;
|
|
99 |
|
|
100 |
TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus;
|
|
101 |
|
|
102 |
if (aRequestId == mRequestId) {
|
|
103 |
if (status == TFSProgress::EFSStatus_RequestComplete && aEvent.iParam) {
|
|
104 |
mStatus = Succeeded;
|
|
105 |
emit operationComplete(NmApiNoError);
|
|
106 |
}
|
|
107 |
else if (status == TFSProgress::EFSStatus_RequestCancelled) {
|
|
108 |
mStatus = Canceled;
|
|
109 |
emit operationComplete(NmApiCancelError);
|
|
110 |
}
|
|
111 |
else {
|
|
112 |
mStatus = Failed;
|
|
113 |
emit operationComplete(NmApiGeneralError);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
}
|
|
117 |
}
|