|
1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // CreateSmtpMessageFromParamFile |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // ServiceId <input>: Value of the SMTP service id. |
|
20 // FolderId <input>: Value of the local folder id where the message will be created. |
|
21 // mailInfo <input>: Reference to a CPop3MailInfo object containing mail info |
|
22 // MessageId <output>: Value of the created SMTP message id. |
|
23 // [Action Description] |
|
24 // Creates a SMTP message on one of the local folders. |
|
25 // [APIs Used] |
|
26 // CMsvEntry::SetEntryL |
|
27 // CMsvEntry::Entry |
|
28 // TMsvId::Id |
|
29 // CImCltRecvConvert::SetMsvId |
|
30 // CImCltRecvConvert::ResetL |
|
31 // CImCltRecvConvert::MessageCompleteL |
|
32 // __ACTION_INFO_END__ |
|
33 // |
|
34 // |
|
35 |
|
36 /** |
|
37 @file |
|
38 */ |
|
39 |
|
40 #include <msvapi.h> |
|
41 #include <miutset.h> |
|
42 |
|
43 #include "CMtfTestActionCreateSmtpMessageFromParamEmailFile.h" |
|
44 #include "CMtfTestCase.h" |
|
45 #include "CMtfTestActionParameters.h" |
|
46 #include "CPop3MailInfo.h" |
|
47 #include "ImCltCvRecv.h" |
|
48 |
|
49 |
|
50 CMtfTestAction* CMtfTestActionCreateSmtpMessageFromParamEmailFile::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
51 { |
|
52 CMtfTestActionCreateSmtpMessageFromParamEmailFile* self = |
|
53 new (ELeave) CMtfTestActionCreateSmtpMessageFromParamEmailFile(aTestCase); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(aActionParameters); |
|
56 CleanupStack::Pop(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 CMtfTestActionCreateSmtpMessageFromParamEmailFile::CMtfTestActionCreateSmtpMessageFromParamEmailFile(CMtfTestCase& aTestCase) |
|
62 : CMtfSynchronousTestAction(aTestCase) |
|
63 { |
|
64 } |
|
65 |
|
66 |
|
67 CMtfTestActionCreateSmtpMessageFromParamEmailFile::~CMtfTestActionCreateSmtpMessageFromParamEmailFile() |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 #include <mtuireg.h> |
|
73 #include <msvstd.h> |
|
74 #include <mtmuibas.h> |
|
75 |
|
76 |
|
77 TMsvId CMtfTestActionCreateSmtpMessageFromParamEmailFile::CreateAndSendMessageL( CPop3MailInfo &mailInfo ) |
|
78 { |
|
79 CSendAs* sendAs = CSendAs::NewL( *this ); |
|
80 CleanupStack::PushL( sendAs ); |
|
81 |
|
82 sendAs->SetMtmL( KUidMsgTypeSMTP ); |
|
83 sendAs->SetService(0); |
|
84 sendAs->CreateMessageL(KMsvGlobalOutBoxIndexEntryId); |
|
85 |
|
86 |
|
87 // these next 2 literals will come from mail info params eventually |
|
88 _LIT( KRecipient, "matthewf@msexchange2k.closedtest.intra" ); |
|
89 sendAs->AddRecipientL( KRecipient ); |
|
90 |
|
91 _LIT( KSubject, "test subject" ); |
|
92 sendAs->SetSubjectL( KSubject ); |
|
93 |
|
94 //Create and read the file data int a CRichText object |
|
95 TCharFormat charForm; |
|
96 TCharFormatMask charFormatMask; |
|
97 charFormatMask.SetAll(); |
|
98 |
|
99 CParaFormatLayer* paraFormat = CParaFormatLayer::NewL( ); |
|
100 CleanupStack::PushL( paraFormat ); |
|
101 CCharFormatLayer* charFormat = CCharFormatLayer::NewL( charForm, charFormatMask ); |
|
102 CleanupStack::PushL( charFormat ); |
|
103 CRichText* rText = CRichText::NewL( paraFormat, charFormat ); |
|
104 CleanupStack::PushL( rText ); |
|
105 |
|
106 // |
|
107 RFs fs; |
|
108 fs.Connect(); |
|
109 RFile file; |
|
110 mailInfo.GetFileName(); |
|
111 User::LeaveIfError( file.Open(fs, mailInfo.GetFileName(), EFileRead ) ); |
|
112 |
|
113 const TInt KLineLen = 1024; |
|
114 TBuf8<KLineLen> line; |
|
115 TBuf8<1> aChar; |
|
116 TBool finished = FALSE; |
|
117 TInt pos = 0; |
|
118 |
|
119 do |
|
120 { |
|
121 line.FillZ(); |
|
122 line.SetLength(0); |
|
123 do |
|
124 { |
|
125 file.Read(aChar, 1); |
|
126 if(aChar.Length()) |
|
127 line.Append(aChar); |
|
128 else |
|
129 finished = TRUE; |
|
130 } while(aChar.Length() && aChar[0] != 0x0A); |
|
131 if(!line.Length()) |
|
132 break; |
|
133 |
|
134 TBuf<KLineLen> line16; |
|
135 line16.Copy( line ); |
|
136 rText->InsertL( pos, line16 ); |
|
137 pos += line16.Length(); |
|
138 } while(!finished); |
|
139 |
|
140 sendAs->SetBodyL( *rText ); |
|
141 sendAs->SaveMessageL(); |
|
142 TMsvId entryId = sendAs->ClientMtm().Entry().EntryId(); |
|
143 CleanupStack::PopAndDestroy( 4 ); // sendAs, paraFormat, charFormat, rText |
|
144 return entryId; |
|
145 } |
|
146 |
|
147 void CMtfTestActionCreateSmtpMessageFromParamEmailFile::ExecuteActionL() |
|
148 { |
|
149 |
|
150 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
151 TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
152 TMsvId paramFolderId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2)); |
|
153 |
|
154 CPop3MailInfo* mailInfo = ObtainParameterReferenceL<CPop3MailInfo>(TestCase(),ActionParameters().Parameter(3)); |
|
155 |
|
156 TMsvId paramMessageId = CreateAndSendMessageL( *mailInfo ); |
|
157 |
|
158 StoreParameterL<TMsvId>(TestCase(),paramMessageId,ActionParameters().Parameter(4)); |
|
159 TestCase().ActionCompletedL(*this); |
|
160 } |
|
161 |