74
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: A utility class for parsing URI strings
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "nmuriparser.h"
|
|
18 |
#include "emailtrace.h"
|
|
19 |
|
|
20 |
#include <QUrl>
|
|
21 |
|
|
22 |
|
|
23 |
/*!
|
|
24 |
Keys for parsing data.
|
|
25 |
*/
|
|
26 |
static const QString NmUriParserEmailSendSubjectKey = "subject";
|
|
27 |
static const QString NmUriParserEmailEmailSendToKey = "to";
|
|
28 |
static const QString NmUriParserEmailSendCcKey = "cc";
|
|
29 |
static const QString NmUriParserEmailSendBccKey = "bcc";
|
|
30 |
static const QString NmUriParserEmailSendBodyTextKey = "body";
|
|
31 |
|
|
32 |
/*!
|
|
33 |
Class constructor.
|
|
34 |
*/
|
|
35 |
NmUriParser::NmUriParser()
|
|
36 |
{
|
|
37 |
NM_FUNCTION;
|
|
38 |
}
|
|
39 |
|
|
40 |
/*!
|
|
41 |
Class destructor.
|
|
42 |
*/
|
|
43 |
NmUriParser::~NmUriParser()
|
|
44 |
{
|
|
45 |
NM_FUNCTION;
|
|
46 |
}
|
|
47 |
|
|
48 |
/*!
|
|
49 |
Extracts the data from the given QString into the class members.
|
|
50 |
\param data QString containing the data.
|
|
51 |
\return True if success, false otherwise.
|
|
52 |
*/
|
|
53 |
bool NmUriParser::extractData(const QString &data)
|
|
54 |
{
|
|
55 |
NM_FUNCTION;
|
|
56 |
|
|
57 |
bool success(false);
|
|
58 |
|
|
59 |
QUrl uri(data);
|
|
60 |
|
|
61 |
if (uri.isValid()) {
|
|
62 |
|
|
63 |
mSubject = uri.queryItemValue(NmUriParserEmailSendSubjectKey);
|
|
64 |
QString to = uri.path();
|
|
65 |
QString cc = uri.queryItemValue(NmUriParserEmailSendCcKey);
|
|
66 |
QString bcc = uri.queryItemValue(NmUriParserEmailSendBccKey);
|
|
67 |
QString bodyText = uri.queryItemValue(NmUriParserEmailSendBodyTextKey);
|
|
68 |
if (bodyText.length()) {
|
|
69 |
mBodyText = bodyText;
|
|
70 |
}
|
|
71 |
|
|
72 |
addAddressesToList(to, mToAddresses);
|
|
73 |
addAddressesToList(cc, mCcAddresses);
|
|
74 |
addAddressesToList(bcc, mBccAddresses);
|
|
75 |
|
|
76 |
success = true;
|
|
77 |
}
|
|
78 |
|
|
79 |
return success;
|
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
Appends the given addresses into the given list.
|
|
84 |
\param address The addresses to append.
|
|
85 |
\param list The list where the addresses are appended to.
|
|
86 |
*/
|
|
87 |
void NmUriParser::addAddressesToList(QString &addresses, QStringList &list)
|
|
88 |
{
|
|
89 |
NM_FUNCTION;
|
|
90 |
|
|
91 |
if (!addresses.isEmpty()) {
|
|
92 |
|
|
93 |
QStringList foundAddresses;
|
|
94 |
|
|
95 |
// Process multiple addresses.
|
|
96 |
if (addresses.contains(",")) {
|
|
97 |
QString str;
|
|
98 |
while (addresses.contains(",")) {
|
|
99 |
str = addresses.section(",", 0, 0); // Get the occurance.
|
|
100 |
addresses.remove(0, (addresses.indexOf(",")+1)); // Remove the occurance.
|
|
101 |
if (!str.isEmpty()) { // In case str would be empty on some error data.
|
|
102 |
foundAddresses.append(str);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
if (!addresses.isEmpty()) { // In case addresses would be empty on some error data.
|
|
107 |
// Last one or single address.
|
|
108 |
foundAddresses.append(addresses);
|
|
109 |
}
|
|
110 |
// Append the found addresses into the given list.
|
|
111 |
list.append(foundAddresses);
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
/*!
|
|
116 |
Resets the data.
|
|
117 |
*/
|
|
118 |
void NmUriParser::resetData()
|
|
119 |
{
|
|
120 |
NM_FUNCTION;
|
|
121 |
|
|
122 |
mSubject.clear();
|
|
123 |
mToAddresses.clear();
|
|
124 |
mCcAddresses.clear();
|
|
125 |
mBccAddresses.clear();
|
|
126 |
mBodyText.clear();
|
|
127 |
}
|
|
128 |
|
|
129 |
/*!
|
|
130 |
Getter for subject
|
|
131 |
\return QString subject of parsed uri
|
|
132 |
*/
|
|
133 |
QString NmUriParser::subject() const
|
|
134 |
{
|
|
135 |
return mSubject;
|
|
136 |
}
|
|
137 |
/*!
|
|
138 |
Getter for to-addresses
|
|
139 |
\return QStringList list of parsed to-addresses
|
|
140 |
*/
|
|
141 |
QStringList NmUriParser::toAddresses() const
|
|
142 |
{
|
|
143 |
return mToAddresses;
|
|
144 |
}
|
|
145 |
/*!
|
|
146 |
Getter for ccAddresses
|
|
147 |
\return QStringList list of parsed cc-addresses
|
|
148 |
*/
|
|
149 |
QStringList NmUriParser::ccAddresses() const
|
|
150 |
{
|
|
151 |
return mCcAddresses;
|
|
152 |
}
|
|
153 |
/*!
|
|
154 |
Getter for bcc-Addresses
|
|
155 |
\return QStringList list of parsed bcc-addresses
|
|
156 |
*/
|
|
157 |
QStringList NmUriParser::bccAddresses() const
|
|
158 |
{
|
|
159 |
return mBccAddresses;
|
|
160 |
}
|
|
161 |
/*!
|
|
162 |
Getter for bcc-Addresses
|
|
163 |
\return QString parsed body text
|
|
164 |
*/
|
|
165 |
QString NmUriParser::bodyText() const
|
|
166 |
{
|
|
167 |
return mBodyText;
|
|
168 |
}
|