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