diff options
Diffstat (limited to 'examples/maildirresource/libmaildir/maildir.cpp')
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.cpp | 193 |
1 files changed, 109 insertions, 84 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp index 3d4630f..59e7e5c 100644 --- a/examples/maildirresource/libmaildir/maildir.cpp +++ b/examples/maildirresource/libmaildir/maildir.cpp | |||
@@ -142,7 +142,6 @@ public: | |||
142 | { | 142 | { |
143 | // KeyCache* keyCache = KeyCache::self(); | 143 | // KeyCache* keyCache = KeyCache::self(); |
144 | // if (keyCache->isNewKey(path, key)) { | 144 | // if (keyCache->isNewKey(path, key)) { |
145 | qWarning() << path + QString::fromLatin1("/new/") + key; | ||
146 | if (QFile::exists(path + QString::fromLatin1("/new/") + key)) { | 145 | if (QFile::exists(path + QString::fromLatin1("/new/") + key)) { |
147 | #ifdef DEBUG_KEYCACHE_CONSITENCY | 146 | #ifdef DEBUG_KEYCACHE_CONSITENCY |
148 | if (!QFile::exists(path + QString::fromLatin1("/new/") + key)) { | 147 | if (!QFile::exists(path + QString::fromLatin1("/new/") + key)) { |
@@ -178,6 +177,13 @@ public: | |||
178 | return realKey; | 177 | return realKey; |
179 | } | 178 | } |
180 | 179 | ||
180 | static QString stripFlags(const QString& key) | ||
181 | { | ||
182 | const QRegExp rx = *(statusSeparatorRx()); | ||
183 | const int index = key.indexOf(rx); | ||
184 | return key.mid(0, index); | ||
185 | } | ||
186 | |||
181 | static QString subDirNameForFolderName(const QString &folderName) | 187 | static QString subDirNameForFolderName(const QString &folderName) |
182 | { | 188 | { |
183 | return QString::fromLatin1(".%1.directory").arg(folderName); | 189 | return QString::fromLatin1(".%1.directory").arg(folderName); |
@@ -560,7 +566,20 @@ QDateTime Maildir::lastModified(const QString& key) const | |||
560 | return info.lastModified(); | 566 | return info.lastModified(); |
561 | } | 567 | } |
562 | 568 | ||
563 | QByteArray Maildir::readEntryHeadersFromFile(const QString& file) const | 569 | QString Maildir::getKeyFromFile(const QString& file) |
570 | { | ||
571 | return Maildir::Private::stripFlags(file.split('/').last()); | ||
572 | } | ||
573 | |||
574 | QString Maildir::getDirectoryFromFile( const QString& file ) | ||
575 | { | ||
576 | auto parts = file.split('/'); | ||
577 | parts.removeLast(); //File | ||
578 | parts.removeLast(); //cur/new/tmp | ||
579 | return parts.join('/') + "/"; | ||
580 | } | ||
581 | |||
582 | QByteArray Maildir::readEntryHeadersFromFile(const QString& file) | ||
564 | { | 583 | { |
565 | QByteArray result; | 584 | QByteArray result; |
566 | 585 | ||
@@ -643,9 +662,14 @@ QString Maildir::addEntry(const QByteArray& data) | |||
643 | 662 | ||
644 | QFile f(key); | 663 | QFile f(key); |
645 | bool result = f.open(QIODevice::WriteOnly); | 664 | bool result = f.open(QIODevice::WriteOnly); |
665 | if (!result) { | ||
666 | qWarning() << f.errorString(); | ||
667 | qWarning() << "Cannot write to mail file: " << key; | ||
668 | } | ||
646 | result = result & (f.write(data) != -1); | 669 | result = result & (f.write(data) != -1); |
647 | f.close(); | 670 | f.close(); |
648 | if (!result) { | 671 | if (!result) { |
672 | qWarning() << "Cannot write to mail file: " << key; | ||
649 | // d->lastError = i18n("Cannot write to mail file %1." , key); | 673 | // d->lastError = i18n("Cannot write to mail file %1." , key); |
650 | return QString(); | 674 | return QString(); |
651 | } | 675 | } |
@@ -688,88 +712,89 @@ bool Maildir::removeEntry(const QString& key) | |||
688 | // return QFile::remove(realKey); | 712 | // return QFile::remove(realKey); |
689 | } | 713 | } |
690 | 714 | ||
691 | // QString Maildir::changeEntryFlags(const QString& key, const Sink::Item::Flags& flags) | 715 | QString Maildir::changeEntryFlags(const QString& key, const Maildir::Flags& flags) |
692 | // { | 716 | { |
693 | // QString realKey(d->findRealKey(key)); | 717 | QString realKey(d->findRealKey(key)); |
694 | // if (realKey.isEmpty()) { | 718 | if (realKey.isEmpty()) { |
695 | // qWarning() << "Maildir::changeEntryFlags unable to find: " << key; | 719 | qWarning() << "Maildir::changeEntryFlags unable to find: " << key; |
696 | // d->lastError = i18n("Cannot locate mail file %1." , key); | 720 | // d->lastError = i18n("Cannot locate mail file %1." , key); |
697 | // return QString(); | 721 | return QString(); |
698 | // } | 722 | } |
699 | // | 723 | |
700 | // const QRegExp rx = *(statusSeparatorRx()); | 724 | const QRegExp rx = *(statusSeparatorRx()); |
701 | // QString finalKey = key.left(key.indexOf(rx)); | 725 | QString finalKey = key.left(key.indexOf(rx)); |
702 | // | 726 | |
703 | // QStringList mailDirFlags; | 727 | QStringList mailDirFlags; |
704 | // Q_FOREACH (const Sink::Item::Flag &flag, flags) { | 728 | if (flags & Forwarded) |
705 | // if (flag == Sink::MessageFlags::Forwarded) | 729 | mailDirFlags << QLatin1String("P"); |
706 | // mailDirFlags << QLatin1String("P"); | 730 | if (flags & Replied) |
707 | // if (flag == Sink::MessageFlags::Replied) | 731 | mailDirFlags << QLatin1String("R"); |
708 | // mailDirFlags << QLatin1String("R"); | 732 | if (flags & Seen) |
709 | // if (flag == Sink::MessageFlags::Seen) | 733 | mailDirFlags << QLatin1String("S"); |
710 | // mailDirFlags << QLatin1String("S"); | 734 | if (flags & Deleted) |
711 | // if (flag == Sink::MessageFlags::Deleted) | 735 | mailDirFlags << QLatin1String("T"); |
712 | // mailDirFlags << QLatin1String("T"); | 736 | if (flags & Flagged) |
713 | // if (flag == Sink::MessageFlags::Flagged) | 737 | mailDirFlags << QLatin1String("F"); |
714 | // mailDirFlags << QLatin1String("F"); | 738 | |
715 | // } | 739 | mailDirFlags.sort(); |
716 | // mailDirFlags.sort(); | 740 | if (!mailDirFlags.isEmpty()) { |
717 | // if (!mailDirFlags.isEmpty()) { | 741 | #ifdef Q_OS_WIN |
718 | // #ifdef Q_OS_WIN | 742 | finalKey.append(QLatin1String("!2,") + mailDirFlags.join(QString())); |
719 | // finalKey.append(QLatin1String("!2,") + mailDirFlags.join(QString())); | 743 | #else |
720 | // #else | 744 | finalKey.append(QLatin1String(":2,") + mailDirFlags.join(QString())); |
721 | // finalKey.append(QLatin1String(":2,") + mailDirFlags.join(QString())); | 745 | #endif |
722 | // #endif | 746 | } |
723 | // } | 747 | |
724 | // | 748 | QString newUniqueKey = finalKey; //key without path |
725 | // QString newUniqueKey = finalKey; //key without path | 749 | finalKey.prepend(d->path + QString::fromLatin1("/cur/")); |
726 | // finalKey.prepend(d->path + QString::fromLatin1("/cur/")); | 750 | |
727 | // | 751 | if (realKey == finalKey) { |
728 | // if (realKey == finalKey) { | 752 | // Somehow it already is named this way (e.g. migration bug -> wrong status in sink) |
729 | // // Somehow it already is named this way (e.g. migration bug -> wrong status in sink) | 753 | qWarning() << "File already named that way: " << newUniqueKey << finalKey; |
730 | // return newUniqueKey; | 754 | return newUniqueKey; |
731 | // } | 755 | } |
732 | // | 756 | |
733 | // QFile f(realKey); | 757 | QFile f(realKey); |
734 | // if (QFile::exists(finalKey)) { | 758 | if (QFile::exists(finalKey)) { |
735 | // QFile destFile(finalKey); | 759 | QFile destFile(finalKey); |
736 | // QByteArray destContent; | 760 | QByteArray destContent; |
737 | // if (destFile.open(QIODevice::ReadOnly)) { | 761 | if (destFile.open(QIODevice::ReadOnly)) { |
738 | // destContent = destFile.readAll(); | 762 | destContent = destFile.readAll(); |
739 | // destFile.close(); | 763 | destFile.close(); |
740 | // } | 764 | } |
741 | // QByteArray sourceContent; | 765 | QByteArray sourceContent; |
742 | // if (f.open(QIODevice::ReadOnly)) { | 766 | if (f.open(QIODevice::ReadOnly)) { |
743 | // sourceContent = f.readAll(); | 767 | sourceContent = f.readAll(); |
744 | // f.close(); | 768 | f.close(); |
745 | // } | 769 | } |
746 | // | 770 | |
747 | // if (destContent != sourceContent) { | 771 | if (destContent != sourceContent) { |
748 | // QString newFinalKey = QLatin1String("1-") + newUniqueKey; | 772 | QString newFinalKey = QLatin1String("1-") + newUniqueKey; |
749 | // int i = 1; | 773 | int i = 1; |
750 | // while (QFile::exists(d->path + QString::fromLatin1("/cur/") + newFinalKey)) { | 774 | while (QFile::exists(d->path + QString::fromLatin1("/cur/") + newFinalKey)) { |
751 | // i++; | 775 | i++; |
752 | // newFinalKey = QString::number(i) + QLatin1Char('-') + newUniqueKey; | 776 | newFinalKey = QString::number(i) + QLatin1Char('-') + newUniqueKey; |
753 | // } | 777 | } |
754 | // finalKey = d->path + QString::fromLatin1("/cur/") + newFinalKey; | 778 | finalKey = d->path + QString::fromLatin1("/cur/") + newFinalKey; |
755 | // } else { | 779 | } else { |
756 | // QFile::remove(finalKey); //they are the same | 780 | QFile::remove(finalKey); //they are the same |
757 | // } | 781 | } |
758 | // } | 782 | } |
759 | // | 783 | |
760 | // if (!f.rename(finalKey)) { | 784 | if (!f.rename(finalKey)) { |
761 | // qWarning() << "Maildir: Failed to rename entry: " << f.fileName() << " to " << finalKey << "! Error: " << f.errorString(); | 785 | qWarning() << "Maildir: Failed to rename entry: " << f.fileName() << " to " << finalKey << "! Error: " << f.errorString(); |
762 | // d->lastError = i18n("Failed to update the file name %1 to %2 on the disk. The error was: %3." , f.fileName(), finalKey, f.errorString()); | 786 | // d->lastError = i18n("Failed to update the file name %1 to %2 on the disk. The error was: %3." , f.fileName(), finalKey, f.errorString()); |
763 | // return QString(); | 787 | return QString(); |
764 | // } | 788 | } |
765 | // | 789 | qWarning() << "Renamed file: " << f.fileName() << finalKey; |
766 | // KeyCache *keyCache = KeyCache::self(); | 790 | |
767 | // keyCache->removeKey(d->path, key); | 791 | // KeyCache *keyCache = KeyCache::self(); |
768 | // keyCache->addCurKey(d->path, newUniqueKey); | 792 | // keyCache->removeKey(d->path, key); |
769 | // | 793 | // keyCache->addCurKey(d->path, newUniqueKey); |
770 | // return newUniqueKey; | 794 | |
771 | // } | 795 | return newUniqueKey; |
772 | // | 796 | } |
797 | |||
773 | Maildir::Flags Maildir::readEntryFlags(const QString& key) | 798 | Maildir::Flags Maildir::readEntryFlags(const QString& key) |
774 | { | 799 | { |
775 | Flags flags; | 800 | Flags flags; |