summaryrefslogtreecommitdiff
authorsandman <sandman>2002-08-06 00:55:56 (UTC)
committer sandman <sandman>2002-08-06 00:55:56 (UTC)
commitb980135ff5ce5447ca41411b6ace74ce2803fadb (patch) (side-by-side diff)
treec02cdd16e1435855bff16e2c2707f5d5484d43f4
parentd96244956f42782f987acc2b5efb32dc1f1dd70a (diff)
downloadopie-b980135ff5ce5447ca41411b6ace74ce2803fadb.zip
opie-b980135ff5ce5447ca41411b6ace74ce2803fadb.tar.gz
opie-b980135ff5ce5447ca41411b6ace74ce2803fadb.tar.bz2
mail2 should display (most) mails now with these workarounds. imap handling
is still buggy by design though.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/libmail/configfile.cpp4
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.cpp36
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.h3
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.cpp7
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.cpp224
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.h5
-rw-r--r--noncore/unsupported/mail2/viewmail.cpp4
7 files changed, 194 insertions, 89 deletions
diff --git a/noncore/unsupported/mail2/libmail/configfile.cpp b/noncore/unsupported/mail2/libmail/configfile.cpp
index a5c2b49..082b330 100644
--- a/noncore/unsupported/mail2/libmail/configfile.cpp
+++ b/noncore/unsupported/mail2/libmail/configfile.cpp
@@ -73,40 +73,40 @@ void ConfigFile::updateAccount(Account account)
config->writeEntry("DefaultCc", account.defaultCc());
config->writeEntry("DefaultBcc", account.defaultBcc());
config->writeEntry("DefaultReplyTo", account.defaultReplyTo());
config->writeEntry("Cc", account.cc());
config->writeEntry("Bcc", account.bcc());
config->writeEntry("ReplyTo", account.replyTo());
config->writeEntry("Signature", account.signature().replace(QRegExp("\\n"), "<br>"));
config->write();
}
void ConfigFile::deleteAccount(Account account)
{
QFile f((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName());
f.remove();
}
void ConfigFile::checkDirectory()
{
if (!QDir((QString) getenv("HOME") + "/Applications/mail/accounts").exists()) {
system("mkdir -p $HOME/Applications/mail/accounts");
qWarning("mail: $HOME/Applications/mail/accounts created");
}
}
QString ConfigFile::rot13(const QString &input)
{
QString i = input;
int l = i.length();
while(l--) {
if (i[l] >= QChar('A') && i[l] <= QChar('M') ||
i[l] >= QChar('a') && i[l] <= QChar('m'))
- i[l] = (char)((int)QChar(l[i])+13);
+ i[l] = QChar(i[l].unicode()+13);
else if (i[l] >= QChar('N') && i[l] <= QChar('Z') ||
i[l] >= QChar('n') && i[l] <= QChar('z'))
- i[l] = (char)((int)QChar(l[i])-13);
+ i[l] = QChar(i[l].unicode()-13);
}
return i;
}
diff --git a/noncore/unsupported/mail2/libmail/imapbase.cpp b/noncore/unsupported/mail2/libmail/imapbase.cpp
index 9a2ba47..4753f43 100644
--- a/noncore/unsupported/mail2/libmail/imapbase.cpp
+++ b/noncore/unsupported/mail2/libmail/imapbase.cpp
@@ -24,87 +24,109 @@ IMAPBase::IMAPBase(const Account &account)
void IMAPBase::sendCommand(const QString &command)
{
if (!_connected) makeConnect();
_commandQueue.append(command);
}
void IMAPBase::disconnect()
{
_connected = false;
delete _socket;
emit disconnected();
}
void IMAPBase::makeConnect()
{
emit lookingUpHost();
if (_socket == NULL) _socket = new QSocket(this);
Q_UINT16 port = _account.imapPort().toUInt();
_socket->connectToHost(_account.imapServer(), port);
}
void IMAPBase::writeCommands()
{
if (!_connected) return;
if (_commandQueue.isEmpty()) return;
if (!_writingAllowed) return;
QStringList::Iterator it;
for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) {
if (!(*it).isEmpty() && _writingAllowed) {
#ifndef QT_NO_DEBUG
- qDebug("IMAP > " + (*it).stripWhiteSpace());
+ qDebug("IMAP > " + (*it).stripWhiteSpace().local8Bit ());
#endif
_socket->writeBlock((*it).latin1(), (*it).length());
_writingAllowed = false;
+ if (( *it ). find ( QRegExp ( "^[a-z][0-9]+ " )) == 0 )
+ _lasttag = (*it).left(2);
+
+ connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable()));
_commandQueue.remove(it);
break;
}
}
}
void IMAPBase::slotError(int err)
{
if (err == QSocket::ErrConnectionRefused) {
emit error(IMAPErrConnectionRefused);
} else if (err == QSocket::ErrHostNotFound) {
emit error(IMAPErrHostNotFound);
} else if (err == QSocket::ErrSocketRead) {
emit error(IMAPErrSocketRead);
} else {
emit error(IMAPErrUnknownError);
}
}
void IMAPBase::slotHostFound()
{
emit hostFound();
}
void IMAPBase::slotConnected()
{
_connected = true;
emit connected();
}
void IMAPBase::slotDisconnected()
{
_connected = false;
emit disconnected();
}
+#include <unistd.h>
+
void IMAPBase::slotDataAvailiable()
{
+ static bool firstline = true;
+
while (_socket->canReadLine()) {
- _data += _socket->readLine();
- if (_socket->atEnd()) {
-#ifndef QT_NO_DEBUG
- qDebug("IMAP < " + _data.stripWhiteSpace());
-#endif
+ QString tmp = _socket-> readLine ( );
+
+ _data += tmp;
+ qDebug ( "New Line [%d]: '%s'\n", _connected ? 1 : 0, tmp.latin1( ));
+
+ if ( firstline || tmp. left(2) == _lasttag ) {
+ firstline = false;
+
+// if ( _socket-> atEnd ( ))
+ qDebug ( "at end -> emitting\n" );
+
+ QObject::disconnect(_socket, SIGNAL(readyRead()), this, SLOT(slotDataAvailiable()));
emit dataReceived(_data);
+ _data = QString::null;
_writingAllowed = true;
- _data = QString(0);
}
}
}
+void IMAPBase::tryRead ( QString &data )
+{
+ qDebug ( "Trying to read...\n" );
+
+ while ( _socket-> canReadLine ( ))
+ data += _socket-> readLine ( );
+}
diff --git a/noncore/unsupported/mail2/libmail/imapbase.h b/noncore/unsupported/mail2/libmail/imapbase.h
index e4a0b97..7697ffe 100644
--- a/noncore/unsupported/mail2/libmail/imapbase.h
+++ b/noncore/unsupported/mail2/libmail/imapbase.h
@@ -10,43 +10,44 @@ class QSocket;
class IMAPBase : public QObject
{
Q_OBJECT
public:
IMAPBase(const Account &account);
enum Error { IMAPErrConnectionRefused, IMAPErrHostNotFound,
IMAPErrSocketRead, IMAPErrUnknownError,
IMAPErrLoginFailed };
void sendCommand(const QString &command);
void disconnect();
signals:
void dataReceived(const QString &data);
void lookingUpHost();
void hostFound();
void connected();
void disconnected();
void error(int err);
protected:
void makeConnect();
protected slots:
void writeCommands();
void slotError(int error);
void slotHostFound();
void slotConnected();
void slotDisconnected();
void slotDataAvailiable();
+ void tryRead ( QString & );
private:
Account _account;
QString _data;
QSocket *_socket;
QStringList _commandQueue;
bool _connected, _writingAllowed;
-
+ QString _lasttag;
};
#endif
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp
index 7493240..dc97b28 100644
--- a/noncore/unsupported/mail2/libmail/imaphandler.cpp
+++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp
@@ -269,69 +269,72 @@ QString IMAPHandler::iUid(const QString &command, const QString &arguments)
QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments)
{
doLogin();
_ibase->sendCommand(QString("%1 X%2 %3\r\n")
.arg(tag())
.arg(commandAtom)
.arg(arguments));
return tag(false);
}
QString IMAPHandler::escape(const QString &in)
{
QString in_ = in;
return in_.replace(QRegExp("\""), "\\\"");
}
QString IMAPHandler::tag(bool count)
{
return QString("a%1").arg(count ? _tag++ : _tag);
}
void IMAPHandler::slotDataReceived(const QString &data)
{
if (!_ready) {
// The first data is always the greeting string.
// We can ignore it.
_ready = true;
return;
}
- IMAPResponseParser parser(data);
+ IMAPResponseParser parser;
+// connect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & )));
+ parser. parse ( data );
IMAPResponse response = parser.response();
+// disconnect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & )));
response.setImapHandler(this);
- if (!_loggingin) emit gotResponse(response);
+ if (!_loggingin) { qDebug("Emitting gotResponse!\n" ); emit gotResponse(response); }
else {
if (response.statusResponse().status() == IMAPResponseEnums::OK) {
_loggingin = false;
_loggedin = true;
qWarning("OK. Logged in. Leaving loggingin state.");
} else {
_loggingin = false;
emit IMAPError(IMAPBase::IMAPErrLoginFailed);
}
}
}
void IMAPHandler::slotLookingUpHost()
{
emit IMAPLookingUpHost();
}
void IMAPHandler::slotHostFound()
{
emit IMAPHostFound();
}
void IMAPHandler::slotConnected()
{
emit IMAPConnected();
}
void IMAPHandler::slotDisconnected()
{
_loggedin = false;
emit IMAPDisconnected();
}
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.cpp b/noncore/unsupported/mail2/libmail/imapresponse.cpp
index 06dca33..ce5b18b 100644
--- a/noncore/unsupported/mail2/libmail/imapresponse.cpp
+++ b/noncore/unsupported/mail2/libmail/imapresponse.cpp
@@ -1,107 +1,142 @@
#include "imapresponse.h"
-static QString _previousData;
-static unsigned int _neededData;
-IMAPResponseParser::IMAPResponseParser(const QString &data)
+IMAPResponseParser::IMAPResponseParser()
+{
+}
+
+void IMAPResponseParser::parse ( const QString &_data )
{
- QString _data = data, more;
- _data.replace((QString)"\r\n", "\n");
-
- QStringList lines = QStringList::split('\n', _data);
- QStringList::Iterator it;
- for (it = lines.begin(); it != lines.end(); it++) {
- QString tag, lineData;
-
- if (!_previousData.isNull()) {
- qDebug(QString("IMAPResponseParser: got additional data. (%1/%2)").arg(_previousData.length()).arg(_neededData));
- _previousData += *it + "\n";
- if (_previousData.length() >= _neededData) {
- _previousData += ")";
- qDebug("IMAPResponseParser: got ALL additional data.");
- qDebug("Data is: " + _previousData);
- parseResponse(_previousData);
- _previousData = QString(0);
- _neededData = 0;
- }
- } else {
- splitTagData(*it, tag, lineData);
- if (tag == "*") {
- int pos;
- if ((pos = data.find(QRegExp("\\{\\d*\\}"))) != -1) {
- qDebug("IMAPResponseParser: waiting for additional data...");
- _previousData = lineData + "\n";
-
- QString tmp = data.right(data.length() - pos - 1).stripWhiteSpace();
- tmp.truncate(tmp.length() - 1);
-
- _neededData = tmp.toUInt();
- if (_previousData.length() >= _neededData) {
- qDebug("IMAPResponseParser: got ALL additional data. (1st)");
- parseResponse(_previousData);
- _previousData = QString(0);
- _neededData = 0;
- } else {
+ QString data = _data;
+
+ int pos = 0;
+ int len = data. length ( );
+
+
+ while ( pos < len ) {
+ pos = data. find ( QRegExp ( "[^\\s]" ), pos );
+
+ if (( pos < 0 ) || ( pos >= len ))
+ break;
+
+ switch ( data [pos]. latin1 ( )) {
+ case '*': {
+ qDebug ( "* ASTERIX\n" );
+
+ int eol = data. find ( '\n', pos );
+ int bracket = data. findRev ( '{', eol );
+ int rest = data. find ( QRegExp ( "[^\\s]" ), pos + 1 );
+
+ qDebug ( "pos=%d, rest=%d, bracket=%d, eol=%d\n", pos, rest, bracket, eol );
+
+ if ( bracket > pos ) {
+ uint needdata = data. mid ( bracket + 1, data. find ( '}', bracket + 1 ) - bracket - 1 ). toUInt ( );
+
+ if ( needdata ) {
+ qDebug ( "nd=%d - hd=%d\n", needdata, ( len - eol - 1 ));
+
+ while ( needdata > ( len - eol - 1 )) {
+ qDebug ( "emitting need more...\n" );
+ emit needMoreData ( data );
+ len = data. length ( );
+ }
+ qDebug ( "Got all data...\n" );
+
+ QString tmp = data. mid ( rest, eol - rest + 1 + needdata );
+
+ int tail = 0;
+
+ while ( data [eol - rest + 1 + needdata + tail] != ')' )
+ tail++;
+ tmp. append ( data. mid ( eol - rest + 1 + needdata, tail + 1 ));
+
+
+ qDebug ( "Complete parse = |%s|\n", tmp.latin1());
+
+ parseResponse ( tmp );
+
+ pos = rest + needdata + tail + 1;
break;
- }
- } else {
- parseResponse(lineData);
+ }
}
- } else if (tag == "+") {
- emit needMoreData(_data);
- } else {
- _iresponse.setTag(tag);
- parseResponse(_data, true);
+
+ parseResponse ( data. mid ( rest, eol - rest + 1 ). stripWhiteSpace ( ));
+ break;
+ }
+ case '+': {
+ qDebug ( "+ PLUS\n" );
+
+ emit needMoreData ( data );
+ len = data. length ( );
+ break;
+ }
+ default : {
+ qDebug ( "OTHER: '%s...'\n", data. mid ( pos, 20 ). latin1 ( ));
+
+ uint rest = data. find ( ' ', pos + 1 );
+ rest = data. find ( QRegExp ( "[^\\s]" ), rest + 1 );
+ _iresponse. setTag ( data. mid ( pos, rest - pos ). stripWhiteSpace ( ));
+ parseResponse ( data. mid ( rest, data. find ( '\n', rest )). stripWhiteSpace ( ), true );
+ break;
}
}
+
+ // skip to end-of-line
+ while (( pos < len ) && ( data [pos] != '\n' ))
+ pos++;
}
}
+
IMAPResponse IMAPResponseParser::response()
{
return _iresponse;
}
void IMAPResponseParser::parseResponse(const QString &data, bool tagged)
{
QString response, line;
int pos;
bool isNum = false;
+
+
+// qDebug ( "\n\n#### PRD #### : #%s#\n\n", data.latin1());
+
if ((pos = data.find(' ')) != -1) {
response = data.left(pos).upper();
response.toInt(&isNum);
line = data.right(data.length() - pos - 1);
} else {
- qWarning("IMAPResponseParser: parseResponse: No response found.");
+ qWarning("IMAPResponseParser: parseResponse: No response found.");
return;
}
if (response == "OK" && tagged) {
IMAPResponseStatusResponse status(OK, line);
status.setResponseCode(getResponseCode(status.comment()));
_iresponse.setStatusResponse(status);
} else if (response == "OK" && !tagged) {
IMAPResponseOK ok(line, getResponseCode(line));
_iresponse.addOK(ok);
} else if (response == "NO" && tagged) {
IMAPResponseStatusResponse status(NO, line);
status.setResponseCode(getResponseCode(status.comment()));
_iresponse.setStatusResponse(status);
} else if (response == "NO" && !tagged) {
IMAPResponseNO no(line, getResponseCode(line));
_iresponse.addNO(no);
} else if (response == "BAD" && tagged) {
IMAPResponseStatusResponse status(BAD, line);
status.setResponseCode(getResponseCode(status.comment()));
_iresponse.setStatusResponse(status);
} else if (response == "BAD" && !tagged) {
IMAPResponseBAD bad(line, getResponseCode(line));
_iresponse.addBAD(bad);
} else if (response == "PREAUTH" && tagged) {
IMAPResponseStatusResponse status(PREAUTH, line);
_iresponse.setStatusResponse(status);
} else if (response == "PREAUTH" && !tagged) {
qDebug("IMAPResponseParser: responseParser: got untagged PREAUTH response.");
// XXX
} else if (response == "BYE") {
IMAPResponseStatusResponse status(BYE, line);
@@ -116,118 +151,129 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged)
QStringList flags;
parseParenthesizedList(list[0], flags);
removeLimiters(list[1]);
removeLimiters(list[2]);
IMAPResponseLIST rlist(parseFlagList(flags), list[1], list[2]);
_iresponse.addLIST(rlist);
} else if (response == "LSUB") {
QStringList list = splitData(line, true);
QStringList flags;
parseParenthesizedList(list[0], flags);
removeLimiters(list[1]);
removeLimiters(list[2]);
IMAPResponseLSUB lsub(parseFlagList(flags), list[1], list[2]);
_iresponse.addLSUB(lsub);
} else if (response == "STATUS") {
QStringList list = splitData(line, true);
removeLimiters(list[0]);
IMAPResponseSTATUS status(list[0]);
QStringList flags;
parseParenthesizedList(list[1], flags);
QStringList::Iterator it;
for (it = flags.begin(); it != flags.end(); it++) {
if (*it == "MESSAGES") status.setMessages(*(++it));
else if (*it == "RECENT") status.setRecent(*(++it));
else if (*it == "UIDNEXT") status.setUidnext(*(++it));
else if (*it == "UIDVALIDITY") status.setUidvalidity(*(++it));
else if (*it == "UNSEEN") status.setUnseen(*(++it));
- else qWarning("IMAPResponseParser: parseResponse: Unknown status data: " + *(it++) + "|");
+ else qWarning((QString("IMAPResponseParser: parseResponse: Unknown status data: " )+ *(it++) + "|").latin1());
}
_iresponse.addSTATUS(status);
} else if (response == "SEARCH") {
IMAPResponseSEARCH search(QStringList::split(' ', line));
_iresponse.addSEARCH(search);
} else if (response == "FLAGS") {
QStringList list;
parseParenthesizedList(line, list);
IMAPResponseFLAGS flags(parseFlagList(list));
_iresponse.addFLAGS(flags);
} else if (isNum) {
QStringList list = QStringList::split(' ', line);
if (list[0] == "EXISTS") {
IMAPResponseEXISTS exists(response);
_iresponse.addEXISTS(exists);
} else if (list[0] == "RECENT") {
IMAPResponseRECENT recent(response);
_iresponse.addRECENT(recent);
} else if (list[0] == "EXPUNGE") {
IMAPResponseEXPUNGE expunge(response);
_iresponse.addEXPUNGE(expunge);
} else if (list[0] == "FETCH") {
IMAPResponseFETCH fetch;
QStringList::Iterator it;
+ qDebug ( "Got FETCH\n" );
+
QStringList fetchList = splitData(line, true);
QStringList list;
+
+ qDebug ( "fl [0]=%s, fl [1]=%s, fl[2]=%s\n", fetchList[0].latin1(),fetchList[1].latin1(),fetchList[2].latin1());
+
parseParenthesizedList(fetchList[1], list);
for (it = list.begin(); it != list.end(); it++) {
+ qDebug ( "Checking list[] == %s\n", (*it).latin1());
+
if (*it == "BODY") {
qDebug("IMAPResponseParser: responseParser: got FETCH::BODY");
// XXX
- } else if ((*it).find(QRegExp("BODY\\[\\d+\\]")) != -1) {
- QString bodydata = *(++it);
+ } else if ((*it).find(QRegExp("^BODY\\[\\d+\\]")) != -1) {
qDebug("IMAPResponseParser: responseParser: got FETCH::BODY[x]");
- QStringList blist;
- parseParenthesizedList(bodydata, blist);
+ QString number = ( *it ). mid ( 5, ( *it ). length ( ) - 6 );
+ QString bodydata = *(++it);
+
+// QStringList blist;
+// parseParenthesizedList(bodydata, blist);
IMAPResponseBodyPart bodypart;
- QString tmp;
- for (unsigned int i = 2; i < blist.count(); i++) {
- if (i != 2) tmp += " " + blist[i];
- else tmp += blist[i];
- }
- bodypart.setData(tmp);
+// QString tmp;
+// for (unsigned int i = 2; i < blist.count(); i++) {
+// if (i != 2) tmp += " " + blist[i];
+// else tmp += blist[i];
+// }
+ bodypart.setData(bodydata);
+
+// QString tmp = list[0];
+// tmp.replace(0, 5, "");
+// tmp.truncate(blist[0].length() - 1);
+ bodypart.setPart(number);
- tmp = list[0];
- tmp.replace(0, 5, "");
- tmp.truncate(blist[0].length() - 1);
- bodypart.setPart(tmp);
+ qDebug("added bodypart [%s]: '%s'\n\n", number.latin1(), bodydata.latin1());
fetch.addBodyPart(bodypart);
} else if (*it == "BODYSTRUCTURE") {
qDebug("IMAPResponseParser: responseParser: got FETCH::BODYSTRUCTURE");
/*
QString bsdata = *(++it);
QStringList bsList;
parseParenthesizedList(bsdata, bsList);
IMAPResponseBodystructure bodystructure;
QStringList attachml;
for (int i = 0; i < bsList.count() - 1; i++) {
parseParenthesizedList(bsList[0], attachml);
IMAPResponseBodypart bodypart;
bodypart.setMimeTypeMain(attachml[0] == "NIL" ? QString(0) : attachml[0]);
bodypart.setMimeTypeSub(attachml[1] == "NIL" ? QString(0) : attachml[1]);
bodypart.setAddData(attachml[2] == "NIL" ? QString(0) : attachml[2]);
// 3 (NIL)
// 4 (NIL)
bodypart.setEncoding(attachml[5] == "NIL" ? QString(0) : attachml[5]);
bodypart.setSize(attachml[6] == "NIL" ? QString(0) : attachml[6]);
bodypart.setLength(attachml[7] == "NIL" ? QString(0) : attachml[7]);
bodypart.setAttachInfo(attachml[8] == "NIL" ? QString(0) : attachml[8]);
// 9 (NIL)
// 10 (NIL)
bodystructure.addBodyPart(bodypart);
}
*/
} else if (*it == "ENVELOPE") {
@@ -308,141 +354,173 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged)
removeLimiters(bcca[2]),
removeLimiters(bcca[3])));
}
envelope.setInReplyTo(envList[7] == "NIL" ? QString(0) : removeLimiters(envList[7]));
envelope.setMessageId(envList[8] == "NIL" ? QString(0) : removeLimiters(envList[8]));
fetch.setEnvelope(envelope);
} else if (*it == "FLAGS") {
QString flagdata = *(++it);
QStringList flags;
parseParenthesizedList(flagdata, flags);
fetch.setFlags(parseFlagList(flags));
} else if (*it == "INTERNALDATE") {
fetch.setInternalDate(removeLimiters(*(++it)));
} else if (*it == "RFC822" || *it == "BODY[]") {
qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822");
// XXX
} else if (*it == "RFC822.HEADER" || *it == "BODY.PEEK[HEADER]") {
qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.HEADER");
// XXX
} else if (*it == "RFC822.SIZE") {
fetch.setRFC822Size(*(++it));
} else if (*it == "RFC822.TEXT" || *it == "BODY[TEXT]") {
qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.TEXT");
// XXX
} else if (*it == "UID") {
fetch.setUid(*(++it));
}
}
_iresponse.addFETCH(fetch);
}
- } else qWarning("IMAPResponseParser: parseResponse: Unknown response: " + response + "|");
+ } else qWarning((QString("IMAPResponseParser: parseResponse: Unknown response: ") + response + "|").latin1());
+
}
QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets)
{
int b = 0;
bool a = false, noappend = false, escaped = false;
QString temp;
QStringList list;
+ qDebug ( "sd: '%s'\n", data.latin1());
+
for (unsigned int i = 0; i <= data.length(); i++) {
if (withBrackets && data[i] == '(' && !a) b++;
else if (withBrackets && data[i] == ')' && !a) b--;
- if (data[i] == '"' && !escaped) a = !a;
+ if (data[i] == '{' && !escaped && !a ) {
+ qDebug ( "sd: found a {\n" );
+
+ int p = data. find ( '}', i + 1 );
+ int eol = data. find ( '\n', i + 1 );
+
+ if ( p > int( i )) {
+ int len = data. mid ( i + 1, p - i - 1 ). toInt ( );
+
+ qDebug ( "sd: skipping %d bytes\n", len );
+
+ if ( b == 0 ) {
+ temp = data. mid ( eol + 1, len );
+ noappend = false;
+ i = eol + len;
+ continue;
+ }
+ else {
+ temp. append ( '{' );
+ temp. append ( QString::number ( len ));
+ temp. append ( "}\r\n" );
+ temp. append ( data. mid ( eol + 1, len ));
+ i = eol + len;
+ continue;
+ }
+ }
+ }
+
+ if (data[i] == '\"' && !escaped) a = !a;
else escaped = false;
- if (data[i] == '\\' && data[i + 1] == '"') escaped = true;
+ if (data[i] == '\\' && data[i + 1] == '\"') escaped = true;
if ((data[i] == ' ' || i == data.length()) && b == 0 && !a) {
list.append(temp);
- temp = QString(0);
+ temp = QString::null;
if (data[i] == ' ') noappend = true;
}
if (!noappend) temp += data[i];
noappend = false;
}
return list;
}
void IMAPResponseParser::parseParenthesizedList(const QString &data, QStringList &parsed)
{
QString data_(data);
removeLimiters(data_, '(', ')');
parsed = splitData(data_, true);
}
void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString &data)
{
int pos;
if ((pos = line.find(' ')) != -1) {
tag = line.left(pos);
data = line.right(line.length() - pos - 1);
- } else qWarning("IMAPResponseParser: splitTagData: tag not found. Line was " + line + "|");
+ } else qWarning((QString("IMAPResponseParser: splitTagData: tag not found. Line was ") + line + "|").latin1());
}
QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el)
{
QString tmpString;
+ string = string. stripWhiteSpace ( );
+
if (string[0] == sl && string[string.length() - 1] == el) {
string.truncate(string.length() - 1);
string.replace(0, 1, "");
for (unsigned int i = 1; i <= string.length(); i++) {
- if (string[i - 1] == '\\' && sl == '"') ++i;
+ if (string[i - 1] == '\\' && sl == '\"') ++i;
tmpString += string[i - 1];
}
}
-
return tmpString;
}
IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QString &line)
{
if (line.find(QRegExp((QString) "^\\[.*\\]" + ' ' + ".*")) != -1) {
int pos = line.find("] ");
QString code = line.left(pos + 1).upper();
if (code.find(QRegExp("[ALERT]")) != -1) return ALERT;
else if (code.find(QRegExp("[NEWNAME .* .*]")) != -1) return NEWNAME; // XXX
else if (code.find(QRegExp("[PARSE]")) != -1) return PARSE;
else if (code.find(QRegExp("[PERMANENTFLAGS \\d*]")) != -1) return PERMANENTFLAGS; // XXX
else if (code.find(QRegExp("[READ-ONLY]")) != -1) return READONLY;
else if (code.find(QRegExp("[READ-WRITE]")) != -1) return READWRITE;
else if (code.find(QRegExp("[TRYCREATE]")) != -1) return TRYCREATE;
else if (code.find(QRegExp("[UIDVALIDITY \\d*]")) != -1) return UIDVALIDITY; // XXX
else if (code.find(QRegExp("[UNSEEN \\d*]")) != -1) return UNSEEN; // XXX
else {
- qWarning("IMAPResponseParser: getResponseCode: Unknown code: " + code + "|");
+ qWarning((QString("IMAPResponseParser: getResponseCode: Unknown code: ") + code + "|").latin1());
return UnknownCode;
}
}
return NoCode;
}
QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagList(const QStringList &flagList)
{
QValueList<IMAPResponseFlags> flags;
QStringList::ConstIterator it;
for (it = flagList.begin(); it != flagList.end(); it++) {
QString flag = (*it).lower();
if (flag == "\\seen") flags.append(Seen);
else if (flag == "\\answered") flags.append(Answered);
else if (flag == "\\flagged") flags.append(Flagged);
else if (flag == "\\deleted") flags.append(Deleted);
else if (flag == "\\draft") flags.append(Draft);
else if (flag == "\\recent") flags.append(Recent);
else if (flag == "\\noinferiors") flags.append(Noinferiors);
else if (flag == "\\noselect") flags.append(Noselect);
else if (flag == "\\marked") flags.append(Marked);
else if (flag == "\\unmarked") flags.append(Unmarked);
else if (flag.isEmpty()) { }
- else qWarning("IMAPResponseParser: parseFlagList: Unknown flag: " + *it + "|");
+ else qWarning((QString("IMAPResponseParser: parseFlagList: Unknown flag: ") + *it + "|").latin1());
}
return flags;
}
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.h b/noncore/unsupported/mail2/libmail/imapresponse.h
index 73435ee..5a19b96 100644
--- a/noncore/unsupported/mail2/libmail/imapresponse.h
+++ b/noncore/unsupported/mail2/libmail/imapresponse.h
@@ -476,56 +476,57 @@ public:
QValueList<IMAPResponseEXISTS> EXISTS() { return _existsl; }
QValueList<IMAPResponseRECENT> RECENT() { return _recentl; }
QValueList<IMAPResponseEXPUNGE> EXPUNGE() { return _expungel; }
QValueList<IMAPResponseFETCH> FETCH() { return _fetchl; }
private:
QString _tag;
IMAPResponseStatusResponse _response;
IMAPHandler *_handler;
QValueList<IMAPResponseOK> _okl;
QValueList<IMAPResponseNO> _nol;
QValueList<IMAPResponseBAD> _badl;
QValueList<IMAPResponseCAPABILITY> _capabilityl;
QValueList<IMAPResponseLIST> _listl;
QValueList<IMAPResponseLSUB> _lsubl;
QValueList<IMAPResponseSTATUS> _statusl;
QValueList<IMAPResponseSEARCH> _searchl;
QValueList<IMAPResponseFLAGS> _flagsl;
QValueList<IMAPResponseEXISTS> _existsl;
QValueList<IMAPResponseRECENT> _recentl;
QValueList<IMAPResponseEXPUNGE> _expungel;
QValueList<IMAPResponseFETCH> _fetchl;
};
class IMAPResponseParser : public QObject, public IMAPResponseEnums
{
Q_OBJECT
public:
- IMAPResponseParser(const QString &data);
+ IMAPResponseParser();
+ void parse ( const QString &data);
IMAPResponse response();
signals:
- void needMoreData(const QString &comment);
+ void needMoreData(QString &data);
protected:
void parseResponse(const QString &data, bool tagged = false);
QStringList splitData(const QString &data, bool withBrackets);
void parseParenthesizedList(const QString &data, QStringList &parsed);
void splitTagData(const QString &line, QString &tag, QString &data);
QString removeLimiters(QString &string, const QChar &sl = '"', const QChar &el = '"');
IMAPResponseCode getResponseCode(const QString &line);
QValueList<IMAPResponseFlags> parseFlagList(const QStringList &flags);
private:
IMAPResponse _iresponse;
};
#endif
diff --git a/noncore/unsupported/mail2/viewmail.cpp b/noncore/unsupported/mail2/viewmail.cpp
index 3c88d99..da6924d 100644
--- a/noncore/unsupported/mail2/viewmail.cpp
+++ b/noncore/unsupported/mail2/viewmail.cpp
@@ -154,45 +154,45 @@ void ViewMail::slotForward()
.arg(_mail.envelope().to().toString());
if (!_mail.envelope().cc().toString().isNull())
ftext += QString("Cc: %1\n")
.arg(_mail.envelope().cc().toString());
if (!_mail.envelope().bcc().toString().isNull())
ftext += QString("Bcc: %1\n")
.arg(_mail.envelope().bcc().toString());
if (!_mail.envelope().subject().isNull())
ftext += QString("Subject: %1\n")
.arg(_mail.envelope().subject());
ftext += QString("\n%1\n")
.arg(_mail.bodyPart(1).data());
ftext += QString("----- End forwarded message -----\n");
SendMail sendMail;
sendMail.setSubject("Fwd: " + _mail.envelope().subject());
sendMail.setMessage(ftext);
Composer composer(this, 0, true);
composer.setSendMail(sendMail);
composer.showMaximized();
composer.exec();
}
void ViewMail::slotIMAPUid(IMAPResponse &response)
{
disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &)));
if (response.statusResponse().status() == IMAPResponseEnums::OK) {
QValueList<IMAPResponseBodyPart> bodyParts;
- bodyParts.append(response.FETCH()[0].bodyPart(1));
+ bodyParts.append(response.FETCH()[0].bodyPart(0));
_mail.setBodyParts(bodyParts);
- browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(1).data())));
+ browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(0).data())));
// fillList(response.FETCH()[0].bodyStructure());
_gotBody = true;
} else {
QMessageBox::warning(this, tr("Error"), tr("<p>I was unable to retrieve the mail from the server. You can try again later or give up.</p>"), tr("Ok"));
}
}