|
1 /* |
|
2 * Copyright (c) 2006 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 * Class implementation file |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <eikenv.h> |
|
21 #include <miuthdr.h> |
|
22 #include <smtpset.h> |
|
23 #include <MuiuMsvUiServiceUtilities.h> |
|
24 #include <SenduiMtmUids.h> // mtm uids |
|
25 #include <ImumInMailboxServices.h> |
|
26 |
|
27 #include "ImumMtmLogging.h" |
|
28 #include "EmailPreCreation.h" |
|
29 #include "EmailUtils.H" |
|
30 #include "ImumMboxSettingsUtils.h" |
|
31 |
|
32 const TMsvId KPreCreatedMsgFolderId = KMsvDraftEntryId; |
|
33 const TInt KPreCreateMsgCreatorPriority = ( CActive::EPriorityLow + 1 ); |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CEmailPreCreation::NewL() |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 CEmailPreCreation* CEmailPreCreation::NewL( CImumInternalApi& aMailboxApi ) |
|
40 { |
|
41 IMUM_STATIC_CONTEXT( CEmailPreCreation::NewL, 0, mtm, KImumMtmLog ); |
|
42 IMUM_IN(); |
|
43 |
|
44 CEmailPreCreation* me = new ( ELeave ) CEmailPreCreation( aMailboxApi ); |
|
45 CleanupStack::PushL(me); |
|
46 me->ConstructL(); |
|
47 CleanupStack::Pop(); |
|
48 IMUM_OUT(); |
|
49 return me; |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CEmailPreCreation::~CEmailPreCreation() |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CEmailPreCreation::~CEmailPreCreation() |
|
57 { |
|
58 IMUM_CONTEXT( CEmailPreCreation::~CEmailPreCreation, 0, KImumMtmLog ); |
|
59 IMUM_IN(); |
|
60 |
|
61 delete iEntry; |
|
62 iEntry = NULL; |
|
63 IMUM_OUT(); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CEmailPreCreation::CEmailPreCreation() |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CEmailPreCreation::CEmailPreCreation( CImumInternalApi& aMailboxApi ) |
|
71 : |
|
72 iMailboxApi( aMailboxApi ) |
|
73 { |
|
74 IMUM_CONTEXT( CEmailPreCreation::CEmailPreCreation, 0, KImumMtmLog ); |
|
75 IMUM_IN(); |
|
76 IMUM_OUT(); |
|
77 |
|
78 } |
|
79 |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CEmailPreCreation::PreCreateBlankEmailL() |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CMsvOperation* CEmailPreCreation::PreCreateBlankEmailL( |
|
86 TMsvId aServiceId, |
|
87 TRequestStatus& aStatus ) |
|
88 { |
|
89 IMUM_CONTEXT( CEmailPreCreation::PreCreateBlankEmailL, 0, KImumMtmLog ); |
|
90 IMUM_IN(); |
|
91 |
|
92 const TMsvPartList partList = |
|
93 ( KMsvMessagePartBody | KMsvMessagePartAttachments ); |
|
94 TMsvEmailTypeList type = KMsvEmailTypeListInvisibleMessage; |
|
95 if(ServiceUsesMHTMLEncodingL(aServiceId)) |
|
96 { |
|
97 type |= KMsvEmailTypeListMHTMLMessage; |
|
98 } |
|
99 aStatus = KRequestPending; |
|
100 IMUM_OUT(); |
|
101 |
|
102 return CImEmailOperation::CreateNewL( |
|
103 aStatus, |
|
104 iEntry->Session(), |
|
105 KPreCreatedMsgFolderId, |
|
106 aServiceId, |
|
107 partList, |
|
108 type, |
|
109 KUidMsgTypeSMTP, |
|
110 KPreCreateMsgCreatorPriority); |
|
111 } |
|
112 |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CEmailPreCreation::DeleteAllPreCreatedEmailsL() |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 void CEmailPreCreation::DeleteAllPreCreatedEmailsL( |
|
119 TMsvId aServiceId ) |
|
120 { |
|
121 IMUM_CONTEXT( CEmailPreCreation::DeleteAllPreCreatedEmailsL, 0, KImumMtmLog ); |
|
122 IMUM_IN(); |
|
123 |
|
124 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
125 CleanupStack::PushL(sel); |
|
126 |
|
127 if(iEntry->EntryId() != KPreCreatedMsgFolderId) |
|
128 { |
|
129 iEntry->SetEntryL(KPreCreatedMsgFolderId); |
|
130 } |
|
131 // Search children for invisible messages which match service id. |
|
132 TInt child = iEntry->Count(); |
|
133 while(child--) |
|
134 { |
|
135 const TMsvEntry& entry = (*iEntry)[child]; |
|
136 if( (!entry.Visible()) && (entry.iServiceId == aServiceId) ) |
|
137 { |
|
138 sel->AppendL(entry.Id()); |
|
139 } |
|
140 } |
|
141 |
|
142 if(sel->Count()) |
|
143 { |
|
144 // Do deletion synchronously so that we can guarantee that the |
|
145 // Email editor will not be launched with a message which |
|
146 // we are about to delete. |
|
147 TMsvLocalOperationProgress opProgress; |
|
148 iEntry->DeleteL(*sel, opProgress); |
|
149 } |
|
150 |
|
151 CleanupStack::PopAndDestroy(sel); |
|
152 |
|
153 DeleteEmailWithoutServiceL(); |
|
154 IMUM_OUT(); |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // CEmailPreCreation::DeleteAllPreCreatedEmailsL() |
|
159 // ---------------------------------------------------------------------------- |
|
160 // |
|
161 CMsvOperation* CEmailPreCreation::DeleteAllPreCreatedEmailsL( |
|
162 TMsvId aServiceId, |
|
163 TRequestStatus& aStatus) |
|
164 { |
|
165 IMUM_CONTEXT( CEmailPreCreation::DeleteAllPreCreatedEmailsL, 0, KImumMtmLog ); |
|
166 IMUM_IN(); |
|
167 |
|
168 // Do deletion synchronously so that we can guarantee that the |
|
169 // Email editor will not be launched with a message which |
|
170 // we are about to delete. |
|
171 DeleteAllPreCreatedEmailsL( aServiceId ); |
|
172 |
|
173 CMsvOperation* op = CMsvCompletedOperation::NewL( |
|
174 iEntry->Session(), KUidMsvLocalServiceMtm, KNullDesC8, |
|
175 KMsvLocalServiceIndexEntryId, aStatus); |
|
176 IMUM_OUT(); |
|
177 return op; |
|
178 } |
|
179 |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CEmailPreCreation::FindPreCreatedEmailL() |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 TMsvId CEmailPreCreation::FindPreCreatedEmailL( |
|
186 TMsvId aServiceId, |
|
187 TMsvId aExclude) |
|
188 { |
|
189 IMUM_CONTEXT( CEmailPreCreation::FindPreCreatedEmailL, 0, KImumMtmLog ); |
|
190 IMUM_IN(); |
|
191 |
|
192 TMsvId ret = KMsvNullIndexEntryId; |
|
193 if(iEntry->EntryId() != KPreCreatedMsgFolderId) |
|
194 { |
|
195 iEntry->SetEntryL(KPreCreatedMsgFolderId); |
|
196 } |
|
197 // Search children for invisible messages which match service id. |
|
198 TInt child = iEntry->Count(); |
|
199 while(child--) |
|
200 { |
|
201 TMsvEntry entry = (*iEntry)[child]; |
|
202 if( (!entry.Visible()) && |
|
203 (!entry.InPreparation()) && |
|
204 (entry.iServiceId == aServiceId) && |
|
205 (entry.Id() != aExclude) ) |
|
206 { |
|
207 ret = entry.Id(); |
|
208 // set InPreparation flag |
|
209 iEntry->SetEntryL( ret ); |
|
210 entry.SetInPreparation( ETrue ); |
|
211 iEntry->ChangeL( entry ); |
|
212 break; |
|
213 } |
|
214 } |
|
215 IMUM_OUT(); |
|
216 return ret; |
|
217 } |
|
218 |
|
219 |
|
220 // ---------------------------------------------------------------------------- |
|
221 // CEmailPreCreation::ConstructL() |
|
222 // ---------------------------------------------------------------------------- |
|
223 // |
|
224 void CEmailPreCreation::ConstructL() |
|
225 { |
|
226 IMUM_CONTEXT( CEmailPreCreation::ConstructL, 0, KImumMtmLog ); |
|
227 IMUM_IN(); |
|
228 |
|
229 TMsvSelectionOrdering ordering; |
|
230 ordering.SetShowInvisibleEntries(ETrue); |
|
231 iEntry = CMsvEntry::NewL( |
|
232 iMailboxApi.MsvSession(), KPreCreatedMsgFolderId, ordering ); |
|
233 IMUM_OUT(); |
|
234 } |
|
235 |
|
236 |
|
237 // ---------------------------------------------------------------------------- |
|
238 // CEmailPreCreation::ServiceUsesMHTMLEncodingL() |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 TBool CEmailPreCreation::ServiceUsesMHTMLEncodingL( TMsvId aServiceId ) |
|
242 { |
|
243 IMUM_CONTEXT( CEmailPreCreation::ServiceUsesMHTMLEncodingL, 0, KImumMtmLog ); |
|
244 IMUM_IN(); |
|
245 |
|
246 CImumInSettingsData* accountsettings = |
|
247 iMailboxApi.MailboxServicesL().LoadMailboxSettingsL( |
|
248 aServiceId ); |
|
249 CleanupStack::PushL( accountsettings ); |
|
250 |
|
251 TInt encoding = ImumMboxSettingsUtils::QuickGetL<TInt32>( |
|
252 *accountsettings, |
|
253 TImumInSettings::EKeyDefaultMsgCharSet ); |
|
254 |
|
255 CleanupStack::PopAndDestroy( accountsettings ); |
|
256 accountsettings = NULL; |
|
257 IMUM_OUT(); |
|
258 |
|
259 return ( encoding == TImumInSettings::EValueEncodingMHtmlAsMime ) || |
|
260 ( encoding == TImumInSettings::EValueEncodingMHtmlAltAsMime ); |
|
261 } |
|
262 |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CEmailPreCreation::DeleteEmailWithoutServiceL() |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 void CEmailPreCreation::DeleteEmailWithoutServiceL() |
|
269 { |
|
270 IMUM_CONTEXT( CEmailPreCreation::DeleteEmailWithoutServiceL, 0, KImumMtmLog ); |
|
271 IMUM_IN(); |
|
272 |
|
273 CMsvEntrySelection* smtpServices = |
|
274 MsvUiServiceUtilities::GetListOfAccountsWithMTML( |
|
275 iEntry->Session(), |
|
276 KSenduiMtmSmtpUid, |
|
277 ETrue ); |
|
278 CleanupStack::PushL( smtpServices ); |
|
279 |
|
280 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
281 CleanupStack::PushL( sel ); |
|
282 |
|
283 if(iEntry->EntryId() != KPreCreatedMsgFolderId) |
|
284 { |
|
285 iEntry->SetEntryL( KPreCreatedMsgFolderId ); |
|
286 } |
|
287 // Search children for invisible email messages which service not found |
|
288 TInt child = iEntry->Count(); |
|
289 while(child--) |
|
290 { |
|
291 const TMsvEntry& entry = (*iEntry)[child]; |
|
292 if( !entry.Visible() && |
|
293 entry.iMtm == KSenduiMtmSmtpUid && |
|
294 smtpServices->Find( entry.iServiceId ) == KErrNotFound ) |
|
295 { |
|
296 sel->AppendL(entry.Id()); |
|
297 } |
|
298 } |
|
299 |
|
300 if(sel->Count()) |
|
301 { |
|
302 // Do deletion synchronously so that we can guarantee that the |
|
303 // Email editor will not be launched with a message which we |
|
304 // are about to delete. |
|
305 TMsvLocalOperationProgress opProgress; |
|
306 iEntry->DeleteL(*sel, opProgress); |
|
307 } |
|
308 |
|
309 CleanupStack::PopAndDestroy( 2, smtpServices ); // CSI: 47 # sel, smtpServices. |
|
310 IMUM_OUT(); |
|
311 } |
|
312 |
|
313 // End of File |
|
314 |