|
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: Handles OMA Email Notification messages. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 |
|
22 #include <AlwaysOnlineManagerCommon.h> |
|
23 #include <ImumInSettingsKeys.h> |
|
24 #include <ImumInMailboxServices.h> |
|
25 |
|
26 |
|
27 #include "AlwaysOnlineEmailEMNResolver.h" |
|
28 #include "AlwaysOnlineEmailPluginLogging.h" |
|
29 #include "AlwaysOnlineEmailLoggingTools.h" |
|
30 |
|
31 // Literals used when trying to match a mailbox |
|
32 // to a received EMN message |
|
33 _LIT(KMailatPattern, "*mailat:*@*"); |
|
34 _LIT(KImapUserPattern, "*imap://*@*"); // Same as KImapPattern, but includes also username |
|
35 _LIT(KPopUserPattern, "*pop://*;*@*"); // Include username and auth |
|
36 _LIT(KPopUserNoAuthPattern, "*pop://*@*"); // Same as KPopUserPattern, but does not include auth |
|
37 // Literals used when trying to parse username, server |
|
38 _LIT(KForwardSlashes, "//"); |
|
39 _LIT(KAtSign, "@"); |
|
40 _LIT(KSemicolon, ";"); |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CAlwaysOnlineEmailEMNResolver::CAlwaysOnlineEmailEMNResolver() |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 CAlwaysOnlineEmailEMNResolver::CAlwaysOnlineEmailEMNResolver() |
|
49 { |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CAlwaysOnlineEmailEMNResolver::~CAlwaysOnlineEmailEMNResolver() |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CAlwaysOnlineEmailEMNResolver::~CAlwaysOnlineEmailEMNResolver() |
|
57 { |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CAlwaysOnlineEmailEMNResolver::ConstructL() |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 void CAlwaysOnlineEmailEMNResolver::ConstructL() |
|
65 { |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CAlwaysOnlineEmailEMNResolver::NewL() |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CAlwaysOnlineEmailEMNResolver* CAlwaysOnlineEmailEMNResolver::NewL() |
|
73 { |
|
74 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::NewL" ); |
|
75 CAlwaysOnlineEmailEMNResolver* self = NewLC(); |
|
76 CleanupStack::Pop( self ); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CAlwaysOnlineEmailEMNResolver::NewLC() |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CAlwaysOnlineEmailEMNResolver* CAlwaysOnlineEmailEMNResolver::NewLC() |
|
86 { |
|
87 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::NewLC" ); |
|
88 CAlwaysOnlineEmailEMNResolver* self = |
|
89 new ( ELeave ) CAlwaysOnlineEmailEMNResolver(); |
|
90 CleanupStack::PushL( self ); |
|
91 self->ConstructL(); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 //----------------------------------------------------------------------------- |
|
97 // CAlwaysOnlineEmailEMNResolver::FindEMNMailbox |
|
98 //----------------------------------------------------------------------------- |
|
99 CAlwaysOnlineEmailAgentBase* CAlwaysOnlineEmailEMNResolver::FindEMNMailbox( |
|
100 TDesC& aMailboxURI, CAOEmailAgentArray& aMailAgentArray ) |
|
101 { |
|
102 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::FindEMNMailbox" ); |
|
103 CAlwaysOnlineEmailAgentBase* mailAgent = NULL; |
|
104 TImumDaSettings::TTextEmailAddress emailAddress; |
|
105 TImumDaSettings::TTextServerAddress incomingServer; |
|
106 TImumDaSettings::TTextUserName username; |
|
107 |
|
108 const TInt count = aMailAgentArray.Count(); |
|
109 |
|
110 for ( TInt loop = 0; loop < count && !mailAgent; loop++) |
|
111 { |
|
112 TBool isEmn = aMailAgentArray[loop]->IsEmn(); |
|
113 |
|
114 // We are only interested of those mailboxes which have EMN on. |
|
115 if ( isEmn ) |
|
116 { |
|
117 // Get needed settings |
|
118 aMailAgentArray[loop]->EmailAddress( emailAddress ); |
|
119 aMailAgentArray[loop]->ServerAddress( incomingServer ); |
|
120 aMailAgentArray[loop]->Username( username ); |
|
121 TBool isImap = aMailAgentArray[loop]->IsImap4(); |
|
122 |
|
123 KAOEMAIL_LOGGER_WRITE_FORMAT("aMailboxURI = %s", aMailboxURI.Ptr() ); |
|
124 |
|
125 // <emn mailbox="mailat:username@mail.somehost.com"/> |
|
126 if ( aMailboxURI.Match( KMailatPattern ) == 0 && |
|
127 aMailboxURI.Find( emailAddress ) > 0 ) |
|
128 { |
|
129 mailAgent = aMailAgentArray[loop]; |
|
130 } |
|
131 // <emn mailbox="imap://username@mail.somehost.com"/> |
|
132 else if ( aMailboxURI.Match( KImapUserPattern ) == 0 && isImap ) |
|
133 { |
|
134 if ( HandleEmnImapUserURI( aMailboxURI, username, incomingServer ) ) |
|
135 { |
|
136 mailAgent = aMailAgentArray[loop]; |
|
137 } |
|
138 } |
|
139 // <emn mailbox="pop://userxyz;auth=3598302@mail.somehost.com"/> |
|
140 else if ( aMailboxURI.Match( KPopUserPattern ) == 0 && !isImap ) |
|
141 { |
|
142 if ( HandleEmnPopUserURI( aMailboxURI, username, incomingServer ) ) |
|
143 { |
|
144 mailAgent = aMailAgentArray[loop]; |
|
145 } |
|
146 } |
|
147 // <emn mailbox="pop://userxyz@mail.somehost.com"/> |
|
148 else if ( aMailboxURI.Match( KPopUserNoAuthPattern ) == 0 && !isImap ) |
|
149 { |
|
150 if ( HandleEmnPopNoAuthURI( aMailboxURI, username, incomingServer ) ) |
|
151 { |
|
152 mailAgent = aMailAgentArray[loop]; |
|
153 } |
|
154 } |
|
155 else |
|
156 { |
|
157 KAOEMAIL_LOGGER_WRITE_FORMAT("Mailbox 0x%x is EMN mailbox, but there was no match", aMailAgentArray[loop]->MailboxId() ); |
|
158 } |
|
159 } |
|
160 else |
|
161 { |
|
162 KAOEMAIL_LOGGER_WRITE_FORMAT("Mailbox 0x%x is not EMN mailbox", aMailAgentArray[loop]->MailboxId() ); |
|
163 } |
|
164 } |
|
165 |
|
166 return mailAgent; |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement |
|
171 // ---------------------------------------------------------------------------- |
|
172 TInt CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement( |
|
173 const TDesC8& aParameters, |
|
174 TEMNElement& aElement ) const |
|
175 { |
|
176 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement" ); |
|
177 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement(): Dispatch mailbox URI and timestamp from parameters"); |
|
178 AOLOG_WRV( "Dispatch mailbox URI and timestamp from parameters", EAoLogSt3 ); |
|
179 |
|
180 // Presume that wrong type of parameter is given |
|
181 TInt err = KErrNotSupported; |
|
182 |
|
183 // Unpack parameters to see to which mailbox EMN is for |
|
184 TPckgBuf<TEMNElement> paramPack; |
|
185 |
|
186 // Make sure that the parameter length matches TEMNElement length and |
|
187 // extract mailbox and timestamp values. |
|
188 if ( aParameters.Size() == sizeof( TEMNElement ) ) |
|
189 { |
|
190 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement(): EMN parameters not corrupted, extracting... " ); |
|
191 AOLOG_WRV( "EMN parameters not corrupted, extracting...", EAoLogSt3 ); |
|
192 |
|
193 paramPack.Copy( aParameters ); |
|
194 |
|
195 aElement.mailbox.Zero(); |
|
196 aElement.mailbox.Append( paramPack().mailbox ); |
|
197 |
|
198 aElement.timestamp = paramPack().timestamp; |
|
199 |
|
200 err = KErrNone; |
|
201 } |
|
202 else |
|
203 { |
|
204 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineEmailEMNResolver::ParameterDispatchTEMNElement(): Corrupted EMN parameters?!?!"); |
|
205 } |
|
206 |
|
207 return err; |
|
208 } |
|
209 |
|
210 //----------------------------------------------------------------------------- |
|
211 // Private functions |
|
212 //----------------------------------------------------------------------------- |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // CAlwaysOnlineEmailEMNResolver::HandleEmnImapUserURI |
|
216 // ---------------------------------------------------------------------------- |
|
217 TBool CAlwaysOnlineEmailEMNResolver::HandleEmnImapUserURI( |
|
218 const TDesC& aURI, |
|
219 const TDesC8& aUsername, |
|
220 const TDesC& aServer ) const |
|
221 { |
|
222 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::HandleEmnImapUserURI" ); |
|
223 // Try to match with following EMN message |
|
224 // <emn mailbox="imap://username@mail.somehost.com/folder;UIDVALIDITY=385759045/;UID=20"/> |
|
225 // <emn mailbox="imap://username@mail.somehost.com/"/> |
|
226 |
|
227 // endPart = username@mail.somehost.com/folder;UIDVALIDITY=385759045/;UID=20 |
|
228 TInt pos = aURI.Find( KForwardSlashes ); |
|
229 // Step over forward slashes |
|
230 pos += 2; // CSI: 47 # see comment above |
|
231 // Strip "imap://" away |
|
232 TPtrC endPart( aURI.Right( aURI.Length() - ( pos ) ) ); |
|
233 |
|
234 // Username is from beginning to @ character |
|
235 pos = endPart.Find( KAtSign ); |
|
236 TImumDaSettings::TTextUserName user; |
|
237 user.Copy( endPart.Left( pos ) ); |
|
238 |
|
239 // Strip username and '@' character away |
|
240 endPart.Set( endPart.Right( endPart.Length() - pos - 1 ) ); |
|
241 TPtrC server( endPart ); |
|
242 |
|
243 // Do we have a winner? |
|
244 return ( aUsername.Compare( user ) == 0 && |
|
245 server.Find( aServer ) == 0 ); |
|
246 } |
|
247 |
|
248 // ---------------------------------------------------------------------------- |
|
249 // CAlwaysOnlineEmailEMNResolver::HandleEmnPopUserURI |
|
250 // ---------------------------------------------------------------------------- |
|
251 TBool CAlwaysOnlineEmailEMNResolver::HandleEmnPopUserURI( |
|
252 const TDesC& aURI, |
|
253 const TDesC8& aUsername, |
|
254 const TDesC& aServer ) const |
|
255 { |
|
256 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::HandleEmnPopUserURI" ); |
|
257 // Try to match with following EMN message |
|
258 // <emn mailbox="pop://userxyz;auth=3598302@mail.somehost.com"/> |
|
259 |
|
260 TInt pos = aURI.Find( KForwardSlashes ); |
|
261 // Step over forward slashes |
|
262 pos += 2; // CSI: 47 # see comment above |
|
263 // Strip "pop://" away |
|
264 TPtrC endPart( aURI.Right( aURI.Length() - ( pos ) ) ); |
|
265 |
|
266 // Username is from beginning to ; character |
|
267 pos = endPart.Find( KSemicolon ); |
|
268 TImumDaSettings::TTextUserName user; |
|
269 user.Copy( endPart.Left( pos ) ); |
|
270 |
|
271 // ";auth=3598302" omitted |
|
272 |
|
273 // server name |
|
274 pos = endPart.Find( KAtSign ); |
|
275 // Step over at sign |
|
276 pos++; |
|
277 |
|
278 // server = mail.somehost.com |
|
279 TPtrC server( endPart.Right( endPart.Length() - pos ) ); |
|
280 |
|
281 // Do we have a winner? |
|
282 return ( aUsername.Compare( user ) == 0 && |
|
283 aServer.Compare( server ) == 0 ); |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CAlwaysOnlineEmailEMNResolver::HandleEmnPopNoAuthURI |
|
288 // ---------------------------------------------------------------------------- |
|
289 TBool CAlwaysOnlineEmailEMNResolver::HandleEmnPopNoAuthURI( |
|
290 const TDesC& aURI, |
|
291 const TDesC8& aUsername, |
|
292 const TDesC& aServer ) const |
|
293 { |
|
294 AOLOG_IN( "CAlwaysOnlineEmailEMNResolver::HandleEmnPopNoAuthURI" ); |
|
295 // Try to match with following EMN message |
|
296 // <emn mailbox="pop://userxyz@mail.somehost.com"/> |
|
297 |
|
298 TInt pos = aURI.Find( KForwardSlashes ); |
|
299 // Step over forward slashes |
|
300 pos += 2; // CSI: 47 # see comment above |
|
301 // Strip "pop://" away |
|
302 TPtrC endPart( aURI.Right( aURI.Length() - ( pos ) ) ); |
|
303 |
|
304 // Username is from beginning to @ character |
|
305 pos = endPart.Find( KAtSign ); |
|
306 TImumDaSettings::TTextUserName user; |
|
307 user.Copy( endPart.Left( pos ) ); |
|
308 // Step over at sign |
|
309 pos++; |
|
310 // server = mail.somehost.com |
|
311 TPtrC server( endPart.Right( endPart.Length() - pos ) ); |
|
312 |
|
313 // Do we have a winner? |
|
314 return ( aUsername.Compare( user ) == 0 && |
|
315 aServer.Compare( server ) == 0 ); |
|
316 |
|
317 } |
|
318 |
|
319 // End of File |