diff --git a/CMakeLists.txt b/CMakeLists.txt index 55f339b..a3b18a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,79 +1,80 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.12.40") project(KMime VERSION ${PIM_VERSION}) # ECM setup set(KF5_MIN_VERSION "5.62.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${KMime_SOURCE_DIR}/cmake ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMGeneratePriFile) include(ECMGenerateHeaders) include(ECMSetupVersion) include(FeatureSummary) set(KMIME_LIB_VERSION ${PIM_VERSION}) set(QT_REQUIRED_VERSION "5.11.0") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core) ecm_setup_version(PROJECT VARIABLE_PREFIX KMIME VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kmime_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5MimeConfigVersion.cmake" SOVERSION 5 ) ########### Find packages ########### find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_MIN_VERSION} CONFIG REQUIRED) add_definitions(-DTRANSLATION_DOMAIN=\"libkmime5\") - -#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) +if (EXISTS "${CMAKE_SOURCE_DIR}/.git") + add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) +endif() ########### Targets ########### add_subdirectory(src) add_subdirectory(includes) if(BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Mime") configure_package_config_file( "${KMime_SOURCE_DIR}/KF5MimeConfig.cmake.in" "${KMime_BINARY_DIR}/KF5MimeConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${KMime_BINARY_DIR}/KF5MimeConfig.cmake" "${KMime_BINARY_DIR}/KF5MimeConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5MimeTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5MimeTargets.cmake NAMESPACE KF5:: ) install(FILES ${KMime_BINARY_DIR}/kmime_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/kmime_dateformatter.cpp b/src/kmime_dateformatter.cpp index 78ff4e6..36347f6 100644 --- a/src/kmime_dateformatter.cpp +++ b/src/kmime_dateformatter.cpp @@ -1,345 +1,345 @@ /* kmime_dateformatter.cpp KMime, the KDE Internet mail/usenet news message library. Copyright (c) 2001 the KMime authors. See file AUTHORS for details This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling @ref MIME data and defines the DateFormatter class. @brief Defines the DateFormatter class. @authors the KMime authors (see AUTHORS file) */ #include "kmime_dateformatter.h" #include #include #include using namespace KMime; namespace KMime { class DateFormatterPrivate { public: DateFormatterPrivate() : mTodayOneSecondBeforeMidnight(0) {} /** Returns a QString containing the specified time_t @p t formatted using the #Fancy #FormatType. @param t is the time_t to use for formatting. */ QString fancy(time_t t); /** Returns a QString containing the specified time_t @p t formatted using the #Localized #FormatType. @param t is the time_t to use for formatting. @param shortFormat if true, create the short version of the date string. @param lang is a QString containing the language to use. */ static QString localized(time_t t, bool shortFormat = true, const QString &lang = QString()); /** Returns a QString containing the specified time_t @p t formatted with the ctime() function. @param t is the time_t to use for formatting. */ static QString cTime(time_t t); /** Returns a QString containing the specified time_t @p t in the "%Y-%m-%d %H:%M:%S" #Iso #FormatType. @param t is the time_t to use for formatting. */ static QString isoDate(time_t t); /** Returns a QString containing the specified time_t @p t in the #Rfc #FormatType. @param t is the time_t to use for formatting. */ static QString rfc2822(time_t t); /** Returns a QString containing the specified time_t @p t formatted with a previously specified custom format. @param t time used for formatting */ QString custom(time_t t) const; /** Returns a QString that identifies the timezone (eg."-0500") of the specified time_t @p t. @param t time to compute timezone from. */ static QByteArray zone(time_t t); DateFormatter::FormatType mFormat; time_t mTodayOneSecondBeforeMidnight; QString mCustomFormat; }; } DateFormatter::DateFormatter(FormatType ftype) : d(new DateFormatterPrivate) { d->mFormat = ftype; } DateFormatter::~DateFormatter() { delete d; } DateFormatter::FormatType DateFormatter::format() const { return d->mFormat; } void DateFormatter::setFormat(FormatType ftype) { d->mFormat = ftype; } QString DateFormatter::dateString(time_t t, const QString &lang, bool shortFormat) const { switch (d->mFormat) { case Fancy: return d->fancy(t); case Localized: return d->localized(t, shortFormat, lang); case CTime: return d->cTime(t); case Iso: return d->isoDate(t); case Rfc: return d->rfc2822(t); case Custom: return d->custom(t); } return QString(); } QString DateFormatter::dateString(const QDateTime &dt, const QString &lang, bool shortFormat) const { - return dateString(dt.toLocalTime().toTime_t(), lang, shortFormat); + return dateString(dt.toLocalTime().toSecsSinceEpoch(), lang, shortFormat); } QString DateFormatterPrivate::rfc2822(time_t t) { QDateTime tmp; QString ret; - tmp.setTime_t(t); + tmp.setSecsSinceEpoch(t); ret = tmp.toString(QStringLiteral("ddd, dd MMM yyyy hh:mm:ss ")); ret += QLatin1String(zone(t)); return ret; } QString DateFormatterPrivate::custom(time_t t) const { if (mCustomFormat.isEmpty()) { return QString(); } int z = mCustomFormat.indexOf(QLatin1Char('Z')); QDateTime dt; QString ret = mCustomFormat; - dt.setTime_t(t); + dt.setSecsSinceEpoch(t); if (z != -1) { ret.replace(z, 1, QLatin1String(zone(t))); } ret = dt.toString(ret); return ret; } void DateFormatter::setCustomFormat(const QString &format) { d->mCustomFormat = format; d->mFormat = Custom; } QString DateFormatter::customFormat() const { return d->mCustomFormat; } QByteArray DateFormatterPrivate::zone(time_t t) { #if defined(HAVE_TIMEZONE) || defined(HAVE_TM_GMTOFF) struct tm *local = localtime(&t); #endif #if defined(HAVE_TIMEZONE) //hmm, could make hours & mins static int secs = qAbs(timezone); int neg = (timezone > 0) ? 1 : 0; int hours = secs / 3600; int mins = (secs - hours * 3600) / 60; // adjust to daylight if (local->tm_isdst > 0) { if (neg) { --hours; } else { ++hours; } } #elif defined(HAVE_TM_GMTOFF) int secs = qAbs(local->tm_gmtoff); int neg = (local->tm_gmtoff < 0) ? 1 : 0; int hours = secs / 3600; int mins = (secs - hours * 3600) / 60; #else QDateTime d1 = QDateTime::fromString(QString::fromLatin1(asctime(gmtime(&t)))); QDateTime d2 = QDateTime::fromString(QString::fromLatin1(asctime(localtime(&t)))); int secs = d1.secsTo(d2); int neg = (secs < 0) ? 1 : 0; secs = qAbs(secs); int hours = secs / 3600; int mins = (secs - hours * 3600) / 60; #endif /* HAVE_TIMEZONE */ QByteArray ret; QTextStream s(&ret, QIODevice::WriteOnly); s << (neg ? '-' : '+') << qSetFieldWidth(2) << qSetPadChar(QLatin1Char('0')) << right << hours << mins; //old code: ret.sprintf( "%c%.2d%.2d", (neg) ? '-' : '+', hours, mins ); return ret; } QString DateFormatterPrivate::fancy(time_t t) { auto locale = QLocale::system(); if (t <= 0) { return i18nc("invalid time specified", "unknown"); } if (mTodayOneSecondBeforeMidnight < time(nullptr)) { // determine time_t value of today 23:59:59 const QDateTime today(QDate::currentDate(), QTime(23, 59, 59)); - mTodayOneSecondBeforeMidnight = today.toTime_t(); + mTodayOneSecondBeforeMidnight = today.toSecsSinceEpoch(); } QDateTime old; - old.setTime_t(t); + old.setSecsSinceEpoch(t); if (mTodayOneSecondBeforeMidnight >= t) { const time_t diff = mTodayOneSecondBeforeMidnight - t; if (diff < 7 * 24 * 60 * 60) { if (diff < 24 * 60 * 60) { return i18n("Today %1", locale.toString(old.time(), QLocale::ShortFormat)); } if (diff < 2 * 24 * 60 * 60) { return i18n("Yesterday %1", locale.toString(old.time(), QLocale::ShortFormat)); } for (int i = 3; i < 8; i++) { if (diff < i * 24 * 60 * 60) { return i18nc("1. weekday, 2. time", "%1 %2" , locale.dayName(old.date().dayOfWeek(), QLocale::LongFormat), locale.toString(old.time(), QLocale::ShortFormat)); } } } } return locale.toString(old, QLocale::ShortFormat); } QString DateFormatterPrivate::localized(time_t t, bool shortFormat, const QString &lang) { QDateTime tmp; QString ret; auto locale = QLocale::system(); - tmp.setTime_t(t); + tmp.setSecsSinceEpoch(t); if (!lang.isEmpty()) { locale = QLocale(lang); ret = locale.toString(tmp, (shortFormat ? QLocale::ShortFormat : QLocale::LongFormat)); } else { ret = locale.toString(tmp, (shortFormat ? QLocale::ShortFormat : QLocale::LongFormat)); } return ret; } QString DateFormatterPrivate::cTime(time_t t) { return QString::fromLatin1(ctime(&t)).trimmed(); } QString DateFormatterPrivate::isoDate(time_t t) { char cstr[64]; strftime(cstr, 63, "%Y-%m-%d %H:%M:%S", localtime(&t)); return QLatin1String(cstr); } QString DateFormatter::formatDate(FormatType ftype, time_t t, const QString &data, bool shortFormat) { DateFormatter f(ftype); if (ftype == Custom) { f.setCustomFormat(data); } return f.dateString(t, data, shortFormat); } QString DateFormatter::formatCurrentDate(FormatType ftype, const QString &data, bool shortFormat) { DateFormatter f(ftype); if (ftype == Custom) { f.setCustomFormat(data); } return f.dateString(time(nullptr), data, shortFormat); } diff --git a/tests/test_dates.cpp b/tests/test_dates.cpp index 345be08..59a6b89 100644 --- a/tests/test_dates.cpp +++ b/tests/test_dates.cpp @@ -1,95 +1,95 @@ #include "kmime_dateformatter.h" #include "kmime_header_parsing.h" #include using namespace KMime; int main() { DateFormatter t; time_t ntime = time(nullptr); qDebug() << "Time now:"; qDebug() << "tFancy : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Localized); qDebug() << "tLocalized : \t" << t.dateString(ntime); t.setFormat(DateFormatter::CTime); qDebug() << "tCTime : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Iso); qDebug() << "tIso : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Rfc); qDebug() << "trfc2822 : \t" << t.dateString(ntime); QString rfcd = t.formatDate(DateFormatter::Rfc, ntime); QDateTime dt; QDateTime qdt; QByteArray ba = rfcd.toLatin1(); const char *str = ba.constData(); if (HeaderParsing::parseDateTime(str, str + rfcd.length(), dt)) { - qDebug() << " ntime =" << (ntime) << " dt =" << (dt.toTime_t()); - qdt.setTime_t(dt.toTime_t()); + qDebug() << " ntime =" << (ntime) << " dt =" << (dt.toSecsSinceEpoch()); + qdt.setSecsSinceEpoch(dt.toSecsSinceEpoch()); qDebug() << " qq =" << qdt.toString(QStringLiteral("ddd, dd MMM yyyy hh:mm:ss")); - qDebug() << " rfc2822 :" << t.formatDate(DateFormatter::Rfc, dt.toTime_t()); + qDebug() << " rfc2822 :" << t.formatDate(DateFormatter::Rfc, dt.toSecsSinceEpoch()); } QString ddd = QStringLiteral("Mon, 05 Aug 2002 01:57:51 -0700"); ba = ddd.toLatin1(); str = ba.constData(); if (HeaderParsing::parseDateTime(str, str + ddd.length(), dt)) { - qDebug() << "dt =" << (dt.toTime_t()); - qDebug() << " rfc2822 :" << t.formatDate(DateFormatter::Rfc, dt.toTime_t()); + qDebug() << "dt =" << (dt.toSecsSinceEpoch()); + qDebug() << " rfc2822 :" << t.formatDate(DateFormatter::Rfc, dt.toSecsSinceEpoch()); } t.setCustomFormat(QStringLiteral("MMMM dddd yyyy Z")); qDebug() << "tCustom : \t" << t.dateString(ntime); ntime -= (24 * 3600 + 1); qDebug() << "Time 24 hours and 1 second ago:"; t.setFormat(DateFormatter::Fancy); qDebug() << "tFancy : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Localized); qDebug() << "tLocalized : \t" << t.dateString(ntime); t.setFormat(DateFormatter::CTime); qDebug() << "tCTime : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Iso); qDebug() << "tIso : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Rfc); qDebug() << "trfc2822 : \t" << t.dateString(ntime); t.setCustomFormat(QStringLiteral("MMMM dddd Z yyyy")); qDebug() << "tCustom : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Fancy); ntime -= (24 * 3600 * 30 + 59); qDebug() << "Time 31 days and 1 minute ago:"; qDebug() << "tFancy : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Localized); qDebug() << "tLocalized : \t" << t.dateString(ntime); t.setFormat(DateFormatter::CTime); qDebug() << "tCTime : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Iso); qDebug() << "tIso : \t" << t.dateString(ntime); t.setFormat(DateFormatter::Rfc); qDebug() << "trfc2822 : \t" << t.dateString(ntime); t.setCustomFormat(QStringLiteral("MMMM Z dddd yyyy")); qDebug() << "tCustom : \t" << t.dateString(ntime); qDebug() << "Static functions (dates like in the last test):"; qDebug() << "tFancy : \t" << DateFormatter::formatDate(DateFormatter::Fancy, ntime); qDebug() << "tLocalized : \t" << DateFormatter::formatDate(DateFormatter::Localized, ntime); qDebug() << "tCTime : \t" << DateFormatter::formatDate(DateFormatter::CTime, ntime); qDebug() << "tIso : \t" << DateFormatter::formatDate(DateFormatter::Iso, ntime); qDebug() << "trfc2822 : \t" << DateFormatter::formatDate(DateFormatter::Rfc, ntime); qDebug() << "tCustom : \t" << DateFormatter::formatDate(DateFormatter::Custom, ntime, QStringLiteral("Z MMMM dddd yyyy")); t.setFormat(DateFormatter::Fancy); qDebug() << "QDateTime taking: (dates as in first test)"; qDebug() << "tFancy : \t" << t.dateString((QDateTime::currentDateTime())); t.setFormat(DateFormatter::Localized); qDebug() << "tLocalized : \t" << t.dateString(QDateTime::currentDateTime()); t.setFormat(DateFormatter::CTime); qDebug() << "tCTime : \t" << t.dateString(QDateTime::currentDateTime()); t.setFormat(DateFormatter::Iso); qDebug() << "tIso : \t" << t.dateString(QDateTime::currentDateTime()); t.setFormat(DateFormatter::Rfc); qDebug() << "tIso : \t" << t.dateString(QDateTime::currentDateTime()); t.setCustomFormat(QStringLiteral("MMMM d dddd yyyy Z")); qDebug() << "tCustom : \t" << t.dateString(QDateTime::currentDateTime()); } diff --git a/tests/test_kmime_header_parsing.cpp b/tests/test_kmime_header_parsing.cpp index 65c9788..a3ee2fc 100644 --- a/tests/test_kmime_header_parsing.cpp +++ b/tests/test_kmime_header_parsing.cpp @@ -1,474 +1,474 @@ #include "kmime_headers.h" #include "kmime_header_parsing.h" #include #include #include //#include //#include #include #include #include #include using namespace KMime::HeaderParsing; using namespace std; static const char *tokenTypes[] = { "encoded-word", "atom", "token", "quoted-string", "domain-literal", "comment", "phrase", "dot-atom", "domain", "obs-route", "addr-spec", "angle-addr", "mailbox", "group", "address", "address-list", "parameter", "raw-parameter-list", "parameter-list", "time", "date-time" }; static const int tokenTypesLen = sizeof tokenTypes / sizeof * tokenTypes; void usage(const char *msg = nullptr) { if (msg && *msg) { cerr << msg << endl; } cerr << "usage: test_kmime_header_parsing " "(--token |--headerfield |--header)\n" "\n" " --token interpret input as and output\n" " (-t) in parsed form. Currently defined values of\n" " are:" << endl; for (int i = 0 ; i < tokenTypesLen ; ++i) { cerr << " " << tokenTypes[i] << endl; } cerr << "\n" " --headerfield interpret input as header field \n" " (-f) and output in parsed form.\n" "\n" " --header parse an RFC2822 header. Iterates over all\n" " (-h) header fields and outputs them in parsed form." << endl; exit(1); } ostream &operator<<(ostream &stream, const QString &str) { return stream << str.toUtf8().data(); } int main(int argc, char *argv[]) { if (argc == 1 || argc > 3) { usage(); } // // process options: // enum { None, Token, HeaderField, Header } action = None; const char *argument = nullptr; bool withCRLF = false; while (true) { int option_index = 0; static const struct option long_options[] = { // actions: { "token", 1, nullptr, 't' }, { "headerfield", 1, nullptr, 'f' }, { "header", 0, nullptr, 'h' }, { "crlf", 0, nullptr, 'c' }, { nullptr, 0, nullptr, 0 } }; int c = getopt_long(argc, argv, "cf:ht:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 'c': // --crlf withCRLF = true; break; case 't': // --token action = Token; argument = optarg; break; case 'f': // --headerfield usage("--headerfield is not yet implemented!"); break; case 'h': // --header usage("--header is not yet implemented!"); break; default: usage("unknown option encountered!"); } } if (optind < argc) { usage("non-option argument encountered!"); } assert(action == Token); int index; for (index = 0 ; index < tokenTypesLen ; ++index) { if (!qstricmp(tokenTypes[index], argument)) { break; } } if (index >= tokenTypesLen) { usage("unknown token type"); } //QT5 KComponentData componentData( "test_kmime_header_parsing" ); QFile stdIn; stdIn.open(stdin, QIODevice::ReadOnly); const QByteArray indata = stdIn.readAll(); stdIn.close(); QByteArray::ConstIterator iit = indata.begin(); const QByteArray::ConstIterator iend = indata.end(); switch (index) { case 0: { // encoded-word QString result; QByteArray language, charset; // must have checked for initial '=' already: bool ok = indata.size() >= 1 && *iit++ == '=' && parseEncodedWord(iit, iend, result, language, charset); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl << "language:\n" << language.data() << endl; } break; case 1: { // atom QString result = QStringLiteral("with 8bit: "); bool ok = parseAtom(iit, iend, result, true); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; result = QStringLiteral("without 8bit: "); #ifdef COMPILE_FAIL ok = parseAtom(indata.begin(), iend, result, false); #else iit = indata.begin(); ok = parseAtom(iit, iend, result, false); #endif cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 2: { // token QString result = QStringLiteral("with 8bit: "); bool ok = parseToken(iit, iend, result, ParseTokenAllow8Bit); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; result = QStringLiteral("without 8bit: "); #ifdef COMPILE_FAIL ok = parseToken(indata.begin(), iend, result, ParseTokenNoFlag); #else iit = indata.begin(); ok = parseToken(iit, iend, result, ParseTokenNoFlag); #endif cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 3: { // quoted-string QString result; // must have checked for initial '"' already: bool ok = *iit++ == '"' && parseGenericQuotedString(iit, iend, result, withCRLF, '"', '"'); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 4: { // domain-literal QString result; // must have checked for initial '[' already: bool ok = *iit++ == '[' && parseGenericQuotedString(iit, iend, result, withCRLF, '[', ']'); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 5: { // comment QString result; // must have checked for initial '(' already: bool ok = *iit++ == '(' && parseComment(iit, iend, result, withCRLF, true); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 6: { // phrase QString result; bool ok = parsePhrase(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 7: { // dot-atom QString result; bool ok = parseDotAtom(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 8: { // domain QString result; bool ok = parseDomain(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result:\n" << result << endl; } break; case 9: { // obs-route QStringList result; bool ok = parseObsRoute(iit, iend, result, withCRLF, true /*save*/); cout << (ok ? "OK" : "BAD") << endl << "result: " << result.count() << " domains:" << endl; for (QStringList::ConstIterator it = result.constBegin() ; it != result.constEnd() ; ++it) { cout << (*it) << endl; } } break; case 10: { // addr-spec KMime::Types::AddrSpec result; bool ok = parseAddrSpec(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.localPart:\n" << result.localPart << endl << "result.domain:\n" << result.domain << endl; } break; case 11: { // angle-addr KMime::Types::AddrSpec result; bool ok = parseAngleAddr(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.localPart:\n" << result.localPart << endl << "result.domain:\n" << result.domain << endl; } break; case 12: { // mailbox KMime::Types::Mailbox result; bool ok = parseMailbox(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.displayName:\n" << result.name() << endl << "result.addrSpec.localPart:\n" << result.addrSpec().localPart << endl << "result.addrSpec.domain:\n" << result.addrSpec().domain << endl; } break; case 13: { // group KMime::Types::Address result; bool ok = parseGroup(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.displayName:\n" << result.displayName << endl; int i = 0; foreach (const auto &it, result.mailboxList) { cout << "result.mailboxList[" << i << "].displayName:\n" << (it).name() << endl << "result.mailboxList[" << i << "].addrSpec.localPart:\n" << (it).addrSpec().localPart << endl << "result.mailboxList[" << i << "].addrSpec.domain:\n" << (it).addrSpec().domain << endl; ++i; } } break; case 14: { // address KMime::Types::Address result; bool ok = parseAddress(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.displayName:\n" << endl; int i = 0; foreach (const auto &it, result.mailboxList) { cout << "result.mailboxList[" << i << "].displayName:\n" << (it).name() << endl << "result.mailboxList[" << i << "].addrSpec.localPart:\n" << (it).addrSpec().localPart << endl << "result.mailboxList[" << i << "].addrSpec.domain:\n" << (it).addrSpec().domain << endl; ++i; } } break; case 15: { // address-list KMime::Types::AddressList result; bool ok = parseAddressList(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl; int j = 0; foreach (auto jt, result) { cout << "result[" << j << "].displayName:\n" << (jt).displayName << endl; int i = 0; foreach (const auto &it, (jt).mailboxList) { cout << "result[" << j << "].mailboxList[" << i << "].displayName:\n" << (it).name() << endl << "result[" << j << "].mailboxList[" << i << "].addrSpec.localPart:\n" << (it).addrSpec().localPart << endl << "result[" << j << "].mailboxList[" << i << "].addrSpec.domain:\n" << (it).addrSpec().domain << endl; ++i; } ++j; } } break; case 16: { // parameter QPair result; bool ok = parseParameter(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.first (attribute):\n" << result.first << endl << "result.second.qstring (value):\n" << result.second.qstring << endl << "result.second.qpair (value):\n" << QByteArray(result.second.qpair.first, result.second.qpair.second + 1).data() << endl; } break; case 17: { // raw-parameter-list QMap result; bool ok = parseRawParameterList(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result: " << result.count() << " raw parameters:" << endl; int i = 0; for (QMap::ConstIterator it = result.constBegin(); it != result.constEnd() ; ++it, ++i) { cout << "result[" << i << "].key() (attribute):\n" << it.key() << endl << "result[" << i << "].data().qstring (value):\n" << it.value().qstring << endl << "result[" << i << "].data().qpair (value):\n" << QByteArray(it.value().qpair.first, it.value().qpair.second + 1).data() << endl; } } break; case 18: { // parameter-list QMap result; bool ok = parseParameterList(iit, iend, result, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result: " << result.count() << " parameters:" << endl; int i = 0; for (QMap::Iterator it = result.begin() ; it != result.end() ; ++it, ++i) { cout << "result[" << i << "].key() (attribute):\n" << it.key() << endl << "result[" << i << "].data() (value):\n" << it.value() << endl; } } break; case 19: { // time int hour, mins, secs; long int secsEastOfGMT; bool timeZoneKnown = true; bool ok = parseTime(iit, iend, hour, mins, secs, secsEastOfGMT, timeZoneKnown, withCRLF); cout << (ok ? "OK" : "BAD") << endl << "result.hour: " << hour << endl << "result.mins: " << mins << endl << "result.secs: " << secs << endl << "result.secsEastOfGMT: " << secsEastOfGMT << endl << "result.timeZoneKnown: " << timeZoneKnown << endl; } break; case 20: { // date-time QDateTime result; bool ok = parseDateTime(iit, iend, result, withCRLF); - time_t timet = result.toTime_t(); + time_t timet = result.toSecsSinceEpoch(); cout << (ok ? "OK" : "BAD") << endl << "result.time (in local timezone): " << ctime(&timet) << "result.secsEastOfGMT: " << result.offsetFromUtc() << " (" << result.offsetFromUtc() / 60 << "mins)" << endl; } break; default: assert(0); } }