1
/***************************************************************************
2
copyright : (C) 2002-2005 by Stefano Barbato
3
email : stefano@codesink.org
5
$Id: group.cxx,v 1.2 2005/02/23 10:26:15 tat Exp $
6
***************************************************************************/
8
/***************************************************************************
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
***************************************************************************/
16
#include <mimetic/rfc822/group.h>
17
#include <mimetic/strutils.h>
25
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
28
// group = phrase ":" [#mailbox] ";"
33
Group::Group(const char* cstr)
38
Group::Group(const string& text)
43
static string::size_type find_not_in_quote(const string& s, const string::value_type& c)
46
bool in_dquote = false;
47
for(int i =0; i < len; ++i)
50
in_dquote = !in_dquote;
51
else if( s[i] == c && !in_dquote) {
58
std::string Group::str() const
61
const_iterator bit = begin(), first = bit, eit = end();
62
for(; bit != eit; ++bit)
71
void Group::set(const string& text)
74
size_type colon = find_not_in_quote(m_text, ':');
75
if(colon == string::npos)
76
return; // empty or invalid
77
bool in_dquote = false;
78
int in_par = 0, in_angle = 0;
80
string::iterator p = m_text.begin(), start;
81
m_name.assign(m_text, 0, colon);
82
m_name = remove_external_blanks(m_name);
83
for(p += ++colon, start = p; p < m_text.end(); ++p)
85
if(*p == ';' || *p == ',')
87
if(in_dquote || in_par || in_angle)
90
mbx = remove_external_blanks(mbx);
91
push_back(Mailbox(mbx));
95
} else if(*p == '"') {
96
in_dquote = !in_dquote;
97
} else if(*p == '<') {
99
} else if(*p == '>') {
101
} else if(*p == '(') {
103
} else if(*p == ')') {
107
// trailing ';' missing
108
push_back(Mailbox(string(start, p-1)));
111
string Group::name(int bCanonical) const
112
{ return (bCanonical ? canonical(m_name) : m_name); }
114
void Group::name(const string& name)
117
FieldValue* Group::clone() const
119
return new Group(*this);