diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-14 12:45:58 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-14 12:45:58 +0200 |
| commit | 8cf71bb617c34f52357ce0597c7d07601337828b (patch) | |
| tree | a4426bd014cde0d244373435852aba806eb6d0e0 /src/mimeparser.cpp | |
| parent | 441b93a75b9941d395edfe4b65ed0af2da9e0021 (diff) | |
| download | qtmaildir-8cf71bb617c34f52357ce0597c7d07601337828b.tar.gz qtmaildir-8cf71bb617c34f52357ce0597c7d07601337828b.zip | |
refactor(mime): expose the Date: header parse as MimeParser::parseDate
The date search needs it and the logic already existed inside a file-local
function, including the fix for Qt::RFC2822Date rejecting a string that
carries a trailing timezone comment. Extracted rather than rewritten, so the
second caller cannot end up without that fix.
Diffstat (limited to 'src/mimeparser.cpp')
| -rw-r--r-- | src/mimeparser.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/mimeparser.cpp b/src/mimeparser.cpp index ecf56f1..2782a4a 100644 --- a/src/mimeparser.cpp +++ b/src/mimeparser.cpp @@ -272,20 +272,25 @@ QString recipientSummary(const QString &rawTo, int maxNames) return summary; } -QString attachmentFolderName(const QString &rfc822Date, const QString &subject) +QDateTime MimeParser::parseDate(const QString &rfc822Date) { - // The date prefix sorts chronologically in a file manager. A Date: header - // that does not parse is simply dropped rather than guessed at. // A trailing timezone comment, "... +0200 (CEST)", is legal per RFC 5322 // and common in the wild, but Qt::RFC2822Date rejects the whole string // when one is present (verified on Qt 6.11). Strip comments before - // parsing, or every such message silently loses its date prefix. + // parsing, or every such message silently loses its date. QString cleaned = rfc822Date; cleaned.remove(QRegularExpression(QStringLiteral("\\s*\\([^)]*\\)"))); cleaned = cleaned.trimmed(); + return QDateTime::fromString(cleaned, Qt::RFC2822Date); +} + +QString attachmentFolderName(const QString &rfc822Date, const QString &subject) +{ + // The date prefix sorts chronologically in a file manager. A Date: header + // that does not parse is simply dropped rather than guessed at. QString prefix; - const QDateTime parsed = QDateTime::fromString(cleaned, Qt::RFC2822Date); + const QDateTime parsed = MimeParser::parseDate(rfc822Date); if (parsed.isValid()) prefix = parsed.toString(QStringLiteral("yyyy-MM-dd")); |
