|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "tmrcmailremoteattachmentpluginurlparser.h" |
|
19 #include "cfsmailcommon.h" |
|
20 #include "emailtrace.h" |
|
21 |
|
22 #include <uri16.h> |
|
23 #include <delimitedpath16.h> |
|
24 |
|
25 // Unnamed namespace for local definitions |
|
26 namespace { // namespace::codescanner |
|
27 |
|
28 // Length for path buffer |
|
29 const TInt KPathBufferLen( 64 ); |
|
30 |
|
31 // Mail ID separator |
|
32 _LIT( KMailIDSepararor, "." ); |
|
33 |
|
34 } // namespace |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // TMRCMailRemoteAttachmentPluginURLParser::TMRCMailRemoteAttachmentPluginURLParser |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 TMRCMailRemoteAttachmentPluginURLParser::TMRCMailRemoteAttachmentPluginURLParser() |
|
43 { |
|
44 FUNC_LOG; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // TMRCMailRemoteAttachmentPluginURLParser::~TMRCMailRemoteAttachmentPluginURLParser |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 TMRCMailRemoteAttachmentPluginURLParser::~TMRCMailRemoteAttachmentPluginURLParser() |
|
52 { |
|
53 FUNC_LOG; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // TMRCMailRemoteAttachmentPluginURLParser::Parse |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 TInt TMRCMailRemoteAttachmentPluginURLParser::Parse( |
|
61 const TDesC& aUri ) |
|
62 { |
|
63 FUNC_LOG; |
|
64 |
|
65 TInt err( KErrNone ); |
|
66 |
|
67 iMailboxUid.SetNullId(); |
|
68 iFolderUid.SetNullId(); |
|
69 iMessageUid.SetNullId(); |
|
70 iMessagepartUid.SetNullId(); |
|
71 |
|
72 // Parse URI cmail://mailboxuid/folder/message/messagepart/ |
|
73 // mailboxuid will be the host and rest is the folder structure |
|
74 // |
|
75 TUriParser16 uriparser; |
|
76 TInt error = uriparser.Parse( aUri ); |
|
77 |
|
78 // First we will get mailbox UID |
|
79 TPtrC mailboxuid( uriparser.Extract( EUriHost ) ); |
|
80 ParseMailId( mailboxuid ); |
|
81 |
|
82 TDelimitedPathParser16 pathParser; |
|
83 TPtrC uripath( uriparser.Extract( EUriPath ) ); |
|
84 pathParser.Parse( uripath ); |
|
85 |
|
86 TBuf<KPathBufferLen> pathBuffer; |
|
87 TPtrC pathBufferPtr( pathBuffer ); |
|
88 err = pathParser.Peek( pathBufferPtr ); |
|
89 while ( pathBufferPtr.Length() && err == KErrNone ) |
|
90 { |
|
91 err = ParseMailId( pathBufferPtr ); |
|
92 pathParser.Inc(); |
|
93 err = pathParser.Peek( pathBufferPtr ); |
|
94 } |
|
95 |
|
96 if ( iMailboxUid.IsNullId() || |
|
97 iFolderUid.IsNullId() || |
|
98 iMessageUid.IsNullId() || |
|
99 iMessagepartUid.IsNullId() ) |
|
100 { |
|
101 // Not all UIDs were found |
|
102 err = KErrNotFound; |
|
103 } |
|
104 |
|
105 return err; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // TMRCMailRemoteAttachmentPluginURLParser::Parse |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void TMRCMailRemoteAttachmentPluginURLParser::SetMailId( |
|
113 TFSMailMsgId& aMailId ) |
|
114 { |
|
115 FUNC_LOG; |
|
116 |
|
117 if ( iMailboxUid.IsNullId() ) |
|
118 { |
|
119 iMailboxUid = aMailId; |
|
120 } |
|
121 else if ( iFolderUid.IsNullId() ) |
|
122 { |
|
123 iFolderUid = aMailId; |
|
124 } |
|
125 else if ( iMessageUid.IsNullId() ) |
|
126 { |
|
127 iMessageUid = aMailId; |
|
128 } |
|
129 else if ( iMessagepartUid.IsNullId() ) |
|
130 { |
|
131 iMessagepartUid = aMailId; |
|
132 } |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // TMRCMailRemoteAttachmentPluginURLParser::ParseMailId |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt TMRCMailRemoteAttachmentPluginURLParser::ParseMailId( |
|
140 TPtrC& aMailId ) |
|
141 { |
|
142 FUNC_LOG; |
|
143 |
|
144 TInt err( KErrNone ); |
|
145 TInt pos( KErrNotFound ); |
|
146 |
|
147 // Now we have pathpart in buffer. Each pathpart contains |
|
148 // TFSMailMsgId if following format: pluginuid.pluginid |
|
149 // We need to parse that further to plugin UID and plugin ID |
|
150 pos = aMailId.Find( KMailIDSepararor ); |
|
151 if ( pos != KErrNotFound ) |
|
152 { |
|
153 TPtrC mailUidStr( aMailId.Left( pos ) ); |
|
154 TPtrC mailIdStr( aMailId.Mid( pos + 1 ) ); |
|
155 |
|
156 TUint pluginUid(0); |
|
157 TLex numberParser( mailUidStr ); |
|
158 err = numberParser.Val(pluginUid); |
|
159 |
|
160 if ( KErrNone == err ) |
|
161 { |
|
162 // Then parse plugin ID |
|
163 TUint pluginId(0); |
|
164 numberParser = mailIdStr; |
|
165 err = numberParser.Val(pluginId); |
|
166 |
|
167 TFSMailMsgId mailId( pluginUid, pluginId ); |
|
168 SetMailId( mailId ); |
|
169 } |
|
170 } |
|
171 |
|
172 return err; |
|
173 } |
|
174 |
|
175 // EOF |