Hopefully last major charset improvement.

All known charset related problems should be fixed with that.
- Automatic recoding works correctely for forward and reply
- Redirect works now also with the correct charset
- No characters are lost from the reply phrase when replying to a message with
  a different encoding
- File insertion uses the correct charset for the file

svn path=/trunk/kdenetwork/kmail/; revision=72962
wilder-work
Michael Haeckel 26 years ago
parent 3ff86b31cd
commit ec6694da87
  1. 2
      configuredialog.cpp
  2. 74
      kmcomposewin.cpp
  3. 4
      kmcomposewin.h
  4. 2
      kmfldsearch.cpp
  5. 5
      kmheaders.cpp
  6. 18
      kmmainwin.cpp
  7. 45
      kmmessage.cpp
  8. 8
      kmmessage.h
  9. 2
      kmreaderwin.cpp

@ -1158,7 +1158,7 @@ void ConfigureDialog::makeComposerPage( void )
mComposer.defaultCharsetCombo = new QComboBox( defaultCharsetGroup );
charsetVLay->addWidget( mComposer.defaultCharsetCombo );
mComposer.forceReplyCharsetCheck =
new QCheckBox( i18n("Use own default charset when replying"),
new QCheckBox( i18n("Use own default charset when replying or forwarding"),
defaultCharsetGroup );
charsetVLay->addWidget( mComposer.forceReplyCharsetCheck );
topLevel3->addWidget( defaultCharsetGroup );

@ -276,6 +276,7 @@ void KMComposeWin::readConfig(void)
kdDebug() << "Default charset: " << (const char*)mDefCharset << endl;
mForceReplyCharset = config->readBoolEntry("force-reply-charset", false );
mAutoSign = config->readEntry("signature","auto") == "auto";
mDefEncoding = config->readEntry("encoding", "base64");
mShowHeaders = config->readNumEntry("headers", HDR_STANDARD);
@ -957,7 +958,9 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign)
bodyDecoded = bodyPart.bodyDecoded();
verifyWordWrapLengthIsAdequate(bodyDecoded);
mEditor->setText(bodyDecoded);
QTextCodec *codec = KGlobal::charsets()->codecForName(mCharset);
mEditor->setText(codec->toUnicode(bodyDecoded));
mEditor->insertLine("\n", -1);
for(i=1; i<num; i++)
@ -977,19 +980,7 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign)
mEditor->setText(codec->toUnicode(mMsg->bodyDecoded()));
}
setEditCharset();
QStringList encodings = encodingAction->items();
i = 0;
for ( QStringList::Iterator it = encodings.begin(); it != encodings.end(); ++it, i++ )
// it's safer to compare QFont::CharSet rather that strings directly
if (KGlobal::charsets()->nameToID(*it) == KGlobal::charsets()->nameToID(mCharset))
{
encodingAction->setCurrentItem( i );
slotSetCharset();
break;
}
setCharset(mCharset);
if( mAutoSign && mayAutoSign )
{
@ -1338,6 +1329,28 @@ void KMComposeWin::addrBookSelInto(KMLineEdit* aLineEdit)
}
//-----------------------------------------------------------------------------
void KMComposeWin::setCharset(const QString& aCharset, bool forceDefault)
{
if (forceDefault && mForceReplyCharset) mCharset = mDefCharset;
else mCharset = aCharset;
mMsg->setCharset(mCharset);
QStringList encodings = encodingAction->items();
int i = 0;
for ( QStringList::Iterator it = encodings.begin(); it != encodings.end();
++it, i++ )
{
if (QTextCodec::codecForName(*it) == QTextCodec::codecForName(mCharset))
{
encodingAction->setCurrentItem( i );
slotSetCharset();
break;
}
}
}
//-----------------------------------------------------------------------------
void KMComposeWin::slotAddrBook()
{
@ -1381,23 +1394,21 @@ void KMComposeWin::slotAddrBookBcc()
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void KMComposeWin::slotAttachFile()
{
// Create File Dialog and return selected file(s)
// We will not care about any permissions, existence or whatsoever in
// this function.
KURL::List files = KFileDialog::getOpenURLs(QString::null, "*", this, i18n("Attach File"));
QStringList list = files.toStringList();
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
QString name = *it;
if(!name.isEmpty()) {
addAttach(name);
}
}
void KMComposeWin::slotAttachFile()
{
// Create File Dialog and return selected file(s)
// We will not care about any permissions, existence or whatsoever in
// this function.
KURL::List files = KFileDialog::getOpenURLs(QString::null, "*", this, i18n("Attach File"));
QStringList list = files.toStringList();
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
QString name = *it;
if(!name.isEmpty()) {
addAttach(name);
}
}
}
//-----------------------------------------------------------------------------
@ -1427,7 +1438,7 @@ void KMComposeWin::slotAttachFileResult(KIO::Job *job)
{
int col, line;
mEditor->getCursorPosition(&line, &col);
mEditor->insertAt((*it).data, line, col);
mEditor->insertAt(QString::fromLocal8Bit((*it).data), line, col);
mapAtmLoadData.remove(it);
return;
}
@ -1498,8 +1509,7 @@ void KMComposeWin::slotInsertFile()
void KMComposeWin::slotSetCharset()
{
mCharset = encodingAction->currentText();
if (mAtmList.count() <= 0)
mMsg->setCharset(mCharset);
mMsg->setCharset(mCharset);
setEditCharset();
}

@ -175,6 +175,9 @@ public:
the composer is closed and the message was not sent. Default: FALSE */
inline void setAutoDelete(bool f) { mAutoDeleteMsg = f; }
/** Recode to the specified charset */
void setCharset(const QString& aCharset, bool forceDefault = FALSE);
public slots:
//Actions:
void slotPrint();
@ -417,6 +420,7 @@ private:
};
QMap<KIO::Job *, atmLoadData> mapAtmLoadData;
bool mUnicodeFont;
bool mForceReplyCharset;
};
#endif

@ -450,7 +450,7 @@ void KMFldSearchRule::prepare(void)
mField = mCbxField->currentText();
mFunc = mCbxFunc->currentItem();
mValue = mEdtValue->text();
mNonLatin = QCString(mValue.latin1()).length() != mValue.length();
mNonLatin = mValue.utf8().length() != mValue.length();
}

@ -1137,6 +1137,7 @@ void KMHeaders::forwardMsg ()
kernel->kbp()->busy();
win = new KMComposeWin(msg->createForward(),
msg->headerField( "X-KMail-Identity" ));
win->setCharset(msg->codec()->name(), TRUE);
win->show();
kernel->kbp()->idle();
}
@ -1152,6 +1153,7 @@ void KMHeaders::redirectMsg()
kernel->kbp()->busy();
win = new KMComposeWin(msg->createRedirect());
win->setCharset(msg->codec()->name());
win->show();
kernel->kbp()->idle();
}
@ -1169,6 +1171,7 @@ void KMHeaders::replyToMsg ()
kernel->kbp()->busy();
win = new KMComposeWin(msg->createReply(FALSE),
msg->headerField( "X-KMail-Identity" ));
win->setCharset(msg->codec()->name(), TRUE);
win->show();
kernel->kbp()->idle();
}
@ -1184,6 +1187,7 @@ void KMHeaders::replyAllToMsg ()
kernel->kbp()->busy();
win = new KMComposeWin(msg->createReply(TRUE));
win->setCharset(msg->codec()->name(), TRUE);
win->show();
kernel->kbp()->idle();
}
@ -1198,6 +1202,7 @@ void KMHeaders::replyListToMsg ()
kernel->kbp()->busy();
win = new KMComposeWin(msg->createReply(true, true));
win->setCharset(msg->codec()->name(), TRUE);
win->show();
kernel->kbp()->idle();
}

@ -1243,13 +1243,14 @@ void KMMainWin::slotMailtoCompose()
void KMMainWin::slotMailtoReply()
{
KMComposeWin *win;
KMMessage *msg;
KMMessage *msg, *rmsg;
if (!(msg = mHeaders->getMsg(-1))) return;
msg = msg->createReply(FALSE);
msg->setTo(mUrlCurrent.path());
rmsg = msg->createReply(FALSE);
rmsg->setTo(mUrlCurrent.path());
win = new KMComposeWin(msg);
win = new KMComposeWin(rmsg);
win->setCharset(msg->codec()->name(), TRUE);
win->show();
}
@ -1258,13 +1259,14 @@ void KMMainWin::slotMailtoReply()
void KMMainWin::slotMailtoForward()
{
KMComposeWin *win;
KMMessage *msg;
KMMessage *msg, *fmsg;
if (!(msg = mHeaders->getMsg(-1))) return;
msg = msg->createForward();
msg->setTo(mUrlCurrent.path());
fmsg = msg->createForward();
fmsg->setTo(mUrlCurrent.path());
win = new KMComposeWin(msg);
win = new KMComposeWin(fmsg);
win->setCharset(msg->codec()->name(), TRUE);
win->show();
}

@ -49,8 +49,7 @@ static DwString emptyString("");
// Values that are set from the config file with KMMessage::readConfig()
static QString sReplyLanguage, sReplyStr, sReplyAllStr, sIndentPrefixStr;
static bool sSmartQuote, sReplaceSubjPrefix, sReplaceForwSubjPrefix,
sForceReplyCharset;;
static bool sSmartQuote, sReplaceSubjPrefix, sReplaceForwSubjPrefix;
static int sWrapCol;
static QStringList sReplySubjPrefixes, sForwardSubjPrefixes;
@ -578,12 +577,14 @@ const QCString KMMessage::asQuotedString(const QString& aHeaderStr,
bool isInline;
int i;
QString cset = charset();
QTextCodec* codec;
if (!cset.isEmpty() && !cset.isNull())
codec = KGlobal::charsets()->codecForName(charset());
else
codec = QTextCodec::codecForLocale();
QTextCodec *codec = mCodec;
if (!codec)
{
QString cset = charset();
if (!cset.isEmpty())
codec = QTextCodec::codecForName(cset);
if (!codec) codec = QTextCodec::codecForLocale();
}
indentStr = formatString(aIndentStr);
headerStr = formatString(aHeaderStr);
@ -619,13 +620,6 @@ const QCString KMMessage::asQuotedString(const QString& aHeaderStr,
isInline = (stricmp(msgPart.contentDisposition(), "inline") == 0);
if (isInline) {
if (cset.isEmpty()) {
cset = msgPart.charset();
if (!cset.isEmpty())
codec = KGlobal::charsets()->codecForName(charset());
else
codec = QTextCodec::codecForLocale();
}
if (stricmp(msgPart.typeStr(),"text") == 0 ||
stricmp(msgPart.typeStr(),"message") == 0) {
Kpgp* pgp = Kpgp::getKpgp();
@ -664,7 +658,7 @@ const QCString KMMessage::asQuotedString(const QString& aHeaderStr,
}
}
QCString c = codec->fromUnicode(headerStr + "\n" + result);
QCString c = QString(headerStr + "\n" + result).utf8();
return c;
}
@ -683,7 +677,7 @@ KMMessage* KMMessage::createReply(bool replyToAll, bool replyToList)
mailingListStr = headerField("X-Mailing-List");
replyToStr = replyTo();
msg->setCharset(charset());
msg->setCharset("utf-8");
if (replyToList && parent()->isMailingList())
{
@ -811,8 +805,6 @@ KMMessage* KMMessage::createReply(bool replyToAll, bool replyToList)
if (!recognized)
msg->setSubject("Re: " + subject());
if ( sForceReplyCharset )
msg->setCharset("");
setStatus(KMMsgStatusReplied);
return msg;
@ -852,17 +844,19 @@ KMMessage* KMMessage::createRedirect(void)
{
KMMessage* msg = new KMMessage;
KMMessagePart msgPart;
QString str = "";
QCString str = "";
int i;
str = asQuotedString(str, "", FALSE, false);
msg->setBody(str.latin1());
msg->setHeaderField("Content-Type","text/plain; charset=\"utf-8\"");
msg->setBody(str);
if (numBodyParts() > 0)
{
msgPart.setBody(str.latin1());
msgPart.setBody(str);
msgPart.setTypeStr("text");
msgPart.setSubtypeStr("plain");
msgPart.setCharset("utf-8");
msg->addBodyPart(&msgPart);
for (i = 1; i < numBodyParts(); i++)
@ -881,7 +875,6 @@ KMMessage* KMMessage::createRedirect(void)
msg->setHeaderField("X-KMail-Redirect-From", from());
msg->setSubject(subject());
msg->setFrom(from());
msg->setCharset(charset());
setStatus(KMMsgStatusForwarded);
return msg;
@ -915,14 +908,15 @@ KMMessage* KMMessage::createForward(void)
str += "\n-------------------------------------------------------\n";
}
if (!charset().isEmpty()) msg->setCharset(charset());
msg->setCharset("utf-8");
msg->setBody(str);
if (numBodyParts() > 0)
{
msgPart.setBody(str);
msgPart.setTypeStr("text");
msgPart.setSubtypeStr("plain");
msgPart.setCharset("utf-8");
msgPart.setBody(str);
msg->addBodyPart(&msgPart);
for (i = 1; i < numBodyParts(); i++)
@ -2096,7 +2090,6 @@ void KMMessage::readConfig(void)
if (sForwardSubjPrefixes.count() == 0)
sForwardSubjPrefixes.append("Fwd:");
sReplaceForwSubjPrefix = config->readBoolEntry("replace-forward-prefix", true);
sForceReplyCharset = config->readBoolEntry("force-reply-charset", false );
config->setGroup("Reader");
sHdrStyle = config->readNumEntry("hdr-style", KMReaderWin::HdrFancy);

@ -294,6 +294,13 @@ public:
/** Set the message charset. */
virtual void setCharset(const QString& aStr);
/** Get the charset the user selected for the message to display */
virtual QTextCodec* codec(void) const
{ return mCodec; }
/** Set the charset the user selected for the message to display */
virtual void setCodec(QTextCodec* aCodec)
{ mCodec = aCodec; }
#ifdef KRN
/** Convert a normal References: header into a list of anchors
@ -319,6 +326,7 @@ protected:
bool mNeedsAssembly;
static int sHdrStyle;
static QString sForwardStr;
QTextCodec* mCodec;
};
typedef KMMessage* KMMessagePtr;

@ -515,6 +515,8 @@ void KMReaderWin::parseMsg(void)
if (!mCodec)
mCodec = QTextCodec::codecForName("iso8859-1");
mMsg->setCodec(mCodec);
if (mViewer)
if (mUnicodeFont)
mViewer->setCharset("iso10646-1", true);

Loading…
Cancel
Save