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)
53 rawFullName = lr.rawFullName;
54 rawComment = lr.rawComment;
64 mailAddress::~mailAddress ()
68 mailAddress::mailAddress (
char *aCStr)
73 int mailAddress::parseAddress (
const char *aCStr)
97 rawFullName += QByteArray (aCStr, advance);
101 rawComment += QByteArray (aCStr, advance);
105 user = QByteArray (aCStr, advance);
107 user = user.mid (1, len - 2);
109 pt = user.indexOf(
'@');
110 host = user.right (len - pt - 1);
120 rawFullName += aCStr;
150 if (rawFullName.isEmpty ())
163 else if (user.isEmpty ())
165 pt = rawFullName.indexOf (
'@');
169 host = user.right (user.length () - pt - 1);
171 rawFullName.truncate(0);
177 if (!rawFullName.isEmpty ())
185 if (!rawComment.isEmpty ())
187 if (rawComment[0] ==
'(')
188 rawComment = rawComment.mid (1, rawComment.length () - 2);
189 rawComment = rawComment.trimmed ();
200 const QByteArray mailAddress::getStr ()
const
205 if (!rawFullName.isEmpty ())
207 QByteArray tmpName( rawFullName );
208 KMime::addQuotes( tmpName,
false );
209 retVal = tmpName +
' ';
211 if (!user.isEmpty ())
215 if (!host.isEmpty ()) {
221 if (!rawComment.isEmpty ())
223 retVal +=
" (" + rawComment +
')';
229 bool mailAddress::isEmpty ()
const
231 return user.isEmpty ();
234 void mailAddress::setFullName (
const QString & _str)
236 rawFullName = KIMAP::encodeRFC2047String (_str).toLatin1 ();
239 const QString mailAddress::getFullName ()
const
241 return KIMAP::decodeRFC2047String (rawFullName);
244 void mailAddress::setCommentRaw (
const QByteArray & _str)
249 void mailAddress::setComment (
const QString & _str)
251 rawComment = KIMAP::encodeRFC2047String (_str).toLatin1 ();
254 const QString mailAddress::getComment ()
const
256 return KIMAP::decodeRFC2047String (rawComment);
259 const QByteArray & mailAddress::getCommentRaw ()
const
264 QString mailAddress::emailAddrAsAnchor (
const mailAddress & adr,
bool shortAdr)
267 if (!adr.getFullName ().isEmpty ())
270 retVal += adr.getFullName () +
' ';
272 if (!adr.getUser ().isEmpty () && !shortAdr)
274 retVal +=
"<" + adr.getUser ();
275 if (!adr.getHost ().isEmpty ())
276 retVal +=
'@' + adr.getHost ();
279 if (!adr.getComment ().isEmpty ())
282 retVal =
'(' + adr.getComment () +
')';
285 if (!adr.getUser ().isEmpty ())
288 mail = adr.getUser ();
289 if (!mail.isEmpty () && !adr.getHost ().isEmpty ())
290 mail +=
'@' + adr.getHost ();
291 if (!mail.isEmpty ())
292 retVal =
"<A HREF=\"mailto:" + mail +
"\">" + retVal +
"</A>";
297 QString mailAddress::emailAddrAsAnchor (
const QList < mailAddress *> &list,
bool value)
300 QListIterator < mailAddress *> it (list);
304 retVal += emailAddrAsAnchor ((*it.next()), value) +
"<BR></BR>\n";
311 void mailAddress::clear() {
314 rawFullName.truncate(0);
315 rawComment.truncate(0);