diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index 126180051..18f1c3cfd 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -13,6 +13,7 @@ #include "kmcomposewin.h" #include "kmmessage.h" +#include "kmmsgbase.h" #include "kmmsgpart.h" #include "kmsender.h" #include "kmidentity.h" @@ -1254,7 +1255,8 @@ void KMComposeWin::addAttach(const QString aUrl) msgPart->setCteStr(mDefEncoding); msgPart->setBodyEncoded(str); msgPart->magicSetType(); - msgPart->setContentDisposition("attachment; filename=\""+name+"\""); + msgPart->setContentDisposition("attachment; filename=\"" + + KMMsgBase::encodeRFC2047String(name) + "\""); // show properties dialog kernel->kbp()->idle(); diff --git a/kmmessage.cpp b/kmmessage.cpp index 8721a2611..10a61cf03 100644 --- a/kmmessage.cpp +++ b/kmmessage.cpp @@ -1338,7 +1338,7 @@ void KMMessage::setHeaderField(const QString& aName, const QString& bValue) DwField* field; QString aValue = ""; if (!bValue.isEmpty()) - aValue = bValue; + aValue = encodeRFC2047String(bValue); if (aName.isEmpty()) return; @@ -1716,9 +1716,10 @@ void KMMessage::addBodyPart(const KMMessagePart* aPart) QString type = aPart->typeStr(); QString subtype = aPart->subtypeStr(); QString cte = aPart->cteStr(); - QString contDesc = aPart->contentDescription(); + QString contDesc = KMMsgBase::encodeRFC2047String(aPart-> + contentDescription()); QString contDisp = aPart->contentDisposition(); - QString name = aPart->name(); + QString name = KMMsgBase::encodeRFC2047String(aPart->name()); #if defined CHARSETS QString charset = aPart->charset(); #endif diff --git a/kmmsgbase.cpp b/kmmsgbase.cpp index 13ed2dd6f..825ddd8c3 100644 --- a/kmmsgbase.cpp +++ b/kmmsgbase.cpp @@ -10,6 +10,7 @@ #endif #include +#include #define NUM_STATUSLIST 9 static KMMsgStatus sStatusList[NUM_STATUSLIST] = @@ -361,6 +362,77 @@ const QString KMMsgBase::decodeRFC1522String(const QString& _str) } +//----------------------------------------------------------------------------- +const char especials[16] = "()<>@,;:""/[]?.= "; + +const QString KMMsgBase::encodeRFC2047String(const QString& _str) +{ + if (_str.isEmpty()) return _str; + char *latin = (char *)calloc(1, _str.length() + 1); + strcpy(latin, _str.latin1()); + char *latinStart = latin, *l, *start, *stop; + char hexcode; + int numQuotes, i; + QString result = QString(); + while (*latin) + { + l = latin; + start = latin; + while (*l) + { + if (*l == 32) start = l + 1; + if (*l < 0) break; + l++; + } + if (*l) + { + numQuotes = 1; + while (*l) + { + /* The encoded word must be limited to 75 character */ + for (i = 0; i < 16; i++) if (*l == especials[i]) numQuotes++; + if (*l < 0) numQuotes++; + /* Stop after 58 = 75 - 17 characters or at "= 58 || *l == 60) break; + l++; + } + if (*l) + { + stop = l - 1; + while (stop >= start && *stop != 32) stop--; + if (stop <= start) stop = l; + } else stop = l; + while (latin < start) { result += *latin; latin++; } + result += QString("=?iso-8859-1?q?"); + while (latin < stop) + { + numQuotes = 0; + for (i = 0; i < 16; i++) if (*latin == especials[i]) numQuotes = 1; + if (*latin < 0) numQuotes = 1; + if (numQuotes) + { + result += "="; + hexcode = ((*latin & 0xF0) >> 4) + 48; + if (hexcode >= 58) hexcode += 7; + result += hexcode; + hexcode = (*latin & 0x0F) + 48; + if (hexcode >= 58) hexcode += 7; + result += hexcode; + } else { + result += *latin; + } + latin++; + } + result += "?="; + } else { + while (*latin) { result += *latin; latin++; } + } + } + free(latinStart); + return result; +} + + //----------------------------------------------------------------------------- const QString KMMsgBase::decodeQuotedPrintableString(const QString& aStr) { diff --git a/kmmsgbase.h b/kmmsgbase.h index ace95a1a2..35dafb2d7 100644 --- a/kmmsgbase.h +++ b/kmmsgbase.h @@ -127,6 +127,10 @@ public: Base64 ("=?iso-8859-1?b?...?=") and quoted-printable */ static const QString decodeRFC1522String(const QString& aStr); + /** Encode given string as described in RFC2047 (update for RFC1522) + using quoted-printable. */ + static const QString encodeRFC2047String(const QString& aStr); + protected: KMFolder* mParent; unsigned long mFolderOffset, mMsgSize; diff --git a/kmmsgpart.cpp b/kmmsgpart.cpp index 4b0cebb11..066bd7a73 100644 --- a/kmmsgpart.cpp +++ b/kmmsgpart.cpp @@ -10,6 +10,7 @@ #include #include +#include "kmmsgbase.h" #include "kmmsgpart.h" #include "kmmessage.h" @@ -300,7 +301,7 @@ void KMMessagePart::setContentTransferEncoding(int aCte) //----------------------------------------------------------------------------- const QString KMMessagePart::contentDescription(void) const { - return mContentDescription; + return KMMsgBase::decodeRFC1522String(mContentDescription); }