|
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: ESMR policy implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmrmeetingrequestsender.h" |
|
20 |
|
21 #include <cmrmailboxutils.h> |
|
22 #include <coemain.h> |
|
23 #include <f32file.h> |
|
24 #include <calentry.h> |
|
25 #include <caluser.h> |
|
26 #include <utf.h> |
|
27 #include "mesmrmeetingrequestentry.h" |
|
28 #include "cesmrcalimportexporter.h" |
|
29 #include "esmrentryhelper.h" |
|
30 #include "esmrhelper.h" |
|
31 #include "cesmrmailplaitextformatter.h" |
|
32 |
|
33 // Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 const TInt KMRBufferSize = 16 * 1024; |
|
37 |
|
38 _LIT8( KMethodRequest, "REQUEST" ); |
|
39 _LIT8( KMethodResponse, "RESPONSE" ); |
|
40 _LIT8( KMethodCancel, "CANCEL" ); |
|
41 _LIT8( KNewLine, "\n" ); |
|
42 |
|
43 //<cmail> remove hardcoded paths |
|
44 //_LIT( KNCFileName, "c:\\temp\\mail.tmp" ); //codescanner::driveletters |
|
45 _LIT( KNCFile, "temp\\mail.tmp" ); |
|
46 //</cmail> |
|
47 _LIT8( KStart, "EHLO hello\n"); |
|
48 _LIT8( KEnd, ".\nQUIT\n" ); |
|
49 |
|
50 _LIT8( KMailFromStart, "MAIL FROM:<"); |
|
51 _LIT8( KRecipientTo, "RCPT TO:<"); |
|
52 _LIT8( KAddressEnd, ">\n"); |
|
53 _LIT8( KDataStart, "DATA\n" ); |
|
54 _LIT8( KTo, "To:"); |
|
55 |
|
56 |
|
57 // ======== LOCAL FUNCTIONS ======== |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Constructs file for nc application. NC application can further |
|
61 // send the file to recipients. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void StoreToFileL( |
|
65 MESMRMeetingRequestEntry& aEntry, |
|
66 CMRMailboxUtils& aMailboxUtils, |
|
67 const TDesC& aFreePlainText ) |
|
68 { |
|
69 FUNC_LOG; |
|
70 HBufC8* mrBuffer = HBufC8::NewLC( KMRBufferSize ); |
|
71 TPtr8 mrBufPtr( mrBuffer->Des() ); |
|
72 CESMRMailPlainTextFormatter* mailPlainTextFormatter = |
|
73 CESMRMailPlainTextFormatter::NewLC( aMailboxUtils ); |
|
74 |
|
75 mrBufPtr.Append(KStart); |
|
76 |
|
77 CCalEntry& entry = aEntry.Entry(); |
|
78 |
|
79 CCalUser* sender = entry.PhoneOwnerL(); |
|
80 |
|
81 if ( !sender ) |
|
82 { |
|
83 User::Leave( KErrArgument); |
|
84 } |
|
85 |
|
86 mrBufPtr.Append( KMailFromStart ); |
|
87 mrBufPtr.Append( |
|
88 ESMRHelper::AddressWithoutMailtoPrefix( sender->Address() ) ); |
|
89 mrBufPtr.Append( KAddressEnd ); |
|
90 |
|
91 if ( entry.MethodL() == CCalEntry::EMethodReply ) |
|
92 { |
|
93 CCalUser* organizer = NULL; |
|
94 TRAP_IGNORE( organizer = entry.OrganizerL() ); |
|
95 |
|
96 mrBufPtr.Append(KRecipientTo() ); |
|
97 mrBufPtr.Append( |
|
98 ESMRHelper::AddressWithoutMailtoPrefix( organizer->Address() ) ); |
|
99 mrBufPtr.Append(KAddressEnd()); |
|
100 } |
|
101 else |
|
102 { |
|
103 RPointerArray<CCalAttendee>& attendees = entry.AttendeesL(); |
|
104 TInt attendeeCount( attendees.Count() ); |
|
105 for (TInt i(0); i < attendeeCount; ++i ) |
|
106 { |
|
107 mrBufPtr.Append(KRecipientTo() ); |
|
108 mrBufPtr.Append( |
|
109 ESMRHelper::AddressWithoutMailtoPrefix( attendees[i]->Address() ) ); |
|
110 mrBufPtr.Append(KAddressEnd()); |
|
111 } |
|
112 } |
|
113 |
|
114 mrBufPtr.Append( KDataStart ); |
|
115 |
|
116 _LIT(KDateFormat,"%*E%,%D%*N %1 %2"); |
|
117 _LIT( KDateStart, "Date: " ); |
|
118 |
|
119 TTime time; time.UniversalTime(); |
|
120 TDateTime dTime = time.DateTime(); |
|
121 TBuf<30> dateString; |
|
122 time.FormatL(dateString, KDateFormat ); |
|
123 mrBufPtr.Append( KDateStart ); |
|
124 mrBufPtr.Append( dateString ); |
|
125 |
|
126 _LIT8( KFormat, " %d %02d:%02d:%02d +0000\n" ); |
|
127 mrBufPtr.AppendFormat( KFormat, dTime.Year(), dTime.Hour(), dTime.Minute(), dTime.Second() ); |
|
128 |
|
129 if ( entry.MethodL() == CCalEntry::EMethodReply ) |
|
130 { |
|
131 // Leavescan fix |
|
132 CCalUser* organizer = NULL; |
|
133 TRAP_IGNORE( organizer = entry.OrganizerL() ); |
|
134 |
|
135 mrBufPtr.Append( KTo ); |
|
136 mrBufPtr.Append( |
|
137 ESMRHelper::AddressWithoutMailtoPrefix( organizer->Address() ) ); |
|
138 mrBufPtr.Append( KNewLine ); |
|
139 } |
|
140 else |
|
141 {mrBufPtr.Append( KTo ); |
|
142 RPointerArray<CCalAttendee>& attendees = entry.AttendeesL(); |
|
143 TInt attendeeCount( attendees.Count() ); |
|
144 for (TInt i(0); i < attendeeCount; ++i ) |
|
145 { |
|
146 |
|
147 _LIT8( KComma, ","); |
|
148 _LIT8( KStart, "<"); |
|
149 _LIT8( KEnd, "<"); |
|
150 mrBufPtr.Append( KStart ); |
|
151 mrBufPtr.Append( |
|
152 ESMRHelper::AddressWithoutMailtoPrefix( attendees[i]->Address() ) ); |
|
153 mrBufPtr.Append( KEnd ); |
|
154 mrBufPtr.Append( KComma ); |
|
155 } |
|
156 mrBufPtr.Append( KNewLine ); |
|
157 } |
|
158 |
|
159 _LIT8( KReplyTo, "Reply-To: "); |
|
160 mrBufPtr.Append( KReplyTo ); |
|
161 mrBufPtr.Append( |
|
162 ESMRHelper::AddressWithoutMailtoPrefix( sender->Address() ) ); |
|
163 mrBufPtr.Append( KNewLine ); |
|
164 |
|
165 _LIT8( KFrom, "From: " ); |
|
166 mrBufPtr.Append( KFrom ); |
|
167 mrBufPtr.Append( |
|
168 ESMRHelper::AddressWithoutMailtoPrefix( sender->Address() ) ); |
|
169 mrBufPtr.Append( KNewLine ); |
|
170 |
|
171 _LIT8( KSubject, "Subject: " ); |
|
172 mrBufPtr.Append( KSubject ); |
|
173 HBufC8* subject = mailPlainTextFormatter->Subject8LC(aEntry); |
|
174 mrBufPtr.Append( *subject ); |
|
175 CleanupStack::PopAndDestroy( subject ); |
|
176 mrBufPtr.Append( KNewLine ); |
|
177 |
|
178 _LIT8(KMimeVer, "MIME-Version: 1.0\n" ); |
|
179 mrBufPtr.Append( KMimeVer ); |
|
180 |
|
181 _LIT8( KMailContentType, "Content-Type: multipart/alternative;\n boundary=\"EPOC32-cqFgWS+P6_g42_fH-ySFynWD'-TgP+tX+tHKMDhNp-fmZFHj\"\n" ); |
|
182 mrBufPtr.Append( KMailContentType ); |
|
183 |
|
184 _LIT8( XParams, "X-imss-version: 2.043\nX-imss-result: Passed\nX-imss-scores: Clean:45.41865 C:2 M:3 S:5 R:5\nX-imss-settings: Baseline:2 C:1 M:1 S:1 R:1 (0.1500 0.1500)\n\nThis is a MIME Message\n\n" ); |
|
185 mrBufPtr.Append( XParams ); |
|
186 |
|
187 _LIT8( KPlainBoundary, "--EPOC32-cqFgWS+P6_g42_fH-ySFynWD'-TgP+tX+tHKMDhNp-fmZFHj\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Disposition: inline\nContent-Transfer-Encoding: quoted-printable\n\n" ); |
|
188 mrBufPtr.Append( KPlainBoundary ); |
|
189 |
|
190 HBufC8* bodyText = mailPlainTextFormatter->Body8LC( aEntry ); |
|
191 mrBufPtr.Append( *bodyText ); |
|
192 CleanupStack::PopAndDestroy( bodyText ); |
|
193 |
|
194 if ( aFreePlainText.Length() ) |
|
195 { |
|
196 _LIT8( KFreeTextSeparatorTxt, "------------------------------------------------------------------------\n" ); |
|
197 mrBufPtr.Append( KFreeTextSeparatorTxt ); |
|
198 |
|
199 HBufC8* freeTxt8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aFreePlainText ); |
|
200 mrBufPtr.Append( *freeTxt8 ); |
|
201 mrBufPtr.Append( KNewLine ); |
|
202 mrBufPtr.Append( KNewLine ); |
|
203 |
|
204 delete freeTxt8; |
|
205 } |
|
206 |
|
207 _LIT( KMRBoundary, "--EPOC32-cqFgWS+P6_g42_fH-ySFynWD'-TgP+tX+tHKMDhNp-fmZFHj\nContent-Type: text/calendar;\n method="); |
|
208 mrBufPtr.Append( KMRBoundary ); |
|
209 |
|
210 if ( entry.MethodL() == CCalEntry::EMethodRequest ) |
|
211 { |
|
212 mrBufPtr.Append( KMethodRequest ); |
|
213 } |
|
214 else if ( entry.MethodL() == CCalEntry::EMethodCancel ) |
|
215 { |
|
216 mrBufPtr.Append( KMethodCancel ); |
|
217 } |
|
218 else |
|
219 { |
|
220 mrBufPtr.Append( KMethodResponse ); |
|
221 } |
|
222 mrBufPtr.Append( KNewLine ); |
|
223 |
|
224 _LIT( KMRBoundaryEnd, " name=\"meeting.ics\"\nContent-Transfer-Encoding: 8bit\n\n" ); |
|
225 mrBufPtr.Append( KMRBoundaryEnd ); |
|
226 |
|
227 |
|
228 CESMRCalImportExporter* calExporter = CESMRCalImportExporter::NewLC(); |
|
229 |
|
230 HBufC8* iCal = calExporter->ExportToICal8LC( entry ); |
|
231 mrBufPtr.Append( *iCal ); |
|
232 |
|
233 CleanupStack::PopAndDestroy( iCal ); |
|
234 CleanupStack::PopAndDestroy(calExporter); |
|
235 |
|
236 mrBufPtr.Append( KNewLine ); |
|
237 |
|
238 |
|
239 _LIT(KBoundaryEnd, "--EPOC32-cqFgWS+P6_g42_fH-ySFynWD'-TgP+tX+tHKMDhNp-fmZFHj--\n\n\n" ); |
|
240 mrBufPtr.Append( KBoundaryEnd ); |
|
241 mrBufPtr.Append( KEnd); |
|
242 |
|
243 RFile ncFile; |
|
244 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
245 //<cmail> remove hard coded paths |
|
246 //TInt err = fs.MkDirAll( KNCFileName() ); |
|
247 TFileName fileName(KNCFile); |
|
248 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
249 TInt err = ncFile.Replace( fs, fileName, EFileWrite ); |
|
250 //</cmail> |
|
251 if (KErrAlreadyExists != err ) |
|
252 { |
|
253 User::LeaveIfError( err ); |
|
254 } |
|
255 |
|
256 CleanupClosePushL( ncFile ); |
|
257 User::LeaveIfError( ncFile.Write(mrBufPtr) ); |
|
258 CleanupStack::PopAndDestroy( &ncFile ); |
|
259 // mrBuffer, mailPlainTextFormatter |
|
260 CleanupStack::PopAndDestroy( 2, mrBuffer ); |
|
261 } |
|
262 |
|
263 } // namespace |
|
264 |
|
265 |
|
266 // ======== MEMBER FUNCTIONS ======== |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CESMRMeetingRequestSender::CESMRMeetingRequestSender |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 inline CESMRMeetingRequestSender::CESMRMeetingRequestSender( |
|
273 CMRMailboxUtils& aMailboxUtils) : |
|
274 iMailboxUtils( aMailboxUtils ) |
|
275 |
|
276 { |
|
277 FUNC_LOG; |
|
278 //do nothing |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // CESMRMeetingRequestSender::~CESMRMeetingRequestSender |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C CESMRMeetingRequestSender::~CESMRMeetingRequestSender() |
|
286 { |
|
287 FUNC_LOG; |
|
288 //do nothing |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CESMRMeetingRequestSender::NewL |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 EXPORT_C CESMRMeetingRequestSender* |
|
296 CESMRMeetingRequestSender::NewL( |
|
297 CMRMailboxUtils& aMailboxUtils ) |
|
298 { |
|
299 CESMRMeetingRequestSender* self = |
|
300 new (ELeave) CESMRMeetingRequestSender( aMailboxUtils ); |
|
301 CleanupStack::PushL( self ); |
|
302 self->ConstructL(); |
|
303 CleanupStack::Pop( self ); |
|
304 return self; |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // CESMRMeetingRequestSender::ConstructL |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CESMRMeetingRequestSender::ConstructL() |
|
312 { |
|
313 FUNC_LOG; |
|
314 //do nothing |
|
315 } |
|
316 |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CESMRMeetingRequestSender::CreateAndSendMeetingRequestL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CESMRMeetingRequestSender::CreateAndSendMeetingRequestL( |
|
323 MESMRMeetingRequestEntry& aEntry ) |
|
324 { |
|
325 FUNC_LOG; |
|
326 StoreToFileL( aEntry, iMailboxUtils, KNullDesC() ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // CESMRMeetingRequestSender::CreateAndSendMeetingRequestL |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CESMRMeetingRequestSender::CreateAndSendMeetingRequestL( |
|
334 MESMRMeetingRequestEntry& aEntry, |
|
335 const TDesC& aFreePlainText ) |
|
336 { |
|
337 FUNC_LOG; |
|
338 StoreToFileL( aEntry, iMailboxUtils, aFreePlainText ); |
|
339 } |
|
340 |