40
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 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: CVMessageParser header
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#ifndef VMESSAGEPARSER_H
|
|
20 |
#define VMESSAGEPARSER_H
|
|
21 |
|
|
22 |
#include "omadsfolderobject.h"
|
|
23 |
|
|
24 |
|
|
25 |
// CONSTANTS
|
|
26 |
_LIT(KVMsgTagBegin, "BEGIN:");
|
|
27 |
_LIT(KVMsgTagEnd, "END:");
|
|
28 |
_LIT(KVMsgTagStatus, "X-IRMC-STATUS:");
|
|
29 |
_LIT(KVMsgTagBox, "X-IRMC-BOX:");
|
|
30 |
_LIT(KVMsgTagVersion, "VERSION:");
|
|
31 |
_LIT(KVMsgTagName, "N:");
|
|
32 |
_LIT(KVMsgTagTelephone, "TEL:");
|
|
33 |
_LIT(KVMsgTagDateTime, "X-NOK-DT:");
|
|
34 |
_LIT(KVMsgTagDate, "Date:");
|
|
35 |
_LIT(KVMsgSectionVMsg, "VMSG");
|
|
36 |
_LIT(KVMsgSectionVCard, "VCARD");
|
|
37 |
_LIT(KVMsgSectionVEnv, "VENV");
|
|
38 |
_LIT(KVMsgSectionVBody, "VBODY");
|
|
39 |
_LIT(KVMsgSectionEndVBody, "END:VBODY");
|
|
40 |
_LIT(KVMsgLineFeed, "\n");
|
|
41 |
_LIT(KDesNoData, "");
|
|
42 |
_LIT(KVMsgVersion, "1.1");
|
|
43 |
_LIT(KVMsgVCardVersion, "2.1");
|
|
44 |
_LIT(KVMsgStatusRead, "READ");
|
|
45 |
_LIT(KVMsgStatusUnread, "UNREAD");
|
|
46 |
_LIT(KVMsgStatusSent, "SENT");
|
|
47 |
_LIT(KVMsgStatusUnsent, "UNSENT");
|
|
48 |
_LIT(KFolderInbox, "INBOX");
|
|
49 |
_LIT(KFolderOutbox, "OUTBOX");
|
|
50 |
_LIT(KFolderDraft, "DRAFT");
|
|
51 |
_LIT(KFolderSent, "SENT");
|
|
52 |
_LIT(KFolderMyFolders, "MY FOLDERS");
|
|
53 |
_LIT(KFolderUnspesified, "");
|
|
54 |
const TInt KIndentStepSize = 1;
|
|
55 |
|
|
56 |
|
|
57 |
// FORWARD DECLARATIONS
|
|
58 |
class CRichText;
|
|
59 |
|
|
60 |
// CLASS DECLARATION
|
|
61 |
|
|
62 |
const TInt KNameMaxLength = 32;
|
|
63 |
const TInt KNumberMaxLength = 48;
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Class CVMessageParser
|
|
67 |
* Helper class for converting SMS message information to/from text/x-VMessage.
|
|
68 |
*/
|
|
69 |
class CVMessageParser: public CBase
|
|
70 |
{
|
|
71 |
public: // Data types
|
|
72 |
|
|
73 |
struct TTelephoneNumber
|
|
74 |
{
|
|
75 |
TBuf<KNameMaxLength> iName;
|
|
76 |
TBuf<KNumberMaxLength> iNumber;
|
|
77 |
};
|
|
78 |
|
|
79 |
public: // Constructors and destructor
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Two-phased constructor.
|
|
83 |
*/
|
|
84 |
static CVMessageParser* NewL();
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Two-phased constructor leaving item to clenup stack
|
|
88 |
*/
|
|
89 |
static CVMessageParser* NewLC();
|
|
90 |
|
|
91 |
/**
|
|
92 |
* Destructor.
|
|
93 |
*/
|
|
94 |
~CVMessageParser();
|
|
95 |
|
|
96 |
private: // Private constructors
|
|
97 |
|
|
98 |
/**
|
|
99 |
* C++ default constructor.
|
|
100 |
* C++ default constructor can NOT contain any code, that
|
|
101 |
* might leave.
|
|
102 |
*/
|
|
103 |
CVMessageParser();
|
|
104 |
|
|
105 |
/**
|
|
106 |
* By default Symbian 2nd phase constructor is private.
|
|
107 |
*/
|
|
108 |
void ConstructL();
|
|
109 |
|
|
110 |
public: // New functions
|
|
111 |
|
|
112 |
/**
|
|
113 |
* This function decodes received text/x-vMessage and stores the data
|
|
114 |
* to member variables of this class.
|
|
115 |
*
|
|
116 |
* @param aMessage IN: buffer containing received text/x-vMessage
|
|
117 |
* @return TInt Result, Length of SMS message body or negative error code.
|
|
118 |
*/
|
|
119 |
TInt ParseMessageL( const TDesC8& aMessage );
|
|
120 |
|
|
121 |
/**
|
|
122 |
* This function constructs a text/x-vMessage based on the data stored
|
|
123 |
* to member variables of this class.
|
|
124 |
*
|
|
125 |
* @param aMessage OUT: dynamic buffer where text/x-vMessage is constructed
|
|
126 |
*/
|
|
127 |
void ConstructMessageL( CBufBase& aMessage );
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Initialises all variables to with default values
|
|
131 |
*/
|
|
132 |
void ResetAll();
|
|
133 |
|
|
134 |
/**
|
|
135 |
* Loads message body data to given rich text object
|
|
136 |
*
|
|
137 |
* @param aMsgBody where to load the data
|
|
138 |
*/
|
|
139 |
void LoadMessageBodyL( CRichText& aMsgBody );
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Stores message body data from given rich text object
|
|
143 |
*
|
|
144 |
* @param aMsgBody where from store the data
|
|
145 |
*/
|
|
146 |
void StoreMessageBodyL( CRichText& aMsgBody );
|
|
147 |
|
|
148 |
/**
|
|
149 |
* Parses telephone number and name from the string containing number and possibly contact name
|
|
150 |
*
|
|
151 |
* @param aNumberSring IN: String from which to parse the number (like "Abc Pqr <+0123456789>")
|
|
152 |
* @param aNumberStore OUT: Variable where to store the output data
|
|
153 |
* @return TBool ETrue if operation was successful
|
|
154 |
*/
|
|
155 |
TBool ParseTelephoneNumber(const TDesC& aNumberString, TTelephoneNumber& aNumberStore);
|
|
156 |
|
|
157 |
private: // Internal functions used by ReadMessage()
|
|
158 |
|
|
159 |
/**
|
|
160 |
* Reads and decodes text/x-VMessage header.
|
|
161 |
*
|
|
162 |
* @return TInt KErrNone or negative error code
|
|
163 |
*/
|
|
164 |
TInt ReadMessageHeader();
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Reads and decodes envelope part of text/x-VMessage header.
|
|
168 |
* There can be multiple envelopes, which are handled recursively.
|
|
169 |
*
|
|
170 |
* @return TInt KErrNone or negative error code
|
|
171 |
*/
|
|
172 |
TInt ReadEnvelope();
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Reads and parses time stamp field found from vMessage starting from the current read position.
|
|
176 |
* Note that this field is optional.
|
|
177 |
*
|
|
178 |
* @param aTimetstamp IN: Timestamp field found from vMessage
|
|
179 |
* @param aUniversalTime OUT: Parsed timestand as universal time
|
|
180 |
* @return TInt KErrNone if operation succeeded
|
|
181 |
*/
|
|
182 |
TInt ReadTaggedTimeStamp( TTime& aUniversalTime );
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Reads and decodes text/x-VMessage body.
|
|
186 |
*
|
|
187 |
* @return TInt Length of message body or negative value in error case
|
|
188 |
*/
|
|
189 |
TInt ReadMessageBodyL();
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Raeds VCARD section of text/x-vMessage - contains cotact information
|
|
193 |
*
|
|
194 |
* @param aResult telephone number and contact name found is stored here
|
|
195 |
* @return TInt Result
|
|
196 |
*/
|
|
197 |
TInt ReadVCard(TTelephoneNumber& aResult);
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Searches next given message tag with given value from text/x-VMessage
|
|
201 |
*
|
|
202 |
* @param aMsgTag IN: Message tag to be found
|
|
203 |
* @param aValue IN: Expected value of the message tag to be found
|
|
204 |
* @return TInt Result, Starting point of the message tag. KErrNotFound if not found.
|
|
205 |
*/
|
|
206 |
TInt FindMessageTagWithValue( const TDesC& aMsgTag, const TDesC& aValue );
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Searches next given message tag from text/x-VMessage and gets it's value
|
|
210 |
* Value is expected to start from tag and end to newline.
|
|
211 |
*
|
|
212 |
* @param aMsgTag IN: Message tag to be found
|
|
213 |
* @param aValue OUT: Value of the message tag
|
|
214 |
* @param aMoveReadPosition IN: whether moving start point of seach for the next field forward or not
|
|
215 |
* @return TInt Result, Starting point of the message tag. KErrNotFound if not found.
|
|
216 |
*/
|
|
217 |
TInt GetMessageTagValue( const TDesC& aMsgTag, TDes& aValue, TBool aMoveReadBufPos = ETrue );
|
|
218 |
|
|
219 |
/**
|
|
220 |
* Stores a portion of message data from text/x-vMessage to local descriptor varíable.
|
|
221 |
* Conversion from TDes8 to TDes16 is done and sufficient length of local descriptor
|
|
222 |
* is checked - no more bytes than maximum length of the descriptor will be copied.
|
|
223 |
*
|
|
224 |
* @param aStart IN: Start point of data to be copied in text/x-vMessage
|
|
225 |
* @param aLength IN: Length of data to be copied
|
|
226 |
* @param aLocalStore OUT: Place where the data will be copied
|
|
227 |
*/
|
|
228 |
void StoreMessageDataField(TInt aStart, TInt aLength, TDes& aLocalStore);
|
|
229 |
|
|
230 |
private: // Internal functions used by WriteMessageL()
|
|
231 |
|
|
232 |
/**
|
|
233 |
* Writes message properties to text/x-VMessage header.
|
|
234 |
*/
|
|
235 |
void WriteMessagePropertiesL();
|
|
236 |
|
|
237 |
/**
|
|
238 |
* Writes message VCARD information to text/x-VMessage header.
|
|
239 |
*/
|
|
240 |
void WriteMessageVCARDL(const TDesC& aName, const TDesC& aNumber);
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Writes message envelope information to text/x-VMessage header.
|
|
244 |
*/
|
|
245 |
void WriteMessageEnvelopeL();
|
|
246 |
|
|
247 |
/**
|
|
248 |
* Writes tagged timestamp field to vMessage in format
|
|
249 |
* X-NOK-DT:yyyymmddThhmmssZ (universal time format)
|
|
250 |
*
|
|
251 |
* @param aUniversalTime IN: Time value to be used
|
|
252 |
*/
|
|
253 |
void WriteTaggedTimestampL( TTime aUniversalTime );
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Writes message body to text/x-VMessage.
|
|
257 |
*/
|
|
258 |
void WriteMessageBodyL();
|
|
259 |
|
|
260 |
/**
|
|
261 |
* Writes one line to text/x-vMessage
|
|
262 |
*
|
|
263 |
* @param aMsgTag IN: Message tag to use
|
|
264 |
* @param aMsgTagData IN: Message tag value to use
|
|
265 |
* @param aIndent IN: Whether indentication is used or not
|
|
266 |
*/
|
|
267 |
void WriteMessageLineL( const TDesC& aMsgTag, const TDesC& aMsgTagData, TBool aIndent = EFalse );
|
|
268 |
|
|
269 |
/**
|
|
270 |
* Writes given data to text/x-vMessage.
|
|
271 |
* Size of pre-allocated dynamic buffer is checked and new size allocated if necessary.
|
|
272 |
*
|
|
273 |
* @param aDate IN: Data to be written
|
|
274 |
*/
|
|
275 |
void WriteToMessageL( const TDesC& aData );
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Gets currect indentication level for writing message line.
|
|
279 |
*
|
|
280 |
* @param aMsgTag IN: Message tag used in the line
|
|
281 |
*/
|
|
282 |
TInt GetIndentLevel( const TDesC& aMsgTag );
|
|
283 |
|
|
284 |
/**
|
|
285 |
* Fills fixed size buffer with given data in safe way so that max size will not be exeeded.
|
|
286 |
*
|
|
287 |
* @param aData IN: Input data
|
|
288 |
* @param aBuffer OUT: Buffer to fill
|
|
289 |
*/
|
|
290 |
void AssignDataToBuffer( const TDesC& aData, TDes& aBuffer );
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
public: // Public member variables. Contain text/x-vMessage data.
|
|
297 |
|
|
298 |
|
|
299 |
/**
|
|
300 |
* Actual message body is stored here
|
|
301 |
*/
|
|
302 |
HBufC* iMessageBody;
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Message time stamp in universal time
|
|
306 |
*/
|
|
307 |
TTime iUniversalTime;
|
|
308 |
|
|
309 |
/**
|
|
310 |
* Message time stamp in home time
|
|
311 |
*/
|
|
312 |
TTime iHomeTime;
|
|
313 |
|
|
314 |
/**
|
|
315 |
* Message folder name
|
|
316 |
*/
|
|
317 |
TBuf<KMaxFolderNameLength> iFolder;
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Message status
|
|
321 |
*/
|
|
322 |
TBuf<8> iStatus;
|
|
323 |
|
|
324 |
/**
|
|
325 |
* Sender phone number
|
|
326 |
*/
|
|
327 |
TTelephoneNumber iSender;
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Recipient phone numbers
|
|
331 |
*/
|
|
332 |
RArray<TTelephoneNumber> iRecipients;
|
|
333 |
|
|
334 |
private: // Internal member variables
|
|
335 |
|
|
336 |
/**
|
|
337 |
* Internal variables used for parsing vMessage
|
|
338 |
*/
|
|
339 |
TInt iReadBufPosition;
|
|
340 |
TPtrC iReadBuf;
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Internal variables used for constructing vMessage
|
|
344 |
*/
|
|
345 |
TInt iWriteBufPosition;
|
|
346 |
TInt iWriteBufSize;
|
|
347 |
TInt iWriteIndentLevel;
|
|
348 |
CBufBase* iWriteBuf;
|
|
349 |
|
|
350 |
};
|
|
351 |
|
|
352 |
#endif // VMESSAGEPARSER_H
|