24 #include "mailaddress.h"
25 #include "mimehdrline.h"
26 #include <kimap/rfccodecs.h>
27 #include <kmime/kmime_util.h>
30 using namespace KIMAP;
32 mailAddress::mailAddress ()
36 mailAddress::mailAddress (
const mailAddress & lr):
39 rawFullName (lr.rawFullName),
40 rawComment (lr.rawComment)
45 mailAddress & mailAddress::operator = (
const mailAddress & lr)
54 rawFullName = lr.rawFullName;
55 rawComment = lr.rawComment;
62 mailAddress::~mailAddress ()
66 mailAddress::mailAddress (
char *aCStr)
68 parseAddress( aCStr );
71 int mailAddress::parseAddress (
const char *aCStr)
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();
185 if ( !rawFullName.isEmpty() ) {
187 KMime::addQuotes( tmpName,
false );
188 retVal = tmpName +
' ';
190 if ( !user.isEmpty() ) {
193 if ( !host.isEmpty() ) {
199 if ( !rawComment.isEmpty() ) {
200 retVal +=
" (" + rawComment +
')';
206 bool mailAddress::isEmpty ()
const
211 void mailAddress::setFullName (
const QString & _str)
213 rawFullName = KIMAP::encodeRFC2047String( _str ).toLatin1();
216 const QString mailAddress::getFullName ()
const
218 return KIMAP::decodeRFC2047String( rawFullName );
221 void mailAddress::setCommentRaw (
const QByteArray & _str)
226 void mailAddress::setComment (
const QString & _str)
228 rawComment = KIMAP::encodeRFC2047String( _str ).toLatin1();
231 const QString mailAddress::getComment ()
const
233 return KIMAP::decodeRFC2047String( rawComment );
236 const QByteArray & mailAddress::getCommentRaw ()
const
241 QString 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();
267 retVal =
"<A HREF=\"mailto:" + mail +
"\">" + retVal +
"</A>";
278 while ( it.hasNext() ) {
279 retVal += emailAddrAsAnchor ( ( *it.next() ), value ) +
"<BR></BR>\n";
284 void mailAddress::clear()
288 rawFullName.truncate( 0 );
289 rawComment.truncate( 0 );
void truncate(int position)
static int parseWord(const char *)
slurp one word
static int parseQuoted(char, char, const char *)
slurp one word
static int skipWS(const char *)
skip all white space characters