24#include "mailaddress.h"
25#include "mimehdrline.h"
26#include <kimap/rfccodecs.h>
27#include <kmime/kmime_util.h>
32mailAddress::mailAddress ()
36mailAddress::mailAddress (
const mailAddress & lr):
39rawFullName (lr.rawFullName),
40rawComment (lr.rawComment)
45mailAddress & mailAddress::operator = (
const mailAddress & lr)
54 rawFullName = lr.rawFullName;
55 rawComment = lr.rawComment;
62mailAddress::~mailAddress ()
66mailAddress::mailAddress (
char *aCStr)
68 parseAddress( aCStr );
71int mailAddress::parseAddress (
const char *aCStr)
91 rawFullName += QByteArray( aCStr, advance );
95 rawComment += QByteArray( aCStr, advance );
99 user = QByteArray( aCStr, advance );
101 user = user.mid ( 1, len - 2 );
103 pt = user.indexOf(
'@' );
104 host = user.right( len - pt - 1 );
110 if ( user.isEmpty() ) {
111 if ( *aCStr !=
',' ) {
112 rawFullName += aCStr;
132 if ( *aCStr ==
',' ) {
138 if ( rawFullName.isEmpty() ) {
139 if ( user.isEmpty() ) {
142 if ( host.isEmpty() ) {
147 }
else if ( user.isEmpty() ) {
148 pt = rawFullName.indexOf(
'@' );
151 host = user.right( user.length() - pt - 1 );
153 rawFullName.truncate( 0 );
159 if ( !rawFullName.isEmpty() ) {
167 if ( !rawComment.isEmpty() ) {
168 if ( rawComment[0] ==
'(' ) {
169 rawComment = rawComment.mid( 1, rawComment.length() - 2 );
171 rawComment = rawComment.trimmed();
180const QByteArray mailAddress::getStr ()
const
183 retVal.reserve( 128 );
185 if ( !rawFullName.isEmpty() ) {
186 QByteArray tmpName( rawFullName );
187 KMime::addQuotes( tmpName,
false );
188 retVal = tmpName +
' ';
190 if ( !user.isEmpty() ) {
193 if ( !host.isEmpty() ) {
199 if ( !rawComment.isEmpty() ) {
200 retVal +=
" (" + rawComment +
')';
206bool mailAddress::isEmpty ()
const
208 return user.isEmpty();
211void mailAddress::setFullName (
const QString & _str)
213 rawFullName = KIMAP::encodeRFC2047String( _str ).toLatin1();
216const QString mailAddress::getFullName ()
const
218 return KIMAP::decodeRFC2047String( rawFullName );
221void mailAddress::setCommentRaw (
const QByteArray & _str)
226void mailAddress::setComment (
const QString & _str)
228 rawComment = KIMAP::encodeRFC2047String( _str ).toLatin1();
231const QString mailAddress::getComment ()
const
233 return KIMAP::decodeRFC2047String( rawComment );
236const QByteArray & mailAddress::getCommentRaw ()
const
241QString mailAddress::emailAddrAsAnchor (
const mailAddress & adr,
bool shortAdr)
244 if ( !adr.getFullName().isEmpty() ) {
246 retVal += adr.getFullName() +
' ';
248 if ( !adr.getUser().isEmpty() && !shortAdr ) {
249 retVal +=
"<" + adr.getUser();
250 if ( !adr.getHost().isEmpty() ) {
251 retVal +=
'@' + adr.getHost();
255 if ( !adr.getComment().isEmpty() ) {
257 retVal =
'(' + adr.getComment() +
')';
260 if ( !adr.getUser().isEmpty() ) {
262 mail = adr.getUser();
263 if ( !mail.isEmpty() && !adr.getHost().isEmpty() ) {
264 mail +=
'@' + adr.getHost();
266 if ( !mail.isEmpty() ) {
267 retVal =
"<A HREF=\"mailto:" + mail +
"\">" + retVal +
"</A>";
273QString mailAddress::emailAddrAsAnchor (
const QList < mailAddress *> &list,
bool value)
276 QListIterator < mailAddress *> it( list );
278 while ( it.hasNext() ) {
279 retVal += emailAddrAsAnchor ( ( *it.next() ), value ) +
"<BR></BR>\n";
284void mailAddress::clear()
288 rawFullName.truncate( 0 );
289 rawComment.truncate( 0 );
static int parseWord(const char *)
slurp one word
static int skipWS(const char *)
skip all white space characters
static int parseQuoted(char, char, const char *)
slurp one word