Changeset View
Changeset View
Standalone View
Standalone View
messagecomposer/src/helper/messagefactoryng.cpp
Show All 35 Lines | |||||
36 | #include <kmime/kmime_dateformatter.h> | 36 | #include <kmime/kmime_dateformatter.h> | ||
37 | #include <KEmailAddress> | 37 | #include <KEmailAddress> | ||
38 | #include <MessageCore/MailingList> | 38 | #include <MessageCore/MailingList> | ||
39 | #include <MessageCore/StringUtil> | 39 | #include <MessageCore/StringUtil> | ||
40 | #include "helper/messagehelper.h" | 40 | #include "helper/messagehelper.h" | ||
41 | #include <KLocalizedString> | 41 | #include <KLocalizedString> | ||
42 | #include "messagecomposer_debug.h" | 42 | #include "messagecomposer_debug.h" | ||
43 | #include <KCharsets> | 43 | #include <KCharsets> | ||
44 | #include <QRegularExpression> | ||||
44 | #include <QTextCodec> | 45 | #include <QTextCodec> | ||
45 | 46 | | |||
46 | using namespace MessageComposer; | 47 | using namespace MessageComposer; | ||
47 | 48 | | |||
48 | namespace KMime { | 49 | namespace KMime { | ||
49 | namespace Types { | 50 | namespace Types { | ||
50 | static bool operator==(const KMime::Types::Mailbox &left, const KMime::Types::Mailbox &right) | 51 | static bool operator==(const KMime::Types::Mailbox &left, const KMime::Types::Mailbox &right) | ||
51 | { | 52 | { | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 141 | { | |||
146 | 147 | | |||
147 | const uint originalIdentity = identityUoid(m_origMsg); | 148 | const uint originalIdentity = identityUoid(m_origMsg); | ||
148 | MessageHelper::initFromMessage(msg, m_origMsg, m_identityManager, originalIdentity); | 149 | MessageHelper::initFromMessage(msg, m_origMsg, m_identityManager, originalIdentity); | ||
149 | replyToList = m_origMsg->replyTo()->mailboxes(); | 150 | replyToList = m_origMsg->replyTo()->mailboxes(); | ||
150 | 151 | | |||
151 | msg->contentType()->setCharset("utf-8"); | 152 | msg->contentType()->setCharset("utf-8"); | ||
152 | 153 | | |||
153 | if (auto hdr = m_origMsg->headerByType("List-Post")) { | 154 | if (auto hdr = m_origMsg->headerByType("List-Post")) { | ||
154 | const QString hdrListPost = hdr->asUnicodeString(); | 155 | static const QRegularExpression rx { | ||
155 | if (hdrListPost.contains(QLatin1String("mailto:"), Qt::CaseInsensitive)) { | 156 | QStringLiteral("<\\s*mailto\\s*:([^@>]+@[^>]+)>"), | ||
156 | QRegExp rx(QStringLiteral("<mailto:([^@>]+)@([^>]+)>"), Qt::CaseInsensitive); | 157 | QRegularExpression::CaseInsensitiveOption | ||
157 | if (rx.indexIn(hdrListPost, 0) != -1) { // matched | 158 | }; | ||
159 | const auto match = rx.match(hdr->asUnicodeString()); | ||||
160 | if (match.hasMatch()) { | ||||
158 | KMime::Types::Mailbox mailbox; | 161 | KMime::Types::Mailbox mailbox; | ||
159 | mailbox.fromUnicodeString(rx.cap(1) + QLatin1Char('@') + rx.cap(2)); | 162 | mailbox.fromUnicodeString(match.captured(1)); | ||
160 | m_mailingListAddresses << mailbox; | 163 | m_mailingListAddresses << mailbox; | ||
161 | } | 164 | } | ||
162 | } | 165 | } | ||
163 | } | | |||
164 | 166 | | |||
165 | switch (m_replyStrategy) { | 167 | switch (m_replyStrategy) { | ||
166 | case MessageComposer::ReplySmart: | 168 | case MessageComposer::ReplySmart: | ||
167 | { | 169 | { | ||
168 | if (auto hdr = m_origMsg->headerByType("Mail-Followup-To")) { | 170 | if (auto hdr = m_origMsg->headerByType("Mail-Followup-To")) { | ||
169 | toList << KMime::Types::Mailbox::listFrom7BitString(hdr->as7BitString(false)); | 171 | toList << KMime::Types::Mailbox::listFrom7BitString(hdr->as7BitString(false)); | ||
170 | } else if (!m_mailingListAddresses.isEmpty()) { | 172 | } else if (!m_mailingListAddresses.isEmpty()) { | ||
171 | if (replyToList.isEmpty()) { | 173 | if (replyToList.isEmpty()) { | ||
▲ Show 20 Lines • Show All 735 Lines • ▼ Show 20 Line(s) | 908 | if (id == 0 && m_folderId > 0) { | |||
907 | id = m_folderId; | 909 | id = m_folderId; | ||
908 | } | 910 | } | ||
909 | return id; | 911 | return id; | ||
910 | } | 912 | } | ||
911 | 913 | | |||
912 | QString MessageFactoryNG::replaceHeadersInString(const KMime::Message::Ptr &msg, const QString &s) | 914 | QString MessageFactoryNG::replaceHeadersInString(const KMime::Message::Ptr &msg, const QString &s) | ||
913 | { | 915 | { | ||
914 | QString result = s; | 916 | QString result = s; | ||
915 | QRegExp rx(QStringLiteral("\\$\\{([a-z0-9-]+)\\}"), Qt::CaseInsensitive); | 917 | static QRegularExpression rx { | ||
916 | Q_ASSERT(rx.isValid()); | 918 | QStringLiteral("\\$\\{([a-z0-9-]+)\\}"), | ||
919 | QRegularExpression::CaseInsensitiveOption | ||||
920 | }; | ||||
917 | 921 | | |||
918 | const QString sDate = KMime::DateFormatter::formatDate( | 922 | const QString sDate = KMime::DateFormatter::formatDate( | ||
919 | KMime::DateFormatter::Localized, msg->date()->dateTime().toSecsSinceEpoch()); | 923 | KMime::DateFormatter::Localized, msg->date()->dateTime().toSecsSinceEpoch()); | ||
920 | qCDebug(MESSAGECOMPOSER_LOG) << "creating mdn date:" << msg->date()->dateTime().toSecsSinceEpoch() << sDate; | 924 | qCDebug(MESSAGECOMPOSER_LOG) << "creating mdn date:" << msg->date()->dateTime().toSecsSinceEpoch() << sDate; | ||
921 | 925 | | |||
922 | result.replace(QStringLiteral("${date}"), sDate); | 926 | result.replace(QStringLiteral("${date}"), sDate); | ||
923 | 927 | | |||
924 | int idx = 0; | 928 | int idx = 0; | ||
925 | while ((idx = rx.indexIn(result, idx)) != -1) { | 929 | for (auto match = rx.match(result); match.hasMatch(); match = rx.match(result, idx)) { | ||
926 | const QByteArray ba = rx.cap(1).toLatin1(); | 930 | idx = match.capturedStart(1); | ||
927 | QString replacement; | 931 | const QByteArray ba = match.captured(1).toLatin1(); | ||
928 | if (auto hrd = msg->headerByType(ba.constData())) { | 932 | if (auto hdr = msg->headerByType(ba.constData())) { | ||
929 | replacement = hrd->asUnicodeString(); | 933 | const auto replacement = hdr->asUnicodeString(); | ||
930 | } | 934 | result.replace(idx, match.capturedLength(1), replacement); | ||
931 | result.replace(idx, rx.matchedLength(), replacement); | | |||
932 | idx += replacement.length(); | 935 | idx += replacement.length(); | ||
933 | } | 936 | } | ||
937 | else { | ||||
938 | result.remove(idx, match.capturedLength(1)); | ||||
939 | } | ||||
940 | } | ||||
934 | return result; | 941 | return result; | ||
935 | } | 942 | } | ||
936 | 943 | | |||
937 | void MessageFactoryNG::applyCharset(const KMime::Message::Ptr msg) | 944 | void MessageFactoryNG::applyCharset(const KMime::Message::Ptr msg) | ||
938 | { | 945 | { | ||
939 | if (MessageComposer::MessageComposerSettings::forceReplyCharset()) { | 946 | if (MessageComposer::MessageComposerSettings::forceReplyCharset()) { | ||
940 | // first convert the body from its current encoding to unicode representation | 947 | // first convert the body from its current encoding to unicode representation | ||
941 | QTextCodec *bodyCodec = KCharsets::charsets()->codecForName(QString::fromLatin1(msg->contentType()->charset())); | 948 | QTextCodec *bodyCodec = KCharsets::charsets()->codecForName(QString::fromLatin1(msg->contentType()->charset())); | ||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |