1
/***************************************************************************
2
copyright : (C) 2002-2005 by Stefano Barbato
3
email : stefano@codesink.org
5
$Id: field.cxx,v 1.4 2005/02/24 13:08:08 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/field.h>
17
#include <mimetic/strutils.h>
18
#include <mimetic/utils.h>
19
#include <mimetic/contenttype.h>
20
#include <mimetic/rfc822/mailboxlist.h>
28
const Field Field::null;
31
Constructs a null Field
40
Parses \p line and sets \e name, \e value and \e valueText of *this
41
\param line input field string as defined in RFC822 (fieldname: text)
43
Field::Field(const string& line)
46
string::size_type colon = line.find(':');
47
if(colon != string::npos)
49
m_name.assign(line.begin(), line.begin() + colon);
51
for(i = 1 + colon; i < line.length() - 1 && line[i] == ' '; ++i)
52
; // skip spaces before field-body
53
string val(line.begin() +i, line.end());
60
Initialize *this with \p n and \p v
62
\param v content of the %field
64
Field::Field(const string& n , const string& v)
68
m_pValue = new StringFieldValue(v);
74
Field::Field(const Field& r)
75
:m_name(r.m_name), m_pValue(0)
78
m_pValue = r.m_pValue->clone();
81
Field& Field::operator=(const Field& r)
90
m_pValue = r.m_pValue->clone();
107
Sets the field name to \p n
108
\param name new %field %name
110
void Field::name(const string& name)
121
Sets the field value to \p v
122
\param val new %value %name
124
void Field::value(const string& val)
127
m_pValue = new StringFieldValue(val);
133
Returns the field name
135
const istring& Field::name() const
144
Returns the field value.
146
string Field::value() const
150
return m_pValue->str();
153
std::ostream& operator<<(std::ostream& os, const Field& f)
155
return f.write(os, 0);
158
ostream& Field::write(ostream& os, unsigned int fold) const
160
// default folding idiot-algorithm
161
// override to customize
165
string ostr = name() + ": " + value();
167
while(ostr.length() > fold)
169
for(i = 0, sp = 0; i < ostr.length(); ++i)
172
sp = i; // last blank found
176
os.write(ostr.c_str(), sp);
183
break; // can't fold anymore
189
return os << name() << ": " << value();