author | conber <conber> | 2002-06-15 09:46:14 (UTC) |
---|---|---|
committer | conber <conber> | 2002-06-15 09:46:14 (UTC) |
commit | 7f2eef29708380844922f34f59ba4e9beefbf7c3 (patch) (side-by-side diff) | |
tree | f57125fbaabddecc35d6677f1b9e48a4594165d5 /noncore/unsupported/mail2/libmail | |
parent | 0acbdd392814589df303b6e50c79d9822e3db27a (diff) | |
download | opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.zip opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.gz opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.bz2 |
initial checkin
Diffstat (limited to 'noncore/unsupported/mail2/libmail') (more/less context) (show whitespace changes)
21 files changed, 3214 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/libmail/configfile.cpp b/noncore/unsupported/mail2/libmail/configfile.cpp new file mode 100644 index 0000000..a5c2b49 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/configfile.cpp @@ -0,0 +1,112 @@ +#include <qdir.h> + +#include <qpe/config.h> + +#include <stdlib.h> + +#include "configfile.h" + +ConfigFile::ConfigFile() : QObject() +{ + checkDirectory(); + + QDir dir((QString) getenv("HOME") + "/Applications/mail/accounts"); + QStringList entries = dir.entryList("account-*"); + + QStringList::Iterator it; + for (it = entries.begin(); it != entries.end(); it++) { + Account account; + + Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/" + *it, Config::File); + config->setGroup("Account"); + account.setAccountName((*it).replace(0, 8, "")); + account.setRealName(config->readEntry("RealName")); + account.setEmail(config->readEntry("Email")); + account.setOrg(config->readEntry("Organization")); + account.setImapServer(config->readEntry("ImapServer")); + account.setImapPort(config->readEntry("ImapPort")); + account.setSmtpServer(config->readEntry("SmtpServer")); + account.setSmtpPort(config->readEntry("SmtpPort")); + account.setUser(config->readEntry("User")); + account.setPass(rot13(config->readEntryCrypt("Pass"))); + account.setSmtpSsl(config->readBoolEntry("SmtpSsl")); + account.setSmtpSslPort(config->readEntry("SmtpSslPort")); + account.setImapSsl(config->readBoolEntry("ImapSsl")); + account.setImapSslPort(config->readEntry("ImapSslPort")); + account.setDefaultCc(config->readBoolEntry("DefaultCc")); + account.setDefaultBcc(config->readBoolEntry("DefaultBcc")); + account.setDefaultReplyTo(config->readBoolEntry("DefaultReplyTo")); + account.setCc(config->readEntry("Cc")); + account.setBcc(config->readEntry("Bcc")); + account.setReplyTo(config->readEntry("ReplyTo")); + account.setSignature(config->readEntry("Signature").replace(QRegExp("<br>"), "\n")); + + _accounts.append(account); + } +} + +QValueList<Account> ConfigFile::getAccounts() +{ + ConfigFile *configFile = new ConfigFile(); + return configFile->_accounts; +} + +void ConfigFile::updateAccount(Account account) +{ + checkDirectory(); + Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName(), Config::File); + + config->setGroup("Account"); + config->writeEntry("RealName", account.realName()); + config->writeEntry("Email", account.email()); + config->writeEntry("Organization", account.org()); + config->writeEntry("ImapServer", account.imapServer()); + config->writeEntry("ImapPort", account.imapPort()); + config->writeEntry("SmtpServer", account.smtpServer()); + config->writeEntry("SmtpPort", account.smtpPort()); + config->writeEntry("User", account.user()); + config->writeEntryCrypt("Pass", rot13(account.pass())); + config->writeEntry("SmtpSsl", account.smtpSsl()); + config->writeEntry("SmtpSslPort", account.smtpSslPort()); + config->writeEntry("ImapSsl", account.imapSsl()); + config->writeEntry("ImapSslPort", account.imapSslPort()); + 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); + 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); + } + return i; +} + diff --git a/noncore/unsupported/mail2/libmail/configfile.h b/noncore/unsupported/mail2/libmail/configfile.h new file mode 100644 index 0000000..84b57d5 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/configfile.h @@ -0,0 +1,97 @@ +#ifndef CONFIGFILE_H +#define CONFIGFILE_H + +#include <qobject.h> + +class Config; + +class Account +{ +public: + Account() + { + _smtpssl = false; + _imapssl = false; + _dateField = false; + _msgIdField = false; + _defaultCc = false; + _defaultBcc = false; + _defaultRep = false; + } + + void setAccountName(QString accountName) { _accountName = accountName; } + + void setRealName(QString name) { _name = name; } + void setEmail(QString email) { _email = email; } + void setOrg(QString org) { _org = org; } + void setImapServer(QString imapServer) { _imapServer = imapServer; } + void setImapPort(QString imapPort) { _imapPort = imapPort; } + void setSmtpServer(QString smtpServer) { _smtpServer = smtpServer; } + void setSmtpPort(QString smtpPort) { _smtpPort = smtpPort; } + void setUser(QString user) { _user = user; } + void setPass(QString pass) { _pass = pass; } + void setSmtpSsl(bool smtpssl) { _smtpssl = smtpssl; } + void setSmtpSslPort(QString smtpSslPort) { _smtpSslPort = smtpSslPort; } + void setImapSsl(bool imapssl) { _imapssl = imapssl; } + void setImapSslPort(QString imapSslPort) { _imapSslPort = imapSslPort; } + void setDateField(bool dateField) { _dateField = dateField; } + void setMsgIdField(bool msgIdField) { _msgIdField = msgIdField; } + void setDefaultCc(bool defaultCc) { _defaultCc = defaultCc; } + void setDefaultBcc(bool defaultBcc) { _defaultBcc = defaultBcc; } + void setDefaultReplyTo(bool defaultRep) { _defaultRep = defaultRep; } + void setCc(QString cc) { _cc = cc; } + void setBcc(QString bcc) { _bcc = bcc; } + void setReplyTo(QString replyTo) { _replyTo = replyTo; } + void setSignature(QString signature) { _signature = signature; } + + QString accountName() { return _accountName; } + + QString realName() { return _name; } + QString email() { return _email; } + QString org() { return _org; } + QString imapServer() { return _imapServer; } + QString imapPort() { return _imapPort; } + QString smtpServer() { return _smtpServer; } + QString smtpPort() { return _smtpPort; } + QString user() { return _user; } + QString pass() { return _pass; } + bool smtpSsl() { return _smtpssl; } + QString smtpSslPort() { return _smtpSslPort; } + bool imapSsl() { return _imapssl; } + QString imapSslPort() { return _imapSslPort; } + bool dateField() { return _dateField; } + bool msgIdField() { return _msgIdField; } + bool defaultCc() { return _defaultCc; } + bool defaultBcc() { return _defaultBcc; } + bool defaultReplyTo() { return _defaultRep; } + QString cc() { return _cc; } + QString bcc() { return _bcc; } + QString replyTo() { return _replyTo; } + QString signature() { return _signature; } + +private: + QString _accountName, _name, _email, _org, _imapServer, _smtpServer, _user, _pass, _cc, _bcc, _replyTo, _imapPort, _smtpPort, _signature, _smtpSslPort, _imapSslPort; + bool _dateField, _msgIdField, _defaultCc, _defaultBcc, _defaultRep, _smtpssl, _imapssl; + +}; + +class ConfigFile : public QObject +{ + Q_OBJECT + +public: + static QValueList<Account> getAccounts(); + static void updateAccount(Account account); + static void deleteAccount(Account account); + +protected: + static void checkDirectory(); + static QString rot13(const QString &input); + + ConfigFile(); + + QValueList<Account> _accounts; + +}; + +#endif diff --git a/noncore/unsupported/mail2/libmail/defines.h b/noncore/unsupported/mail2/libmail/defines.h new file mode 100644 index 0000000..489cb0e --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/defines.h @@ -0,0 +1,8 @@ +#ifndef DEFINES_H +#define DEFINES_H + +#define VERSION "0.0.9" + +#define USERAGENT "LISAMail/" + VERSION + +#endif diff --git a/noncore/unsupported/mail2/libmail/imapbase.cpp b/noncore/unsupported/mail2/libmail/imapbase.cpp new file mode 100644 index 0000000..9a2ba47 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imapbase.cpp @@ -0,0 +1,110 @@ +#include <qsocket.h> +#include <qtimer.h> + +#include "imapbase.h" + +IMAPBase::IMAPBase(const Account &account) + : QObject(), _account(account) +{ + _connected = false; + _writingAllowed = false; + _socket = new QSocket(this); + + connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable())); + connect(_socket, SIGNAL(hostFound()), SLOT(slotHostFound())); + connect(_socket, SIGNAL(connected()), SLOT(slotConnected())); + connect(_socket, SIGNAL(connectionClosed()), SLOT(slotDisconnected())); + connect(_socket, SIGNAL(error(int)), SLOT(slotError(int))); + + QTimer *commandTimer = new QTimer(this); + commandTimer->start(200); + connect(commandTimer, SIGNAL(timeout()), SLOT(writeCommands())); +} + +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()); +#endif + _socket->writeBlock((*it).latin1(), (*it).length()); + _writingAllowed = false; + _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(); +} + +void IMAPBase::slotDataAvailiable() +{ + while (_socket->canReadLine()) { + _data += _socket->readLine(); + if (_socket->atEnd()) { +#ifndef QT_NO_DEBUG + qDebug("IMAP < " + _data.stripWhiteSpace()); +#endif + emit dataReceived(_data); + _writingAllowed = true; + _data = QString(0); + } + } +} + diff --git a/noncore/unsupported/mail2/libmail/imapbase.h b/noncore/unsupported/mail2/libmail/imapbase.h new file mode 100644 index 0000000..e4a0b97 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imapbase.h @@ -0,0 +1,52 @@ +#ifndef IMAPBASE_H +#define IMAPBASE_H + +#include <qobject.h> + +#include "configfile.h" + +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(); + +private: + Account _account; + QString _data; + QSocket *_socket; + QStringList _commandQueue; + bool _connected, _writingAllowed; + +}; + +#endif diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp new file mode 100644 index 0000000..66c92c5 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp @@ -0,0 +1,334 @@ +#include "imapresponse.h" +#include "imaphandler.h" +#include "imapbase.h" + +IMAPHandler::IMAPHandler(const Account &account) + : QObject(), _account(account) +{ + _loggingin = false; + _loggedin = false; + _tag = 0; + _ibase = new IMAPBase(account); + + connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &))); + connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost())); + connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound())); + connect(_ibase, SIGNAL(connected()), SLOT(slotConnected())); + connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected())); + connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int))); +} + +void IMAPHandler::doLogin() +{ + if (_loggedin) return; + if (_loggingin) return; + + _loggingin = true; + iLogin(_account.user(), _account.pass()); +} + +QString IMAPHandler::iCapability() +{ + _ibase->sendCommand(QString("%1 CAPABILITY\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iNoop() +{ + _ibase->sendCommand(QString("%1 NOOP\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iLogout() +{ + _ibase->sendCommand(QString("%1 LOGOUT\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iAuthenticate(const QString &mechanism) +{ + _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mechanism))); + return tag(false); +} + +QString IMAPHandler::iLogin(const QString &user, const QString &pass) +{ + _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n") + .arg(tag()) + .arg(escape(user)) + .arg(escape(pass))); + return tag(false); +} + +QString IMAPHandler::iSelect(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iExamine(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iCreate(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iDelete(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 RENAME \"%2\" \"%3\"\r\n") + .arg(tag()) + .arg(escape(mailbox)) + .arg(escape(newMailbox))); + return tag(false); +} + +QString IMAPHandler::iSubscribe(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 SUBSCRIBE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iUnsubscribe(const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 UNSUBSCRIBE \"%2\"\r\n") + .arg(tag()) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iList(const QString &reference, const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 LIST \"%2\" \"%3\"\r\n") + .arg(tag()) + .arg(escape(reference)) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iLsub(const QString &reference, const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 LSUB \"%2\" \"%3\"\r\n") + .arg(tag()) + .arg(escape(reference)) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iStatus(const QString &mailbox, const QString &items) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 STATUS \"%2\" (%3)\r\n") + .arg(tag()) + .arg(escape(mailbox)) + .arg(escape(items))); + return tag(false); +} + +QString IMAPHandler::iAppend(const QString &mailbox, const QString &literal, const QString &flags, const QString &datetime = 0) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 APPEND \"%2\" (%3) \"%4\" {%5}\r\n%6\r\n") + .arg(tag()) + .arg(escape(mailbox)) + .arg(flags) + .arg(escape(datetime)) + .arg(literal.length()) + .arg(literal)); + return tag(false); +} + +QString IMAPHandler::iCheck() +{ + doLogin(); + + _ibase->sendCommand(QString("%1 CHECK\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iClose() +{ + doLogin(); + + _ibase->sendCommand(QString("%1 CLOSE\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iExpunge() +{ + doLogin(); + + _ibase->sendCommand(QString("%1 EXPUNGE\r\n") + .arg(tag())); + return tag(false); +} + +QString IMAPHandler::iSearch(const QString &search, const QString &charset) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n") + .arg(tag()) + .arg(charset.isEmpty() ? QString(0) : escape(charset)) + .arg(search)); + return tag(false); +} + +QString IMAPHandler::iFetch(const QString &message, const QString &items) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n") + .arg(tag()) + .arg(message) + .arg(items)); + return tag(false); +} + +QString IMAPHandler::iStore(const QString &message, const QString &items) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 STORE %2 %3\r\n") + .arg(tag()) + .arg(message) + .arg(items)); + return tag(false); +} + +QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n") + .arg(tag()) + .arg(message) + .arg(escape(mailbox))); + return tag(false); +} + +QString IMAPHandler::iUid(const QString &command, const QString &arguments) +{ + doLogin(); + + _ibase->sendCommand(QString("%1 UID %2 %3\r\n") + .arg(tag()) + .arg(command) + .arg(arguments)); + return tag(false); +} + +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) +{ + IMAPResponseParser parser(data); + IMAPResponse response = parser.response(); + response.setImapHandler(this); + + if (!_loggingin) 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(); +} + +void IMAPHandler::slotError(int err) +{ + emit IMAPError(err); +} + diff --git a/noncore/unsupported/mail2/libmail/imaphandler.h b/noncore/unsupported/mail2/libmail/imaphandler.h new file mode 100644 index 0000000..8cb42db --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imaphandler.h @@ -0,0 +1,86 @@ +#ifndef IMAPHANDLER_H +#define IMAPHANDLER_H + +#include <qobject.h> + +#include "configfile.h" + +class IMAPBase; +class IMAPResponse; + +class IMAPHandler : public QObject +{ + Q_OBJECT + +public: + IMAPHandler(const Account &account); + + QString iCapability(); + QString iNoop(); + QString iLogout(); + + QString iAuthenticate(const QString &mechanism); + QString iLogin(const QString &user, const QString &pass); + + QString iSelect(const QString &mailbox); + QString iExamine(const QString &mailbox); + QString iCreate(const QString &mailbox); + QString iDelete(const QString &mailbox); + QString iRename(const QString &mailbox, const QString &newMailbox); + + QString iSubscribe(const QString &mailbox); + QString iUnsubscribe(const QString &mailbox); + + QString iList(const QString &reference, const QString &mailbox); + QString iLsub(const QString &reference, const QString &mailbox); + + QString iStatus(const QString &mailbox, const QString &items); + + QString iAppend(const QString &mailbox, const QString &literal, const QString &flags = 0, const QString &datetime = 0); + + QString iCheck(); + QString iClose(); + QString iExpunge(); + + QString iSearch(const QString &search, const QString &charset = 0); + + QString iFetch(const QString &message, const QString &items); + + QString iStore(const QString &message, const QString &items); + QString iCopy(const QString &message, const QString &mailbox); + + QString iUid(const QString &command, const QString &arguments); + + QString iX(const QString &commandAtom, const QString &arguments); + +signals: + void gotResponse(IMAPResponse &response); + + void IMAPLookingUpHost(); + void IMAPHostFound(); + void IMAPConnected(); + void IMAPDisconnected(); + void IMAPError(int err); + +protected: + void doLogin(); + QString escape(const QString &in); + QString tag(bool count = true); + +protected slots: + void slotDataReceived(const QString &data); + void slotLookingUpHost(); + void slotHostFound(); + void slotConnected(); + void slotDisconnected(); + void slotError(int err); + +private: + Account _account; + IMAPBase *_ibase; + unsigned int _tag; + bool _loggingin, _loggedin; + +}; + +#endif diff --git a/noncore/unsupported/mail2/libmail/imapresponse.cpp b/noncore/unsupported/mail2/libmail/imapresponse.cpp new file mode 100644 index 0000000..06dca33 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imapresponse.cpp @@ -0,0 +1,448 @@ +#include "imapresponse.h" + +static QString _previousData; +static unsigned int _neededData; + +IMAPResponseParser::IMAPResponseParser(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 { + break; + } + } else { + parseResponse(lineData); + } + } else if (tag == "+") { + emit needMoreData(_data); + } else { + _iresponse.setTag(tag); + parseResponse(_data, true); + } + } + } +} + +IMAPResponse IMAPResponseParser::response() +{ + return _iresponse; +} + +void IMAPResponseParser::parseResponse(const QString &data, bool tagged) +{ + QString response, line; + int pos; + bool isNum = false; + 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."); + 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); + if (!tagged) status.setExitedUnexpected(true); + _iresponse.setStatusResponse(status); + } else if (response == "CAPABILITY") { + IMAPResponseCAPABILITY capability(QStringList::split(' ', line)); + _iresponse.addCAPABILITY(capability); + } else if (response == "LIST") { + QStringList list = splitData(line, true); + + 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++) + "|"); + } + _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; + + QStringList fetchList = splitData(line, true); + QStringList list; + parseParenthesizedList(fetchList[1], list); + + for (it = list.begin(); it != list.end(); it++) { + if (*it == "BODY") { + qDebug("IMAPResponseParser: responseParser: got FETCH::BODY"); + // XXX + } else if ((*it).find(QRegExp("BODY\\[\\d+\\]")) != -1) { + QString bodydata = *(++it); + qDebug("IMAPResponseParser: responseParser: got FETCH::BODY[x]"); + + 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); + + tmp = list[0]; + tmp.replace(0, 5, ""); + tmp.truncate(blist[0].length() - 1); + bodypart.setPart(tmp); + + 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") { + QString envdata = *(++it); + QStringList envList; + parseParenthesizedList(envdata, envList); + + IMAPResponseEnvelope envelope; + envelope.setMailDate(envList[0] == "NIL" ? QString(0) : removeLimiters(envList[0])); + envelope.setSubject(envList[1] == "NIL" ? QString(0) : removeLimiters(envList[1])); + + QStringList froml, senderl, replytol, tol, ccl, bccl; + QStringList froma, sendera, replytoa, toa, cca, bcca; + parseParenthesizedList(envList[2], froml); + parseParenthesizedList(envList[3], senderl); + parseParenthesizedList(envList[4], replytol); + parseParenthesizedList(envList[5], tol); + parseParenthesizedList(envList[6], ccl); + parseParenthesizedList(envList[7], bccl); + + QStringList::Iterator it; + for (it = froml.begin(); it != froml.end(); it++) { + parseParenthesizedList(*it, froma); + if (froml[0] != "NIL") + envelope.addFrom(IMAPResponseAddress( + removeLimiters(froma[0]), + removeLimiters(froma[1]), + removeLimiters(froma[2]), + removeLimiters(froma[3]))); + } + + for (it = senderl.begin(); it != senderl.end(); it++) { + parseParenthesizedList(*it, sendera); + if (senderl[0] != "NIL") + envelope.addSender(IMAPResponseAddress( + removeLimiters(sendera[0]), + removeLimiters(sendera[1]), + removeLimiters(sendera[2]), + removeLimiters(sendera[3]))); + } + + for (it = replytol.begin(); it != replytol.end(); it++) { + parseParenthesizedList(*it, replytoa); + if (replytol[0] != "NIL") + envelope.addReplyTo(IMAPResponseAddress( + removeLimiters(replytoa[0]), + removeLimiters(replytoa[1]), + removeLimiters(replytoa[2]), + removeLimiters(replytoa[3]))); + } + + for (it = tol.begin(); it != tol.end(); it++) { + parseParenthesizedList(*it, toa); + if (tol[0] != "NIL") + envelope.addTo(IMAPResponseAddress( + removeLimiters(toa[0]), + removeLimiters(toa[1]), + removeLimiters(toa[2]), + removeLimiters(toa[3]))); + } + + for (it = ccl.begin(); it != ccl.end(); it++) { + parseParenthesizedList(*it, cca); + if (ccl[0] != "NIL") + envelope.addCc(IMAPResponseAddress( + removeLimiters(cca[0]), + removeLimiters(cca[1]), + removeLimiters(cca[2]), + removeLimiters(cca[3]))); + } + + for (it = bccl.begin(); it != bccl.end(); it++) { + parseParenthesizedList(*it, bcca); + if (bccl[0] != "NIL") + envelope.addBcc(IMAPResponseAddress( + removeLimiters(bcca[0]), + removeLimiters(bcca[1]), + 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 + "|"); +} + +QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets) +{ + int b = 0; + bool a = false, noappend = false, escaped = false; + QString temp; + QStringList list; + + 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; + else escaped = false; + + if (data[i] == '\\' && data[i + 1] == '"') escaped = true; + + if ((data[i] == ' ' || i == data.length()) && b == 0 && !a) { + list.append(temp); + temp = QString(0); + 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 + "|"); +} + +QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el) +{ + QString tmpString; + 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; + 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 + "|"); + 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 + "|"); + } + return flags; +} + diff --git a/noncore/unsupported/mail2/libmail/imapresponse.h b/noncore/unsupported/mail2/libmail/imapresponse.h new file mode 100644 index 0000000..73435ee --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/imapresponse.h @@ -0,0 +1,531 @@ +#ifndef IMAPRESPONSE_H +#define IMAPRESPONSE_H + +#include <qobject.h> + +#define MAX_BODYPARTS 50 + +class IMAPHandler; + +class IMAPResponseEnums +{ +public: + enum IMAPResponseStatus { + OK, NO, BAD, PREAUTH, BYE, UnknownStatus = 0 + }; + + enum IMAPResponseFlags { + Seen, Answered, Flagged, Deleted, Draft, Recent, + Noinferiors, Noselect, Marked, Unmarked, UnknownFlag = 0 + }; + + enum IMAPResponseCode { + ALERT, NEWNAME, PARSE, PERMANENTFLAGS, READONLY, READWRITE, + TRYCREATE, UIDVALIDITY, UNSEEN, NoCode, UnknownCode = 0 + }; + +}; + +class IMAPResponseAddress +{ +public: + IMAPResponseAddress(QString name = 0, QString adl = 0, QString mailbox = 0, QString host = 0) + { + _name = name; + _adl = adl; + _mailbox = mailbox; + _host = host; + } + + void setName(QString name) { _name = name; } + QString name() { return _name; } + void setAdl(QString adl) { _adl = adl; } + QString adl() { return _adl; } + void setMailbox(QString mailbox) { _mailbox = mailbox; } + QString mailbox() { return _mailbox; } + void setHost(QString host) { _host = host; } + QString host() { return _host; } + + QString toString() + { + if (_name.isNull() && _mailbox.isNull() && _host.isNull()) + return QString(0); + if (_name != _mailbox + "@" + _host) + return _name + " <" + _mailbox + "@" + _host + ">"; + else + return _name; + } + + QString email() + { + if (_host.isEmpty()) return _mailbox; + else return _mailbox + "@" + _host; + } + +private: + QString _name, _adl, _mailbox, _host; + +}; + +class IMAPResponseAddressList : public QValueList<IMAPResponseAddress> +{ +public: + IMAPResponseAddressList() + : QValueList<IMAPResponseAddress>() + { + + } + + QString toString() + { + QString string; + IMAPResponseAddressList::Iterator it; + for (it = this->begin(); it != this->end(); it++) { + QString tmp = (*it).toString(); + if (!tmp.isNull() && string.isEmpty()) string = tmp; + else if (!tmp.isNull()) string += ", " + tmp; + } + return string; + } + +}; + +class IMAPResponseBody +{ +public: + void setData(QString data) { _data = data; } + QString data() { return _data; } + +private: + QString _data; + +}; + +class IMAPResponseBodyPart : public IMAPResponseBody +{ +public: + void setPart(QString part) { _part = part; } + QString part() { return _part; } + +private: + QString _part; + +}; + +class IMAPResponseEnvelope +{ +public: + void setMailDate(QString date) { _date = date; } + QString mailDate() { return _date; } + void setSubject(QString subject) { _subject = subject; } + QString subject() { return _subject; } + void addFrom(IMAPResponseAddress from) { _from.append(from); } + IMAPResponseAddressList from() { return _from; } + void addSender(IMAPResponseAddress sender) { _sender.append(sender); } + IMAPResponseAddressList sender() { return _sender; } + void addReplyTo(IMAPResponseAddress replyTo) { _replyTo.append(replyTo); } + IMAPResponseAddressList replyTo() { return _replyTo; } + void addTo(IMAPResponseAddress to) { _to.append(to); } + IMAPResponseAddressList to() { return _to; } + void addCc(IMAPResponseAddress cc) { _cc.append(cc); } + IMAPResponseAddressList cc() { return _cc; } + void addBcc(IMAPResponseAddress bcc) { _bcc.append(bcc); } + IMAPResponseAddressList bcc() { return _bcc; } + void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; } + QString inReplyTo() { return _inReplyTo; } + void setMessageId(QString messageId) { _messageId = messageId; } + QString messageId() { return _messageId; } + +private: + QString _date, _subject, _inReplyTo, _messageId; + IMAPResponseAddressList _from, _sender, _replyTo, _to, _cc, _bcc; + +}; + +class IMAPResponseStatusResponse : public IMAPResponseEnums +{ +public: + IMAPResponseStatusResponse(IMAPResponseStatus status = (IMAPResponseStatus)0, QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) + { + _status = status; + _comment = comment; + _code = code; + } + + void setStatus(IMAPResponseStatus status) { _status = status; } + IMAPResponseStatus status() { return _status; } + void setComment(QString comment) { _comment = comment; } + QString comment() { return _comment; } + void setResponseCode(IMAPResponseCode code) { _code = code; } + IMAPResponseCode responseCode() { return _code; } + + void setExitedUnexpected(bool exitu) { _exitu = exitu; } + bool exitedUnexpected() { return _exitu; } + +private: + IMAPResponseStatus _status; + QString _comment; + IMAPResponseCode _code; + bool _exitu; + +}; + +class IMAPResponseOK : public IMAPResponseEnums +{ +public: + IMAPResponseOK(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) + { + _comment = comment; + _code = code; + } + + void setComment(QString comment) { _comment = comment; } + QString comment() { return _comment; } + void setResponseCode(IMAPResponseCode code) { _code = code; } + IMAPResponseCode responseCode() { return _code; } + +private: + QString _comment; + IMAPResponseCode _code; + +}; + +class IMAPResponseNO : public IMAPResponseEnums +{ +public: + IMAPResponseNO(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) + { + _comment = comment; + _code = code; + } + + void setComment(QString comment) { _comment = comment; } + QString comment() { return _comment; } + void setResponseCode(IMAPResponseCode code) { _code = code; } + IMAPResponseCode responseCode() { return _code; } + +private: + QString _comment; + IMAPResponseCode _code; + +}; + +class IMAPResponseBAD : public IMAPResponseEnums +{ +public: + IMAPResponseBAD(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) + { + _comment = comment; + _code = code; + } + + void setComment(QString comment) { _comment = comment; } + QString comment() { return _comment; } + void setResponseCode(IMAPResponseCode code) { _code = code; } + IMAPResponseCode responseCode() { return _code; } + +private: + QString _comment; + IMAPResponseCode _code; + +}; + +class IMAPResponseCAPABILITY +{ +public: + IMAPResponseCAPABILITY(QStringList capabilities = 0) + { + _capabilities = capabilities; + } + + void setCapabilities(QStringList capabilities) { _capabilities = capabilities; } + QStringList capabilities() { return _capabilities; } + +private: + QStringList _capabilities; + +}; + +class IMAPResponseLIST : public IMAPResponseEnums +{ +public: + IMAPResponseLIST(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeparator = 0, QString folder = 0) + { + _flags = flags; + _folderSeparator = folderSeparator; + _folder = folder; + } + + void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } + QValueList<IMAPResponseFlags> flags() { return _flags; } + void setFolderSeparator(QString folderSeparator) { _folderSeparator = folderSeparator; } + QString folderSeparator() { return _folderSeparator; } + void setFolder(QString folder) { _folder = folder; } + QString folder() { return _folder; } + +private: + QValueList<IMAPResponseFlags> _flags; + QString _folderSeparator, _folder; + +}; + +class IMAPResponseLSUB : public IMAPResponseEnums +{ +public: + IMAPResponseLSUB(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeperator = 0, QString folder = 0) + { + _flags = flags; + _folderSeperator = folderSeperator; + _folder = folder; + } + + void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } + QValueList<IMAPResponseFlags> flags() { return _flags; } + void setFolderSeperator(QString folderSeperator) { _folderSeperator = folderSeperator; } + QString folderSeperator() { return _folderSeperator; } + void setFolder(QString folder) { _folder = folder; } + QString folder() { return _folder; } + +private: + QValueList<IMAPResponseFlags> _flags; + QString _folderSeperator, _folder; + +}; + +class IMAPResponseSTATUS +{ +public: + IMAPResponseSTATUS(QString mailbox = 0, QString messages = 0, QString recent = 0, QString uidnext = 0, QString uidvalidity = 0, QString unseen = 0) + { + _mailbox = mailbox; + _messages = messages; + _recent = recent; + _uidnext = uidnext; + _uidvalidity = uidvalidity; + _unseen = unseen; + } + + void setMailbox(QString &mailbox) { _mailbox = mailbox; } + QString mailbox() { return _mailbox; } + void setMessages(QString &messages) { _messages = messages; } + QString messages() { return _messages; } + void setRecent(QString &recent) { _recent = recent; } + QString recent() { return _recent; } + void setUidnext(QString &uidnext) { _uidnext = uidnext; } + QString uidnext() { return _uidnext; } + void setUidvalidity(QString &uidvalidity) { _uidvalidity = uidvalidity; } + QString uidvalidity() { return _uidvalidity; } + void setUnseen(QString &unseen) { _unseen = unseen; } + QString unseen() { return _unseen; } + +private: + QString _mailbox, _messages, _recent, _uidnext, _uidvalidity, _unseen; + +}; + +class IMAPResponseSEARCH +{ +public: + IMAPResponseSEARCH(QStringList mails = 0) + { + _mails = mails; + } + + void setMails(QStringList mails) { _mails = mails; } + QStringList mails() { return _mails; } + +private: + QStringList _mails; + +}; + +class IMAPResponseFLAGS : public IMAPResponseEnums +{ +public: + IMAPResponseFLAGS(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>()) + { + _flags = flags; + } + + void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } + QValueList<IMAPResponseFlags> flags() { return _flags; } + +private: + QValueList<IMAPResponseFlags> _flags; + +}; + +class IMAPResponseEXISTS +{ +public: + IMAPResponseEXISTS(QString mails = 0) + { + _mails = mails; + } + + void setMails(QString mails) { _mails = mails; } + QString mails() { return _mails; } + +private: + QString _mails; + +}; + +class IMAPResponseRECENT +{ +public: + IMAPResponseRECENT(QString mails = 0) + { + _mails = mails; + } + + void setMails(QString mails) { _mails = mails; } + QString mails() { return _mails; } + +private: + QString _mails; + +}; + +class IMAPResponseEXPUNGE +{ +public: + IMAPResponseEXPUNGE(QString mails = 0) + { + _mails = mails; + } + + void setMails(QString mails) { _mails = mails; } + QString mails() { return _mails; } + +private: + QString _mails; + +}; + +class IMAPResponseFETCH : public IMAPResponseEnums +{ +public: + void setEnvelope(IMAPResponseEnvelope envelope) { _envelope = envelope; } + IMAPResponseEnvelope envelope() { return _envelope; } + void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } + QValueList<IMAPResponseFlags> flags() { return _flags; } + void setInternalDate(QString idate) { _idate = idate; } + QString internalDate() { return _idate; } + void setRFC822Size(QString rfc822size) { _rfc822size = rfc822size; } + QString RFC822Size() { return _rfc822size; } + void setUid(QString uid) { _uid = uid; } + QString uid() { return _uid; } + + void setBody(QString body) { _body = body; } + QString body() { return _body; } + void addBodyPart(IMAPResponseBodyPart part) { _bodyParts.append(part); } + void setBodyParts(QValueList<IMAPResponseBodyPart> parts) { _bodyParts = parts; } + QValueList<IMAPResponseBodyPart> bodyParts() { return _bodyParts; } + IMAPResponseBodyPart bodyPart(int part) { return _bodyParts[part]; } + void setRfc822(QString rfc822) { _rfc822 = rfc822; } + QString rfc822() { return _rfc822; } + void setRfc822Header(QString rfc822Header) { _rfc822Header = rfc822Header; } + QString rfc822Header() { return _rfc822Header; } + void setRfc822Text(QString rfc822Text) { _rfc822Text = rfc822Text; } + QString rfc822Text() { return _rfc822Text; } + +private: + IMAPResponseEnvelope _envelope; + QValueList<IMAPResponseFlags> _flags; + QString _idate, _rfc822size, _uid, _body, _rfc822, _rfc822Header, _rfc822Text; + QValueList<IMAPResponseBodyPart> _bodyParts; + +}; + +class IMAPResponse : public IMAPResponseEnums +{ +public: + void setTag(QString tag) { _tag = tag; } + QString tag() { return _tag; } + + void setImapHandler(IMAPHandler *handler) { _handler = handler; } + IMAPHandler *imapHandler() { return _handler; } + + void setStatusResponse(IMAPResponseStatusResponse response) { _response = response; } + IMAPResponseStatusResponse statusResponse() { return _response; } + + void addOK(IMAPResponseOK ok) { _okl.append(ok); } + void addNO(IMAPResponseNO no) { _nol.append(no); } + void addBAD(IMAPResponseBAD bad) { _badl.append(bad); } + void addCAPABILITY(IMAPResponseCAPABILITY capability) { _capabilityl.append(capability); } + void addLIST(IMAPResponseLIST list) { _listl.append(list); } + void addLSUB(IMAPResponseLSUB lsub) { _lsubl.append(lsub); } + void addSTATUS(IMAPResponseSTATUS status) { _statusl.append(status); } + void addSEARCH(IMAPResponseSEARCH search) { _searchl.append(search); } + void addFLAGS(IMAPResponseFLAGS flags) { _flagsl.append(flags); } + void addEXISTS(IMAPResponseEXISTS exists) { _existsl.append(exists); } + void addRECENT(IMAPResponseRECENT recent) { _recentl.append(recent); } + void addEXPUNGE(IMAPResponseEXPUNGE expunge) { _expungel.append(expunge); } + void addFETCH(IMAPResponseFETCH fetch) { _fetchl.append(fetch); } + + QValueList<IMAPResponseOK> OK() { return _okl; } + QValueList<IMAPResponseNO> NO() { return _nol; } + QValueList<IMAPResponseBAD> BAD() { return _badl; } + QValueList<IMAPResponseCAPABILITY> CAPABILITY() { return _capabilityl; } + QValueList<IMAPResponseLIST> LIST() { return _listl; } + QValueList<IMAPResponseLSUB> LSUB() { return _lsubl; } + QValueList<IMAPResponseSTATUS> STATUS() { return _statusl; } + QValueList<IMAPResponseSEARCH> SEARCH() { return _searchl; } + QValueList<IMAPResponseFLAGS> FLAGS() { return _flagsl; } + 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); + + IMAPResponse response(); + +signals: + void needMoreData(const QString &comment); + +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/libmail/libmail.pro b/noncore/unsupported/mail2/libmail/libmail.pro new file mode 100644 index 0000000..662af90 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/libmail.pro @@ -0,0 +1,26 @@ +TEMPLATE = lib +CONFIG = qt warn_on release +HEADERS = configfile.h \ + defines.h \ + imapbase.h \ + imaphandler.h \ + imapresponse.h \ + mailfactory.h \ + md5.cpp \ + miscfunctions.h \ + sharp_char.h \ + smtphandler.h \ + zaurusstuff.h +SOURCES = configfile.cpp \ + imapbase.cpp \ + imaphandler.cpp \ + imapresponse.cpp \ + mailfactory.cpp \ + md5.h \ + miscfunctions.cpp \ + smtphandler.cpp \ + zaurusstuff.cpp +INCLUDEPATH += $(OPIEDIR)/include +LIBS += -L$(OPIEDIR)/lib -lqpe +TARGET = mail +DESTDIR = $(QTDIR)/lib diff --git a/noncore/unsupported/mail2/libmail/mailfactory.cpp b/noncore/unsupported/mail2/libmail/mailfactory.cpp new file mode 100644 index 0000000..58cf5f8 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/mailfactory.cpp @@ -0,0 +1,173 @@ +#include <qmessagebox.h> +#include <qtextstream.h> +#include <qfile.h> + +#include <qpe/mimetype.h> + +#include "miscfunctions.h" +#include "mailfactory.h" +#include "defines.h" + +MailFactory::MailFactory(SendMail &smail, QWidget *parent) + : QObject(), _smail(smail), _parent(parent) +{ + _abort = false; + Account account = _smail.account(); + + if (!_smail.from().isEmpty()) + _header += "From: " + _smail.from() + "\n"; + if (!_smail.replyTo().isEmpty()) + _header += "Reply-To: " + _smail.replyTo() + "\n"; + if (!_smail.to().isEmpty()) + _header += "To: " + _smail.to() + "\n"; + if (!_smail.cc().isEmpty()) + _header += "Cc: " + _smail.cc() + "\n"; + if (!_smail.bcc().isEmpty()) + _header += "Bcc: " + _smail.bcc() + "\n"; + if (!_smail.subject().isEmpty()) + _header += "Subject: " + _smail.subject() + "\n"; + if (!_smail.priority().isEmpty() || (_smail.priority() != "Normal")) + _header += "Priority: " + _smail.priority() + "\n"; + _header += "Date: " + MiscFunctions::rfcDate() + "\n"; + if (!_smail.account().org().isEmpty()) + _header += "Organization: " + _smail.account().org() + "\n"; + if (_smail.needsMime()) + _header += "Mime-Version: 1.0\n"; + _header += "Message-Id: <" + MiscFunctions::uniqueString() + "." + account.email() + ">\n"; + if (!_smail.inReplyTo().isEmpty()) + _header += "In-Reply-To: " + _smail.inReplyTo() + "\n"; + if (!QString((QString) USERAGENT).isEmpty()) + _header += (QString) "User-Agent: " + USERAGENT + "\n"; + + if (!_smail.needsMime()) { +// if (_smail.encrypt() && !_smail.sign()) { +// openPgpEncrypt(_smail.message(), _header, _body); +// } else if (!_smail.encrypt() && _smail.sign()) { +// openPgpSign(_smail.message(), _header, _body); +// } else if (_smail.encrypt() && _smail.sign()) { +// openPgpSignEncrypt(_smail.message(), _header, _body); +// } else { + _body += _smail.message(); +// } + } else { + QString boundary = MiscFunctions::uniqueString(); + + _header += "Content-Type: multipart/mixed; boundary=\"" + boundary + "\"\n"; + + _body += "This is a multi-part message in MIME format.\n\n"; + _body += "--" + boundary + "\n"; + +// if (_smail.encrypt() && !_smail.sign()) { +// QString header, body; +// openPgpEncrypt(_smail.message(), header, body); +// _body += header + "\n" + body + "\n"; +// } else if (!_smail.encrypt() && _smail.sign()) { +// QString header, body; +// openPgpSign(_smail.message(), header, body); +// _body += header + "\n" + body + "\n"; +// } else if (_smail.encrypt() && _smail.sign()) { +// QString header, body; +// openPgpSignEncrypt(_smail.message(), header, body); +// _body += header + "\n" + body + "\n"; +// } else { + + // TODO: Do proper charset handling! + _body += "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; + _body += "Content-Transfer-Encoding: 8bit\n\n"; + _body += _smail.message() + "\n"; +// } + + QValueList<Attachment> attachments = _smail.attachments(); + QValueList<Attachment>::Iterator it; + for (it = attachments.begin(); it != attachments.end(); it++) { + QFile f((*it).fileName()); + if (f.open(IO_ReadOnly)) { + QTextStream t(&f); + QString file; + while (!t.atEnd()) file += t.readLine() + "\n"; + f.close(); + QString mimetype = (new MimeType(*(*it).docLnk()))->id(); + + _body += "\n--" + boundary + "\n"; + _body += "Content-Type: " + mimetype + "; name=\"" + (*it).newName() + "\"\n"; + + // TODO: Decide which content transfer encoding is best. B64 for binary, QP for text. + _body += "Content-Transfer-Encoding: base64\n"; + + _body += "Content-Disposition: attachment; filename=\"" + (*it).newName() + "\"\n"; + if (!(*it).description().isEmpty()) + _body += "Content-Description: " + (*it).description() + "\n"; + + _body += "\n" + MiscFunctions::encodeBase64(file) + "\n"; + } else { + int ret = QMessageBox::critical(_parent, tr("Error"), tr("<p>Couldn't attach file '%1'. Continue anyway or abort?</p>"), tr("Continue"), tr("Abort")); + if (ret == 1) { + it = attachments.end(); + _abort = true; + } + } + } + _body += "\n--" + boundary + "--"; + } + + if (_abort) { + _body = QString(0); + _header = QString(0); + } +} + +// Unfinished GPG code. +/* +void MailFactory::openPgpEncrypt(const QString &text, QString &header, QString &body) +{ + QString boundary = MiscFunctions::uniqueString(); + + header += "Content-Type: multipart/encrypted; boundary=\"" + boundary + "\"; protocol=\"application/pgp-encrypted\"\n"; + + body += "--" + boundary + "\n"; + body += "Content-Type: application/pgp-encrypted\n\n"; + body += "Version: 1\n\n"; + body += "--" + boundary + "\n"; + body += "Content-Type: application/octet-stream\n\n"; + body += GpgHandling::encrypt(_smail.gpgReceivers(), text); + body += "\n--" + boundary + "--\n"; +} + +void MailFactory::openPgpSign(const QString &text, QString &header, QString &body) +{ + QString boundary = MiscFunctions::uniqueString(); + + header += "Content-Type: multipart/signed; boundary=\"" + boundary + "\"; protocol=\"application/pgp-signature\"\n"; + + body += "--" + boundary + "\n"; + + QString temp; + temp += "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; + temp += "Content-Transfer-Encoding: quoted-printable\n\n"; + temp += MiscFunctions::encodeQPrintable(text) + "\n"; + body += temp; + + temp.replace(QRegExp("\n"), "\r\n"); + QString signature = GpgHandling::sign(temp, _parent); + + body += "\n--" + boundary + "\n"; + body += "Content-Type: application/pgp-signature\n\n"; + body += signature + "\n"; + body += "\n--" + boundary + "--\n"; +} + +void MailFactory::openPgpSignEncrypt(const QString &text, QString &header, QString &message) +{ + QString header_, message_; + openPgpSign(text, header_, message_); + openPgpEncrypt(header_ + "\n" + message_, header, message); +} +*/ +void MailFactory::genMail(QString &header, QString &message, SendMail &smail, QWidget *parent) +{ + MailFactory factory(smail, parent); + + header = factory._header; + message = factory._body; +} + diff --git a/noncore/unsupported/mail2/libmail/mailfactory.h b/noncore/unsupported/mail2/libmail/mailfactory.h new file mode 100644 index 0000000..8f67447 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/mailfactory.h @@ -0,0 +1,109 @@ +#ifndef MAILFACTORY_H +#define MAILFACTORY_H + +#include <qobject.h> + +#include <qpe/applnk.h> + +#include "configfile.h" + +class Attachment +{ +public: + void setFileName(QString fileName) { _fileName = fileName; } + void setNewName(QString newName) { _newName = newName; } + void setDescription(QString description) { _description = description; } + void setDocLnk(DocLnk *docLnk) { _docLnk = docLnk; } + + QString fileName() { return _fileName; } + QString newName() { return _newName; } + QString description() { return _description; } + DocLnk *docLnk() { return _docLnk; } + +protected: + QString _fileName, _newName, _description; + DocLnk *_docLnk; + +}; + +class SendMail +{ +public: + SendMail() { _needsMime = false; } + + void setAccount(Account account) { _account = account; } + + void setFrom(QString from) { _from = from; } + void setReplyTo(QString replyTo) { _replyTo = replyTo; } + void setTo(QString to) { _to = to; } + void setCc(QString cc) { _cc = cc; } + void setBcc(QString bcc) { _bcc = bcc; } + void setSubject(QString subject) { _subject = subject; } + void setPriority(QString priority) { _priority = priority; } + void setMessage(QString message) { _message = message; } + void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; } + + void setNeedsMime(bool needsMime) { _needsMime = needsMime; } + + //void setEncrypt(bool encrypt) { _encrypt = encrypt; } + //void setSign(bool sign) { _sign = sign; } + //void setGpgReceivers(QValueList<GpgKey> receivers) { _receivers = receivers; } + //void setGpgPassphrase(QString passphrase) { _passphrase = passphrase; } + + void setAttachments(QValueList<Attachment> attachments) { _attachments = attachments; } + void addAttachment(Attachment attachment) { _attachments.append(attachment); } + + Account account() { return _account; } + + QString from() { return _from; } + QString replyTo() { return _replyTo; } + QString to() { return _to; } + QString cc() { return _cc; } + QString bcc() { return _bcc; } + QString subject() { return _subject; } + QString priority() { return _priority; } + QString message() { return _message; } + QString inReplyTo() { return _inReplyTo; } + + bool needsMime() { return _needsMime; } + + //bool encrypt() { return _encrypt; } + //bool sign() { return _sign; } + //QValueList<GpgKey> gpgReceivers() { return _receivers; } + //QString gpgPassphrase() { return _passphrase; } + + QValueList<Attachment> attachments() { return _attachments; } + +protected: + Account _account; + QString _from, _replyTo, _to, _cc, _bcc, _subject, _priority, _message, _inReplyTo; + bool _needsMime; + //bool _encrypt, _sign; + //QValueList<GpgKey> _receivers; + //QString _passphrase; + QValueList<Attachment> _attachments; + +}; + +class MailFactory : public QObject +{ + Q_OBJECT + +public: + static void genMail(QString &header, QString &message, SendMail &smail, QWidget *parent); + +protected: + MailFactory(SendMail &smail, QWidget *parent); + +// void openPgpEncrypt(const QString &text, QString &header, QString &message); +// void openPgpSign(const QString &text, QString &header, QString &message); +// void openPgpSignEncrypt(const QString &text, QString &header, QString &message); + + bool _abort; + SendMail _smail; + QWidget *_parent; + QString _header, _body; + +}; + +#endif diff --git a/noncore/unsupported/mail2/libmail/md5.cpp b/noncore/unsupported/mail2/libmail/md5.cpp new file mode 100644 index 0000000..4ee2c42 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/md5.cpp @@ -0,0 +1,242 @@ +// This code was written by Colin Plumb. I've made some small changes. +// (Constantin Bergemann) + +#ifdef __cplusplus +extern "C" { +#endif + +#include <string.h> /* for memcpy() */ +#include "md5.h" + +#if __BYTE_ORDER == 1234 +#define byteReverse(buf, len) /* Nothing */ +#else +void byteReverse(unsigned char *buf, unsigned longs); + +/* + * Note: this code is harmless on little-endian machines. + */ +void byteReverse(unsigned char *buf, unsigned longs) +{ + u_int32_t t; + do { + t = (u_int32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(u_int32_t *) buf = t; + buf += 4; + } while (--longs); +} +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void MD5_Init(MD5_CTX *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void MD5_Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) +{ + u_int32_t t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((u_int32_t) len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *) ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (u_int32_t *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (u_int32_t *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (u_int32_t *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((u_int32_t *) ctx->in)[14] = ctx->bits[0]; + ((u_int32_t *) ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (u_int32_t *) ctx->in); + byteReverse((unsigned char *) ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset((char *) ctx, 0, sizeof(ctx)); /* In case it's sensitive */ +} + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +void MD5Transform(u_int32_t buf[4], u_int32_t const in[16]) +{ + register u_int32_t a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +#ifdef __cplusplus +} // extern "C" +#endif + diff --git a/noncore/unsupported/mail2/libmail/md5.h b/noncore/unsupported/mail2/libmail/md5.h new file mode 100644 index 0000000..221dd09 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/md5.h @@ -0,0 +1,35 @@ +// This code was written by Colin Plumb. I've made some small changes. +// (Constantin Bergemann) + +#ifndef _MD5_H_ +#define _MD5_H_ + +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define MD5_HASHBYTES 16 + +typedef struct MD5Context { + u_int32_t buf[4]; + u_int32_t bits[2]; + unsigned char in[64]; +} MD5_CTX; + +extern void MD5_Init(MD5_CTX *context); +extern void MD5_Update(MD5_CTX *context, unsigned char const *buf, + unsigned len); +extern void MD5_Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context); +extern void MD5Transform(u_int32_t buf[4], u_int32_t const in[16]); +extern char * MD5End(MD5_CTX *, char *); +extern char * MD5File(const char *, char *); +extern char * MD5Data (const unsigned char *, unsigned int, char *); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* !_MD5_H_ */ + diff --git a/noncore/unsupported/mail2/libmail/miscfunctions.cpp b/noncore/unsupported/mail2/libmail/miscfunctions.cpp new file mode 100644 index 0000000..0edbfa8 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/miscfunctions.cpp @@ -0,0 +1,295 @@ +#include <qdatetime.h> + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +#include <openssl/md5.h> + +#include "miscfunctions.h" + +QString MiscFunctions::encodeQPrintable(const QString &src) +{ + // TODO: implent encodeQPrintable + return src; +} + +QString MiscFunctions::decodeQPrintable(const QString &src) +{ + QString out; + + for (unsigned int i = 0; i <= src.length(); i++) { + if (src[i] == '=') { + if (src[i+1] == "\n") { + i += 1; + } else { + QString temp = QString("%1%2").arg(src[i+1]).arg(src[i+2]); + int number = temp.toInt(0, 16); + + out += QChar(number); + i += 2; + } + } else { + out += src[i]; + } + } + return out; +} + +QString MiscFunctions::encodeBase64(const QString &src) +{ + char *dataPtr = (char *) src.latin1(); + int len = src.length(); + int count = 0; + QString temp = ""; + + while (len > 0) { + if (len < 3) { + encodeBase64Base(dataPtr, &temp, len); + len = 0; + } else { + encodeBase64Base(dataPtr, &temp, 3); + len -= 3; + dataPtr += 3; + count += 4; + } + if (count > 72) { + count = 0; + temp += "\n"; + } + } + + return temp; +} + +void MiscFunctions::encodeBase64Base(char *src, QString *dest, int len) +{ + QString temp; + uchar c; + uchar bufOut[4]; + + bufOut[0] = src[0]; + bufOut[0] >>= 2; + + bufOut[1] = src[0]; + bufOut[1] = bufOut[1] & (1 + 2); + bufOut[1] <<= 4; + if (len > 1) c = src[1]; + else c = 0; + + c = c & (16 + 32 + 64 + 128); + c >>= 4; + bufOut[1] = bufOut[1] | c; + + bufOut[2] = src[1]; + bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); + bufOut[2] <<= 2; + if (len > 2) c = src[2]; + else c = 0; + + c >>= 6; + bufOut[2] = bufOut[2] | c; + + bufOut[3] = src[2]; + bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); + + if (len == 1) { + bufOut[2] = 64; + bufOut[3] = 64; + } + if (len == 2) { + bufOut[3] = 64; + } + for (int x = 0; x < 4; x++) { + if (bufOut[x] <= 25) + bufOut[x] += (uint) 'A'; + else if (bufOut[x] >= 26 && bufOut[x] <= 51) + bufOut[x] += (uint) 'a' - 26; + else if (bufOut[x] >= 52 && bufOut[x] <= 61) + bufOut[x] += (uint) '0' - 52; + else if (bufOut[x] == 62) + bufOut[x] = '+'; + else if (bufOut[x] == 63) + bufOut[x] = '/'; + else if (bufOut[x] == 64) + bufOut[x] = '='; + + dest->append(bufOut[x]); + } +} + +QString MiscFunctions::decodeBase64(const QString &src) +{ + char plain[4]; + char *destPtr; + QByteArray buffer; + uint bufCount = 0, pos = 0, decodedCount, x; + + buffer.resize(src.length() * 3 / 4); + destPtr = buffer.data(); + + while (pos < src.length()) { + decodedCount = 4; + x = 0; + while ((x < 4) && (pos < src.length())) { + plain[x] = src[pos].latin1(); + pos++; + if (plain[x] == '\r' || plain[x] == '\n' || plain[x] == ' ') + x--; + x++; + } + if (x > 1) { + decodedCount = decodeBase64Base(plain, destPtr); + destPtr += decodedCount; + bufCount += decodedCount; + } + } + + buffer.resize(bufCount); + return QString(buffer); +} + +int MiscFunctions::decodeBase64Base(char *src, char *bufOut) +{ + char c, z; + char li[4]; + int processed; + + for (int x = 0; x < 4; x++) { + c = src[x]; + + if ( (int) c >= 'A' && (int) c <= 'Z') + li[x] = (int) c - (int) 'A'; + if ( (int) c >= 'a' && (int) c <= 'z') + li[x] = (int) c - (int) 'a' + 26; + if ( (int) c >= '0' && (int) c <= '9') + li[x] = (int) c - (int) '0' + 52; + if (c == '+') + li[x] = 62; + if (c == '/') + li[x] = 63; + } + + processed = 1; + bufOut[0] = (char) li[0] & (32+16+8+4+2+1); + bufOut[0] <<= 2; + z = li[1] >> 4; + bufOut[0] = bufOut[0] | z; + + if (src[2] != '=') { + bufOut[1] = (char) li[1] & (8+4+2+1); + bufOut[1] <<= 4; + z = li[2] >> 2; + bufOut[1] = bufOut[1] | z; + processed++; + + if (src[3] != '=') { + bufOut[2] = (char) li[2] & (2+1); + bufOut[2] <<= 6; + z = li[3]; + bufOut[2] = bufOut[2] | z; + processed++; + } + } + return processed; +} + +QString MiscFunctions::uniqueString() +{ + QString uniqueString = QDate::currentDate().toString(); + uniqueString += QTime::currentTime().toString(); + uniqueString += QString("%1").arg(rand()); + + unsigned char md[16]; + + MD5_CTX ctx; + MD5_Init(&ctx); + MD5_Update(&ctx, (unsigned char *)uniqueString.latin1(), uniqueString.length()); + MD5_Final(md, &ctx); + + char hash[16]; + for (unsigned int i = 0; i < sizeof(md); i++) + sprintf(hash + 2 * i, "%02x", md[i]); + + return hash; +} + +QString MiscFunctions::rfcDate() +{ + time_t t = time(NULL); + tm *time = localtime(&t); + QString pm, tzh, tzm, ths, tms, tss; + + time->tm_gmtoff < 0 ? pm = "-" : pm = "+"; + int h = abs(time->tm_gmtoff) / 3600; + int m = (abs(time->tm_gmtoff) - h * 3600) / 60; + h < 10 ? tzh = QString("0%1").arg(h) : tzh = QString("%1").arg(h); + m < 10 ? tzm = QString("0%1").arg(m) : tzm = QString("%1").arg(m); + + int th = time->tm_hour; + int tm = time->tm_min; + int ts = time->tm_sec; + th < 10 ? ths = QString("0%1").arg(th) : ths = QString("%1").arg(th); + tm < 10 ? tms = QString("0%1").arg(tm) : tms = QString("%1").arg(tm); + ts < 10 ? tss = QString("0%1").arg(ts) : tss = QString("%1").arg(ts); + + QString month = QDate().monthName(time->tm_mon + 1); + QString dayna = QDate().dayName(time->tm_wday); + QString tzone = pm + tzh + tzm; + + return QString("%1, %2 %3 %4 %5:%6:%7 %8") + .arg(dayna) + .arg(time->tm_mday) + .arg(month) + .arg(time->tm_year + 1900) + .arg(ths) + .arg(tms) + .arg(tss) + .arg(tzone); +} + +QString MiscFunctions::smtpAuthCramMd5(const QString &data, const QString &key) +{ + MD5_CTX context; + unsigned char k_ipad[65]; + unsigned char k_opad[65]; + unsigned char tk[16]; + unsigned char digest[16]; + unsigned char *key_int = (unsigned char *)key.latin1(); + char hash[33]; + + if (key.length() > 64) { + MD5_CTX tctx; + MD5_Init(&tctx); + MD5_Update(&tctx, key_int, sizeof(key_int)); + MD5_Final(tk, &tctx); + + key_int = tk; + } + + bzero(k_ipad, sizeof k_ipad); + bzero(k_opad, sizeof k_opad); + bcopy(key_int, k_ipad, sizeof(key_int)); + bcopy(key_int, k_opad, sizeof(key_int)); + + for (int i = 0; i < 64; i++) { + k_ipad[i] ^= 0x36; + k_opad[i] ^= 0x5c; + } + + MD5_Init(&context); + MD5_Update(&context, k_ipad, 64); + MD5_Update(&context, (unsigned char *)data.latin1(), data.length()); + MD5_Final(digest, &context); + + MD5_Init(&context); + MD5_Update(&context, k_opad, 64); + MD5_Update(&context, digest, 16); + MD5_Final(digest, &context); + + for (unsigned int i = 0; i < sizeof(digest); i++) + sprintf (hash + 2 * i, "%02x", digest[i]); + + return hash; +} + diff --git a/noncore/unsupported/mail2/libmail/miscfunctions.h b/noncore/unsupported/mail2/libmail/miscfunctions.h new file mode 100644 index 0000000..a13e1e3 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/miscfunctions.h @@ -0,0 +1,27 @@ +#ifndef MISCFUNCTIONS_H +#define MISCFUNCTIONS_H + +#include <qobject.h> + +class MiscFunctions : public QObject +{ + Q_OBJECT + +public: + static QString encodeQPrintable(const QString &src); + static QString decodeQPrintable(const QString &src); + static QString encodeBase64(const QString &src); + static QString decodeBase64(const QString &src); + static QString uniqueString(); + static QString rfcDate(); + static QString smtpAuthCramMd5(const QString &data, const QString &key); + +protected: + MiscFunctions() : QObject() { } + + static void encodeBase64Base(char *src, QString *dest, int len); + static int decodeBase64Base(char *src, char *bufOut); + +}; + +#endif diff --git a/noncore/unsupported/mail2/libmail/sharp_char.h b/noncore/unsupported/mail2/libmail/sharp_char.h new file mode 100644 index 0000000..8bd8beb --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/sharp_char.h @@ -0,0 +1,241 @@ +/* + * linux/include/asm/sharp_char.h + */ + +#ifndef __ASM_SHARP_CHAR_H_INCLUDED +#define __ASM_SHARP_CHAR_H_INCLUDED + +/* + * If SHARPCHAR_USE_MISCDEV defined , misc driver architecture used instead of sharp_char + */ + +#define SHARPCHAR_USE_MISCDEV + +/* + * devices defines... + */ + +#ifndef SHARP_DEV_MAJOR +#define SHARP_DEV_MAJOR 11 +#endif + +#ifndef SHARP_DEV_MINOR_START +#define SHARP_DEV_MINOR_START 210 +#endif + +#define SHARP_DEV_MINOR_MAX 4 /* defines last minor number of SHARP device */ + +#define SHARP_LED_MINOR (SHARP_DEV_MINOR_START+0) +#define SHARP_BUZZER_MINOR (SHARP_DEV_MINOR_START+1) +#define SHARP_GSM_MINOR (SHARP_DEV_MINOR_START+2) +#define SHARP_AUDIOCTL_MINOR (SHARP_DEV_MINOR_START+3) +#define SHARP_KBDCTL_MINOR (SHARP_DEV_MINOR_START+4) + +/* + * ioctl defines... + */ + +#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 + +/* --- for SHARP_LED device --- */ +#define SHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) +#define SHARP_LED_GETSTATUS (SHARP_LED_IOCTL_START) +#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) +#define SHARP_LED_ISUPPORTED (SHARP_LED_IOCTL_START+2) + +typedef struct sharp_led_status { + int which; /* select which LED status is wanted. */ + int status; /* set new led status if you call SHARP_LED_SETSTATUS */ +} sharp_led_status; + +#define SHARP_LED_WHICH_MAX 15 /* last number of LED */ + +/* parameters for 'which' member */ +#define SHARP_LED_PDA 0 /* PDA status */ +#define SHARP_LED_DALARM 1 /* daily alarm */ +#define SHARP_LED_SALARM 2 /* schedule alarm */ +#define SHARP_LED_BATTERY 3 /* main battery status */ +#define SHARP_LED_ACSTATUS 4 /* AC line status */ +#define SHARP_LED_CHARGER 5 /* charger status */ +#define SHARP_LED_PHONE_RSSI 6 /* phone status (RSSI...) */ +#define SHARP_LED_PHONE_DIAL 7 /* phone status (dialing...) */ +#define SHARP_LED_PHONE_IN 8 /* phone status (incoming..) */ +#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ +#define SHARP_LED_MAIL_SEND 10 /* mail status (sending...) */ +#define SHARP_LED_MAIL_QUEUE 11 /* mail to send is in queue */ +#define SHARP_LED_COLLIE_0 12 /* 1st pri. battery LED control */ +#define SHARP_LED_COLLIE_1 13 /* 1st pri. mail LED control */ +#define SHARP_LED_COLLIE_2 14 /* reserved */ +#define SHARP_LED_COLLIE_3 15 /* reserved */ + +/* parameters for 'status' member */ +#define LED_PDA_RUNNING 0 /* for SHARP_LED_RUN */ +#define LED_PDA_SUSPENDED 1 /* for SHARP_LED_RUN */ +#define LED_PDA_OFF 2 /* for SHARP_LED_RUN */ +#define LED_PDA_ERROR 3 /* for SHARP_LED_RUN */ + +#define LED_DALARM_OFF 0 /* for SHARP_LED_DALARM */ +#define LED_DALARM_ON 1 /* for SHARP_LED_DALARM */ + +#define LED_SALARM_OFF 0 /* for SHARP_LED_SALARM */ +#define LED_SALARM_ON 1 /* for SHARP_LED_SALARM */ + +#define LED_BATTERY_GOOD 0 /* for SHARP_LED_BATTERY */ +#define LED_BATTERY_LOW 1 /* for SHARP_LED_BATTERY */ +#define LED_BATTERY_VERY_LOW 2 /* for SHARP_LED_BATTERY */ +#define LED_BATTERY_CRITICAL 3 /* for SHARP_LED_BATTERY */ + +#define LED_CHARGER_OFF 0 /* for SHARP_LED_CHARGER */ +#define LED_CHARGER_CHARGING 1 /* for SHARP_LED_CHARGER */ +#define LED_CHARGER_ERROR 2 /* for SHARP_LED_CHARGER */ + +#define LED_AC_NOT_CONNECTED 0 /* for SHARP_LED_ACSTATUS */ +#define LED_AC_CONNECTED 1 /* for SHARP_LED_ACSTATUS */ + +#define LED_RSSI_OUT 0 /* for SHARP_LED_PHONE_RSSI */ +#define LED_RSSI_IN 1 /* for SHARP_LED_PHONE_RSSI */ + +#define LED_DIAL_OFF 0 /* for SHARP_LED_PHONE_DIAL */ +#define LED_DIAL_DIALING 1 /* for SHARP_LED_PHONE_DIAL */ +#define LED_DIAL_HOLDING 2 /* for SHARP_LED_PHONE_DIAL */ + +#define LED_PHONE_WAITING 0 /* for SHARP_LED_PHONE_IN */ +#define LED_PHONE_INCOMING 1 /* for SHARP_LED_PHONE_IN */ + +#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ +#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ +#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ + +#define LED_SENDMAIL_OFF 0 /* for SHARP_LED_MAIL_SEND */ +#define LED_SENDMAIL_SENDING 1 /* for SHARP_LED_MAIL_SEND */ +#define LED_SENDMAIL_ERROR 2 /* for SHARP_LED_MAIL_SEND */ + +#define LED_MAILQUEUE_NOUNREAD 0 /* for SHARP_LED_MAIL_QUEUE */ +#define LED_MAILQUEUE_NEWMAIL 1 /* for SHARP_LED_MAIL_QUEUE */ +#define LED_MAILQUEUE_UNREAD 2 /* for SHARP_LED_MAIL_QUEUE */ + +#define LED_COLLIE_0_DEFAULT 0 /* for SHARP_LED_COLLIE_0 */ +#define LED_COLLIE_0_OFF 1 /* for SHARP_LED_COLLIE_0 */ +#define LED_COLLIE_0_ON 2 /* for SHARP_LED_COLLIE_0 */ +#define LED_COLLIE_0_FASTBLINK 3 /* for SHARP_LED_COLLIE_0 */ +#define LED_COLLIE_0_SLOWBLINK 4 /* for SHARP_LED_COLLIE_0 */ + + +#define LED_COLLIE_1_DEFAULT 0 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_OFF 1 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_ON 2 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_FLASHON 3 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_FLASHOFF 4 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_VFSTBLINK 5 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_FASTBLINK 6 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_NORMBLINK 7 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_SLOWBLINK 8 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_SOFTBLINK 9 /* for SHARP_LED_COLLIE_1 */ +#define LED_COLLIE_1_SOFTFLASH 10 /* for SHARP_LED_COLLIE_1 */ + +/* --- for SHARP_BUZZER device --- */ +#define SHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) +#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) +#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) +#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) +#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) +#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) +#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) + +typedef struct sharp_buzzer_status { /* this struct is used for setvolume/getvolume */ + int which; /* select which LED status is wanted. */ + int volume; /* set new buzzer volume if you call SHARP_BUZZER_SETVOLUME */ + int mute; /* set 1 to MUTE if you call SHARP_BUZZER_SETMUTE */ +} sharp_buzzer_status; + +#define SHARP_BUZ_WHICH_MAX 14 /* last number of buzzer */ + +#define SHARP_BUZ_ALL_SOUNDS -1 /* for setting volumes of ALL sounds at a time */ + +#define SHARP_BUZ_WRITESOUND 0 /* for sound datas through 'write' calls */ +#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ +#define SHARP_BUZ_KEYSOUND 2 /* key sound */ +#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ +#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ +#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ +#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ +#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ +#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ +#define SHARP_PDA_APPSTART 9 /* application start */ +#define SHARP_PDA_APPQUIT 10 /* application ends */ +#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ +#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ +#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ +#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ + +#define SHARP_BUZ_VOLUME_OFF 0 +#define SHARP_BUZ_VOLUME_LOW 33 +#define SHARP_BUZ_VOLUME_MEDIUM 67 +#define SHARP_BUZ_VOLUME_HIGH 100 /* currentry , this is the maximum ... */ +#define SHARP_BUZ_VOLUME_MAX (SHARP_BUZ_VOLUME_HIGH) + +/* --- for SHARP_GSM device --- */ +#define SHARP_GSM_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) +#define SHARP_GSM_GETEXTSTATUS (SHARP_GSM_IOCTL_START+16) +#define SHARP_GSM_INFO_TELL_MODE (SHARP_GSM_IOCTL_START+17) + +#define GSM_PHONE_NO_POWER 0 /* for SHARP_GSM_INFO_TELL_MODE */ +#define GSM_PHONE_NO_CONNECTION 1 /* for SHARP_GSM_INFO_TELL_MODE */ +#define GSM_PHONE_IN_ANALOG_MODE 2 /* for SHARP_GSM_INFO_TELL_MODE */ +#define GSM_PHONE_IN_DATA_MODE 3 /* for SHARP_GSM_INFO_TELL_MODE */ + +typedef struct sharp_gsmext_status { + int carkit; /* be set as 1 , if car-kit is connected */ + int headphone_mic; /* be set as 1 , if head-phone-microphone is inserted */ +} sharp_gsmext_status; + +/* --- for SHARP_AUDIOCTL device --- */ +#define SHARP_AUDIOCTL_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) +#define SHARP_AUDIOCTL_ARCH_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START+0x10) +#define SHARP_IRIS_AUFIL_GETVAL (SHARP_AUDIOCTL_ARCH_IOCTL_START+0) +#define SHARP_IRIS_AUFIL_SETVAL (SHARP_AUDIOCTL_ARCH_IOCTL_START+1) +#define SHARP_IRIS_AMP_EXT_ON (SHARP_AUDIOCTL_ARCH_IOCTL_START+2) +#define SHARP_IRIS_AMP_EXT_OFF (SHARP_AUDIOCTL_ARCH_IOCTL_START+3) + + +#define SHARP_IRIS_AUFIL_FILTERON 0x01 /* Iris AudioCtl Specific. Enable Audio Filter */ + +/* --- for SHARP_AUDIOCTL device --- */ +#define SHARP_KBDCTL_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) +#define SHARP_KBDCTL_GETMODIFSTAT (SHARP_KBDCTL_IOCTL_START+0) +#define SHARP_KBDCTL_TOGGLEMODIFSTAT (SHARP_KBDCTL_IOCTL_START+1) +#define SHARP_KBDCTL_SETHOLDTH (SHARP_KBDCTL_IOCTL_START+2) +#define SHARP_KBDCTL_SETHOLDTH_GR (SHARP_KBDCTL_IOCTL_START+3) +#define SHARP_KBDCTL_HOLDINFO_SETHD (SHARP_KBDCTL_IOCTL_START+4) +#define SHARP_KBDCTL_HOLDINFO_SETSL (SHARP_KBDCTL_IOCTL_START+5) +#define SHARP_KBDCTL_HOLDINFO_DELHD (SHARP_KBDCTL_IOCTL_START+6) +#define SHARP_KBDCTL_HOLDINFO_DELSL (SHARP_KBDCTL_IOCTL_START+7) +#define SHARP_KBDCTL_HOLDINFO_RESTHD (SHARP_KBDCTL_IOCTL_START+8) +#define SHARP_KBDCTL_HOLDINFO_RESTSL (SHARP_KBDCTL_IOCTL_START+9) +#define SHARP_KBDCTL_HOLDINFO_RESTFULL (SHARP_KBDCTL_IOCTL_START+10) + +typedef struct sharp_kbdctl_modifstat { + int which; + int stat; +} sharp_kbdctl_modifstat; + +typedef struct sharp_kbdctl_holdstat { + int group; + int timeout; +} sharp_kbdctl_holdstat; + +typedef struct sharp_kbdctl_holdcustom { + int normal_hardcode; + int normal_slcode; + int hold_slcode; +} sharp_kbdctl_holdcustom; + +#define SHARP_EXTMODIF_2ND 0x01 +#define SHARP_EXTMODIF_CAPS 0x02 +#define SHARP_EXTMODIF_NUMLOCK 0x03 + +#define HOLDKEY_GROUP_NORMAL 0 +#define HOLDKEY_GROUP_POWER 1 + +#endif /* __ASM_SHARP_CHAR_H_INCLUDED */ + diff --git a/noncore/unsupported/mail2/libmail/smtphandler.cpp b/noncore/unsupported/mail2/libmail/smtphandler.cpp new file mode 100644 index 0000000..1bbad8b --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/smtphandler.cpp @@ -0,0 +1,172 @@ +#warning "TODO: XXX This class needs to be rewritten. XXX" + +#include <qsocket.h> +#include <qtimer.h> +#include <qfile.h> +#include <qdatetime.h> +#include <qdir.h> +#include <qregexp.h> + +#include <qpe/mimetype.h> +#include <qpe/config.h> + +#include <stdlib.h> + +#include "smtphandler.h" +#include "miscfunctions.h" + +SmtpHandler::SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to) + : QObject(), _header(header), _message(message), _account(account), _to(to) +{ + _header.replace(QRegExp("\\n"), "\r\n"); + _message.replace(QRegExp("\\n"), "\r\n"); + _message.replace(QRegExp("\\r\\n\\.\\r\\n"), "\r\n..\r\n"); + +// _state = account.esmtpAuth() ? Ehlo : Helo; + _state = Helo; + + _socket = new QSocket(this); + connect(_socket, SIGNAL(hostFound()), this, SLOT(hostFound())); + connect(_socket, SIGNAL(connected()), this, SLOT(connected())); + connect(_socket, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(_socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); + + _socket->connectToHost(account.smtpServer(), account.smtpPort().toUInt()); + emit status(tr("Looking up host...")); +} + +void SmtpHandler::errorHandling(int err) +{ + if (err == QSocket::ErrConnectionRefused) { + emit error(tr("The server refused the connection.")); + } else if (err == QSocket::ErrHostNotFound) { + emit error(tr("Host lookup failed.")); + } else if (err == QSocket::ErrSocketRead) { + emit error(tr("The read from the socket failed for an unknown reason.")); + } else { + emit error(tr("The sending failed for an unknown reason.")); + } + stop(); +} + +void SmtpHandler::hostFound() +{ + emit status(tr("Host found.")); +} + +void SmtpHandler::connected() +{ + emit status(tr("Connected to %1").arg(_socket->peerName())); +} + +void SmtpHandler::readyRead() +{ + if (!_socket->canReadLine()) return; + if (_state == Close) stop(); + + QString response = _socket->readLine(); + QString temp = response; + temp.truncate(3); + int responseCode = temp.toInt(); + +#ifndef QT_NO_DEBUG + qDebug(tr("SMTP > %3").arg(response.stripWhiteSpace())); +#endif + + response.replace(0, 4, ""); + response.stripWhiteSpace(); + + if (_state == Ehlo && responseCode == 220) { + QString hostname = getenv("HOSTNAME"); + if (hostname.stripWhiteSpace().isEmpty()) + hostname = "opiemail"; + + emit status(tr("SMTP> EHLO *")); + sendToSocket(QString("EHLO %1\r\n").arg(hostname)); + _state = Auth; + } else if (_state == Auth && responseCode == 250) { + QStringList capabilities; + while (_socket->canReadLine()) { + QString line = _socket->readLine().stripWhiteSpace(); + capabilities.append(line); + } + + // FIXME: Dirty, quick hack! + if (!capabilities.grep(QRegExp("^250-AUTH=LOGIN.*CRAM-MD5.*$")).isEmpty()) { +// emit errorOccourred(ErrAuthNotSupported); + _state = Mail; + } else { + emit status(tr("SMTP> AUTH CRAM-MD5")); + sendToSocket("AUTH CRAM-MD5\r\n"); + _state = ReadAuth; + } + } else if (_state == ReadAuth && responseCode == 334) { + QString msgId = MiscFunctions::decodeBase64(response); + + QString authString; + authString = _account.user() + " " + + MiscFunctions::smtpAuthCramMd5(msgId, _account.pass()); + authString = MiscFunctions::encodeBase64(authString); + + emit status(tr("SMTP> Authenticating")); + sendToSocket(authString + "\r\n"); + + _state = Mail; + } else if (_state == Helo && responseCode == 220) { + QString hostname = getenv("HOSTNAME"); + if (hostname.stripWhiteSpace().isEmpty()) + hostname = "opiemail"; + + emit status(tr("SMTP> HELO *")); + sendToSocket(QString("HELO %1\r\n").arg(hostname)); + _state = Mail; + } else if (_state == Mail && responseCode == 250) { + emit status(tr("SMTP> MAIL FROM: *")); + sendToSocket("MAIL FROM: " + _account.email() + "\r\n"); + _state = Rcpt; + } else if (_state == Rcpt && responseCode == 250) { + emit status(tr("SMTP> RCPT TO: *")); + sendToSocket("RCPT TO: " + _to + "\r\n"); + _state = Data; + } else if (_state == Data && responseCode == 250) { + emit status(tr("SMTP> DATA")); + sendToSocket("DATA\r\n"); + _state = Body; + } else if (_state == Body && responseCode == 354) { + emit status(tr("SMTP> Sending data...")); + sendToSocket(_header + "\r\n" + _message + "\r\n.\r\n", false); + _state = Quit; + } else if (_state == Quit) { + emit status(tr("SMTP> QUIT (Done)")); + sendToSocket("QUIT\r\n"); + _state = Close; + } else if (_state == Close) { + + } else { + emit error(tr("The server returned an error. This is the message:<br>%1").arg(response)); + stop(); + } +} + +void SmtpHandler::sendToSocket(const QString &text, bool log) +{ + _socket->writeBlock(text.latin1(), text.length()); + + if (log) { +#ifndef QT_NO_DEBUG + qDebug(tr("SMTP < %3").arg(text.stripWhiteSpace())); +#endif + } +} + +void SmtpHandler::stop() +{ + emit finished(); + QTimer::singleShot(0, this, SLOT(deleteMe())); +} + +void SmtpHandler::deleteMe() +{ + delete this; +} + diff --git a/noncore/unsupported/mail2/libmail/smtphandler.h b/noncore/unsupported/mail2/libmail/smtphandler.h new file mode 100644 index 0000000..abbcbcd --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/smtphandler.h @@ -0,0 +1,55 @@ +#ifndef SMTPHANDLER_H +#define SMTPHANDLER_H + +#include <qobject.h> +#include <qstring.h> + +#include "configfile.h" + +class QSocket; + +class SmtpHandler : public QObject +{ + Q_OBJECT + +public: + SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to); + + enum SmtpError { + ErrConnectionRefused, + ErrHostNotFound, + ErrUnknownResponse, + ErrAuthNotSupported + }; + +public slots: + void stop(); + +signals: + void finished(); + void error(const QString &); + void status(const QString &); + +private slots: + void readyRead(); + void hostFound(); + void connected(); + void deleteMe(); + void errorHandling(int); + +private: + void sendToSocket(const QString &text, bool log = true); + + enum State { Ehlo, Auth, ReadAuth, Helo, Mail, Rcpt, + Data, Body, Quit, Close }; + + QString _header, _message; + Account _account; + QString _to; + QSocket *_socket; + int _state; +}; + +#endif + + diff --git a/noncore/unsupported/mail2/libmail/zaurusstuff.cpp b/noncore/unsupported/mail2/libmail/zaurusstuff.cpp new file mode 100644 index 0000000..bbf1541 --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/zaurusstuff.cpp @@ -0,0 +1,38 @@ +#include <sys/ioctl.h> +#include <fcntl.h> +#include <stdio.h> + +#include "zaurusstuff.h" +#include "sharp_char.h" + +ZaurusStuff::ZaurusStuff() : QObject() +{ + +} + +void ZaurusStuff::blinkLedOn() +{ + sharp_led_status st; + st.which = SHARP_LED_COLLIE_1; + st.status = LED_COLLIE_1_FLASHON; + ioctl(open("/dev/sharp_led", O_WRONLY), SHARP_LED_SETSTATUS, &st); +} + +void ZaurusStuff::blinkLedOff() +{ + sharp_led_status st; + st.which = SHARP_LED_COLLIE_1; + st.status = LED_COLLIE_1_DEFAULT; + ioctl(open("/dev/sharp_led", O_WRONLY), SHARP_LED_SETSTATUS, &st); +} + +void ZaurusStuff::buzzerOn() +{ + ioctl(open("/dev/sharp_buz", O_WRONLY), SHARP_BUZZER_MAKESOUND, 4); +} + +void ZaurusStuff::buzzerOff() +{ + +} + diff --git a/noncore/unsupported/mail2/libmail/zaurusstuff.h b/noncore/unsupported/mail2/libmail/zaurusstuff.h new file mode 100644 index 0000000..33c65da --- a/dev/null +++ b/noncore/unsupported/mail2/libmail/zaurusstuff.h @@ -0,0 +1,23 @@ +#ifndef ZAURUSSTUFF_H +#define ZAURUSSTUFF_H + +#include <qobject.h> + +class ZaurusStuff : public QObject +{ + Q_OBJECT + +public: + static void blinkLedOn(); + static void blinkLedOff(); + static void buzzerOn(); + static void buzzerOff(); + +protected: + ZaurusStuff(); + + +}; + +#endif + |