|
1 // IMCVUTIL.CPP |
|
2 |
|
3 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 // All rights reserved. |
|
5 // This component and the accompanying materials are made available |
|
6 // under the terms of "Eclipse Public License v1.0" |
|
7 // which accompanies this distribution, and is available |
|
8 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 // |
|
10 // Initial Contributors: |
|
11 // Nokia Corporation - initial contribution. |
|
12 // |
|
13 // Contributors: |
|
14 // |
|
15 // Description: |
|
16 // |
|
17 |
|
18 #include <badesca.h> |
|
19 #include "IMCVUTIL.H" |
|
20 #include <miuthdr.h> |
|
21 #include "IMCVTEXT.H" |
|
22 #include <logwrap.h> |
|
23 #include <logwraplimits.h> |
|
24 #include <msvapi.h> |
|
25 |
|
26 #define __IMUT_NO_IM_EMAIL_EVENT_LOGGING //Remove this line to enable e-mail logging |
|
27 |
|
28 EXPORT_C CImcvUtils* CImcvUtils::NewL() |
|
29 { |
|
30 CImcvUtils* self = NewLC(); |
|
31 CleanupStack::Pop(); |
|
32 return self; |
|
33 } |
|
34 |
|
35 EXPORT_C CImcvUtils* CImcvUtils::NewLC() |
|
36 { |
|
37 CImcvUtils* self=new (ELeave) CImcvUtils(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CImcvUtils::~CImcvUtils() |
|
44 { |
|
45 } |
|
46 |
|
47 CImcvUtils::CImcvUtils() |
|
48 { |
|
49 } |
|
50 |
|
51 void CImcvUtils::ConstructL() |
|
52 { |
|
53 iPriority=EMsvMediumPriority; |
|
54 } |
|
55 |
|
56 EXPORT_C void CImcvUtils::ReceiptFieldsL(CDesC8Array& aReceiptFields) |
|
57 { |
|
58 aReceiptFields.Reset(); |
|
59 aReceiptFields.AppendL(KImcvReturnReceiptToPrompt); |
|
60 aReceiptFields.AppendL(KImcvReturnXReceiptToPrompt); |
|
61 aReceiptFields.AppendL(KImcvMsgDispositionTo); |
|
62 aReceiptFields.AppendL(KImcvMsgDispositionOptions); |
|
63 } |
|
64 |
|
65 EXPORT_C void CImcvUtils::PriorityFieldsL(CDesC8Array& aPriorityFields) |
|
66 { |
|
67 aPriorityFields.Reset(); |
|
68 aPriorityFields.AppendL(KImcvPriorityPrompt); |
|
69 aPriorityFields.AppendL(KImcvXPriorityPrompt); |
|
70 aPriorityFields.AppendL(KImcvXMSMailPriorityPrompt); |
|
71 aPriorityFields.AppendL(KImcvImportancePrompt); |
|
72 } |
|
73 |
|
74 EXPORT_C void CImcvUtils::SendReturnReceiptFieldsL(CDesC8Array& aReturnReceiptFields) |
|
75 { // appends field to the array |
|
76 //At the moment it returns KImcvMsgDispositionTo only. In future it could change! |
|
77 aReturnReceiptFields.Reset(); |
|
78 aReturnReceiptFields.AppendL(KImcvMsgDispositionTo); |
|
79 } |
|
80 |
|
81 EXPORT_C void CImcvUtils::SendPriorityFieldsL(CDesC8Array& aSendPriorityFields) |
|
82 { |
|
83 aSendPriorityFields.Reset(); |
|
84 aSendPriorityFields.AppendL(KImcvXPriorityPrompt); |
|
85 } |
|
86 |
|
87 |
|
88 void CImcvUtils::SendImportanceFieldsL(CDesC8Array& aSendImportanceFields) |
|
89 { |
|
90 aSendImportanceFields.Reset(); |
|
91 aSendImportanceFields.AppendL(KImcvImportancePrompt); |
|
92 } |
|
93 |
|
94 EXPORT_C TBool CImcvUtils::EvaluateReturnReceiptFields(const TDesC8& aFieldName) |
|
95 { |
|
96 if (aFieldName.MatchF(KImcvReturnReceiptToPrompt)>=0 || |
|
97 aFieldName.MatchF(KImcvReturnXReceiptToPrompt)>=0 || |
|
98 aFieldName.MatchF(KImcvMsgDispositionTo)>=0) |
|
99 return ETrue; |
|
100 return EFalse; |
|
101 } |
|
102 |
|
103 |
|
104 EXPORT_C TMsvPriority CImcvUtils::EvaluatePriorityText(const TDesC8& aPriority) |
|
105 {// check for high, low and then medium. |
|
106 //Precedence: bulk, special-delivery, first-class, list and junk, should not be used to set any Priority as RFC2076 defines |
|
107 //them as Non-standard controversial and discouraged |
|
108 TInt number=ConvertPriorityIntoNumber(aPriority); |
|
109 if (aPriority.MatchF(KImportanceHighest)>=0 || |
|
110 aPriority.MatchF(KImportanceHigh)>=0 || |
|
111 number<KPriorityNormal || |
|
112 //because match returns found if we search for urgent in a non-urgent string, it should be double checked. |
|
113 (aPriority.MatchF(KImPriorityUrgent)>=0 && aPriority.MatchF(KImPriorityNonUrgent)<0)) |
|
114 { |
|
115 iPriority=EMsvHighPriority; |
|
116 return iPriority; |
|
117 } |
|
118 if (aPriority.MatchF(KImportanceLowest)>=0 || |
|
119 aPriority.MatchF(KImportanceLow)>=0 || |
|
120 aPriority.MatchF(KImPriorityNonUrgent)>=0 || |
|
121 number>KPriorityNormal) |
|
122 {//set to low only if it is medium. |
|
123 if (iPriority==EMsvMediumPriority) |
|
124 iPriority=EMsvLowPriority; |
|
125 } |
|
126 return iPriority; |
|
127 } |
|
128 |
|
129 TInt CImcvUtils::ConvertPriorityIntoNumber(const TDesC8& aPriority) |
|
130 { |
|
131 // if aPriority is null string, set priority to normal |
|
132 if (!aPriority.Length()) |
|
133 return KPriorityNormal; |
|
134 // aPriority can be a digit (1..5) or a string or both. In most cases it is digit. |
|
135 //Hence search for digit in the string first and if it is not found, then search for the strings |
|
136 //search for digits |
|
137 TInt p=KPriorityHigh; //1 |
|
138 while(p<6) |
|
139 { |
|
140 TBuf8<4> buf(KWildChars); //set the wild chars when matching |
|
141 TBuf8<1> num; |
|
142 num.Num(p); |
|
143 buf.Insert(1,num); |
|
144 if (aPriority.Match(buf)>=0) //means found |
|
145 return p; |
|
146 p++; |
|
147 } |
|
148 return KPriorityNormal; |
|
149 } |
|
150 |
|
151 |
|
152 |
|
153 // |
|
154 //CImLogMessage |
|
155 // |
|
156 |
|
157 |
|
158 EXPORT_C CImLogMessage* CImLogMessage::NewL(RFs& aFs, TInt aPriority) |
|
159 { |
|
160 CImLogMessage* self = new (ELeave) CImLogMessage(aPriority); |
|
161 CleanupStack::PushL(self); |
|
162 self->ConstructL(aFs,aPriority); |
|
163 CleanupStack::Pop(); |
|
164 return self; |
|
165 } |
|
166 |
|
167 CImLogMessage::CImLogMessage(TInt aPriority) |
|
168 : CMsgActive(aPriority) |
|
169 { |
|
170 } |
|
171 |
|
172 void CImLogMessage::ConstructL(RFs& aFs,TInt aPriority) |
|
173 { |
|
174 iLogWrapper=CLogWrapper::NewL(aFs,aPriority); |
|
175 CActiveScheduler::Add(this); |
|
176 } |
|
177 |
|
178 CImLogMessage::~CImLogMessage() |
|
179 { |
|
180 Cancel(); |
|
181 Reset(); |
|
182 delete iLogWrapper; |
|
183 } |
|
184 |
|
185 EXPORT_C CLogEvent& CImLogMessage::LogEvent() |
|
186 { |
|
187 if (!iLogEvent) |
|
188 { |
|
189 TRAP_IGNORE(iLogEvent=CLogEvent::NewL()); |
|
190 } |
|
191 return *iLogEvent; |
|
192 } |
|
193 |
|
194 EXPORT_C CLogBase& CImLogMessage::LogBase() |
|
195 { |
|
196 return iLogWrapper->Log(); |
|
197 } |
|
198 |
|
199 |
|
200 EXPORT_C void CImLogMessage::Start(TInt aError,TRequestStatus& aStatus) |
|
201 { |
|
202 if (aError != KErrNone) |
|
203 { |
|
204 TBuf<KLogMaxStatusLength> status; |
|
205 if (GetString(status, R_LOG_DEL_FAILED) == KErrNone) |
|
206 iLogEvent->SetStatus(status); |
|
207 } |
|
208 |
|
209 Queue(aStatus); |
|
210 |
|
211 #ifndef __IMUT_NO_IM_EMAIL_EVENT_LOGGING |
|
212 iLogWrapper->Log().AddEvent(*iLogEvent,iStatus); |
|
213 SetActive(); |
|
214 #else |
|
215 Complete(KErrNone); |
|
216 #endif |
|
217 |
|
218 } |
|
219 |
|
220 EXPORT_C TInt CImLogMessage::GetString(TDes& aString, TInt aId) const |
|
221 { |
|
222 return iLogWrapper->Log().GetString(aString, aId); |
|
223 } |
|
224 |
|
225 void CImLogMessage::DoRunL() |
|
226 { |
|
227 } |
|
228 |
|
229 void CImLogMessage::DoCancel() |
|
230 { |
|
231 iLogWrapper->Log().Cancel(); |
|
232 CMsgActive::DoCancel(); |
|
233 } |
|
234 |
|
235 EXPORT_C void CImLogMessage::Reset() |
|
236 { |
|
237 delete iLogEvent; |
|
238 iLogEvent=NULL; |
|
239 } |
|
240 |
|
241 void CImLogMessage::DoComplete(TInt& aStatus) |
|
242 {//always complete with KErrnone. We don't care if logging fails. |
|
243 aStatus=KErrNone; |
|
244 } |
|
245 |
|
246 // |
|
247 // Check the available disk space and leave if it is insufficient |
|
248 // |
|
249 EXPORT_C void ImCheckDiskSpace::LeaveIfLowDiskL(RFs& aFs, TInt aCurrentDrive) |
|
250 { |
|
251 TVolumeInfo volumeInfo; |
|
252 User::LeaveIfError(aFs.Volume(volumeInfo, aCurrentDrive)); |
|
253 |
|
254 if (volumeInfo.iFree < KMinimumDiskSpaceForSync) |
|
255 User::Leave(KErrDiskFull); |
|
256 } |