aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-03-11 09:05:09 +0000
committerVincent Richard <[email protected]>2013-03-11 09:05:09 +0000
commit32a80f6c1ed501ceb2e1d7613dcdcce6cdf6fe23 (patch)
tree72f7ac0894025d16b8dca950fdfe2df97972faf6 /src
parentRefactored unit tests. (diff)
downloadvmime-32a80f6c1ed501ceb2e1d7613dcdcce6cdf6fe23.tar.gz
vmime-32a80f6c1ed501ceb2e1d7613dcdcce6cdf6fe23.zip
Fixed mailbox and mailbox group parsing. Added unit tests.
Diffstat (limited to 'src')
-rw-r--r--src/address.cpp28
-rw-r--r--src/addressList.cpp2
-rw-r--r--src/mailboxField.cpp2
-rw-r--r--src/mailboxGroup.cpp7
4 files changed, 30 insertions, 9 deletions
diff --git a/src/address.cpp b/src/address.cpp
index ab207cf6..b57892d5 100644
--- a/src/address.cpp
+++ b/src/address.cpp
@@ -68,7 +68,7 @@ address-list = (address *("," address)) / obs-addr-list
ref <address> address::parseNext
(const parsingContext& ctx, const string& buffer, const string::size_type position,
- const string::size_type end, string::size_type* newPosition)
+ const string::size_type end, string::size_type* newPosition, bool *isLastAddressOfGroup)
{
bool escaped = false;
bool quoted = false;
@@ -76,6 +76,10 @@ ref <address> address::parseNext
bool inRouteAddr = false;
bool isGroup = false;
bool stop = false;
+ int commentLevel = 0;
+
+ if (isLastAddressOfGroup)
+ *isLastAddressOfGroup = false;
string::size_type pos = position;
@@ -106,9 +110,22 @@ ref <address> address::parseNext
case '>':
inRouteAddr = false;
break;
+
+ case '(':
+
+ ++commentLevel;
+ break;
+
+ case ')':
+
+ if (commentLevel > 0)
+ --commentLevel;
+
+ break;
+
case '=':
- if (!quoted && !quotedRFC2047 && pos + 1 < end && buffer[pos + 1] == '?')
+ if (commentLevel == 0 && !quoted && !quotedRFC2047 && pos + 1 < end && buffer[pos + 1] == '?')
{
++pos;
quotedRFC2047 = true;
@@ -118,7 +135,7 @@ ref <address> address::parseNext
case '?':
- if (quotedRFC2047 && pos + 1 < end && buffer[pos + 1] == '=')
+ if (commentLevel == 0 && quotedRFC2047 && pos + 1 < end && buffer[pos + 1] == '=')
{
++pos;
quotedRFC2047 = false;
@@ -128,7 +145,7 @@ ref <address> address::parseNext
default:
{
- if (!quoted && !quotedRFC2047 && !inRouteAddr)
+ if (commentLevel == 0 && !quoted && !quotedRFC2047 && !inRouteAddr)
{
switch (buffer[pos])
{
@@ -140,6 +157,9 @@ ref <address> address::parseNext
++pos;
}
+ if (isLastAddressOfGroup)
+ *isLastAddressOfGroup = true;
+
stop = true;
break;
diff --git a/src/addressList.cpp b/src/addressList.cpp
index 5e033f38..326a54e3 100644
--- a/src/addressList.cpp
+++ b/src/addressList.cpp
@@ -60,7 +60,7 @@ void addressList::parseImpl
while (pos < end)
{
- ref <address> parsedAddress = address::parseNext(ctx, buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(ctx, buffer, pos, end, &pos, NULL);
if (parsedAddress != NULL)
m_list.push_back(parsedAddress);
diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp
index 1f11f49c..4eb9d734 100644
--- a/src/mailboxField.cpp
+++ b/src/mailboxField.cpp
@@ -52,7 +52,7 @@ void mailboxField::parse
// Here, we cannot simply call "m_mailbox.parse()" because it
// may have more than one address specified (even if this field
// should contain only one). We are never too much careful...
- ref <address> parsedAddress = address::parseNext(ctx, buffer, position, end, newPosition);
+ ref <address> parsedAddress = address::parseNext(ctx, buffer, position, end, newPosition, NULL);
if (parsedAddress)
{
diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp
index 65611b33..9da16653 100644
--- a/src/mailboxGroup.cpp
+++ b/src/mailboxGroup.cpp
@@ -78,10 +78,11 @@ void mailboxGroup::parseImpl
string::size_type pos = position + (p - pstart);
+ bool isLastAddressOfGroup = false;
- while (pos < end)
+ while (pos < end && !isLastAddressOfGroup)
{
- ref <address> parsedAddress = address::parseNext(ctx, buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(ctx, buffer, pos, end, &pos, &isLastAddressOfGroup);
if (parsedAddress)
{
@@ -103,7 +104,7 @@ void mailboxGroup::parseImpl
}
}
- text::decodeAndUnfold(ctx, name, &m_name);
+ text::decodeAndUnfold(ctx, utility::stringUtils::trim(name), &m_name);
setParsedBounds(position, end);