File indexing completed on 2024-09-22 04:52:49
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef IMAP_PARSER_MAILADDRESS_H 0024 #define IMAP_PARSER_MAILADDRESS_H 0025 0026 #include <QString> 0027 #include <QVariantList> 0028 0029 class QTextStream; 0030 class ImapMessageTest; 0031 0032 /** @short Namespace for IMAP interaction */ 0033 namespace Imap 0034 { 0035 0036 0037 /** @short Classes for handling e-mail messages */ 0038 namespace Message 0039 { 0040 0041 class Envelope; 0042 0043 /** @short Storage container for one address from an envelope */ 0044 class MailAddress { 0045 public: 0046 0047 /** @short Mode to format the address to string */ 0048 typedef enum { 0049 FORMAT_JUST_NAME, /**< @short Just the human-readable name */ 0050 FORMAT_READABLE, /**< @short Real Name <foo@example.org> */ 0051 FORMAT_CLICKABLE, /**< @short HTML clickable form of FORMAT_READABLE */ 0052 FORMAT_SHORT_CLICKABLE /**< @short HTML clickable form of FORMAT_READABLE with conditionally elided text */ 0053 } FormattingMode; 0054 0055 /** @short Phrase from RFC2822 mailbox */ 0056 QString name; 0057 0058 /** @short Route information */ 0059 QString adl; 0060 0061 /** @short RFC2822 Group Name or Local Part */ 0062 QString mailbox; 0063 0064 /** @short RFC2822 Domain Name */ 0065 QString host; 0066 0067 /** @short Construct from already decoded Unicode data */ 0068 MailAddress(const QString &name, const QString &adl, 0069 const QString &mailbox, const QString &host): 0070 name(name), adl(adl), mailbox(mailbox), host(host) {} 0071 0072 /** @short Construct an invalid, empty MailAddress, something with no content */ 0073 MailAddress() {} 0074 0075 QString prettyName(FormattingMode mode) const; 0076 0077 QByteArray asSMTPMailbox() const; 0078 QByteArray asMailHeader() const; 0079 QString asPrettyString() const; 0080 QUrl asUrl() const; 0081 0082 bool hasUsefulDisplayName() const; 0083 0084 static QString prettyList(const QList<MailAddress> &list, FormattingMode mode); 0085 static QString prettyList(const QVariantList &list, FormattingMode mode); 0086 0087 static bool fromPrettyString(MailAddress &into, const QString &address); 0088 static bool parseOneAddress(MailAddress &into, const QString &address, int &startOffset); 0089 static bool fromUrl(MailAddress &into, const QUrl &url, const QString &expectedScheme); 0090 0091 static MailAddress fromNameAndMail(const QString &name, const QString &email); 0092 0093 private: 0094 /** @short Construct from a list of raw items as found in an IMAP ENVELOPE */ 0095 MailAddress(const QVariantList &input, const QByteArray &line, const int start); 0096 friend class Envelope; 0097 friend class ::ImapMessageTest; 0098 }; 0099 0100 QTextStream &operator<<(QTextStream &stream, const MailAddress &address); 0101 0102 bool operator==(const MailAddress &a, const MailAddress &b); 0103 inline bool operator!=(const MailAddress &a, const MailAddress &b) { return !(a == b); } 0104 0105 0106 /** Are the actual e-mail addresses (without any fancy details) equal? */ 0107 bool MailAddressesEqualByMail(const MailAddress &a, const MailAddress &b); 0108 0109 /** Are the domains in the e-mail addresses equal? */ 0110 bool MailAddressesEqualByDomain(const MailAddress &a, const MailAddress &b); 0111 0112 /** @short Is the second domain a prefix of the first one? */ 0113 bool MailAddressesEqualByDomainSuffix(const MailAddress &a, const MailAddress &b); 0114 0115 } 0116 0117 } 0118 0119 QDataStream &operator>>(QDataStream &stream, Imap::Message::MailAddress &a); 0120 QDataStream &operator<<(QDataStream &stream, const Imap::Message::MailAddress &a); 0121 0122 0123 #endif // IMAP_PARSER_MAILADDRESS_H