author | harlekin <harlekin> | 2004-02-29 21:55:06 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-02-29 21:55:06 (UTC) |
commit | dcf152e23f7cc85fe2e46521e07b64e2288efdda (patch) (side-by-side diff) | |
tree | 8aac8095aed8dc9a9efab7005b8f1c53cce82536 /noncore/net/mail/libmailwrapper | |
parent | 225b92ec28bbe3a9368e8534323a3c335432e447 (diff) | |
download | opie-dcf152e23f7cc85fe2e46521e07b64e2288efdda.zip opie-dcf152e23f7cc85fe2e46521e07b64e2288efdda.tar.gz opie-dcf152e23f7cc85fe2e46521e07b64e2288efdda.tar.bz2 |
beginning of nntp stuff
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 10 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/libmailwrapper.pro | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/nntpwrapper.cpp | 241 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/nntpwrapper.h | 48 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 6 |
6 files changed, 305 insertions, 7 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 592cd5e..741a8e1 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp @@ -1,9 +1,10 @@ #include "abstractmail.h" #include "imapwrapper.h" #include "pop3wrapper.h" +#include "nntpwrapper.h" #include "mhwrapper.h" #include "mboxwrapper.h" #include "mailtypes.h" #include <qstring.h> #include <qfile.h> @@ -19,12 +20,17 @@ AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) AbstractMail* AbstractMail::getWrapper(POP3account *a) { return new POP3wrapper(a); } +AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) +{ + return new NNTPwrapper(a); +} + AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) { return new MHwrapper(a,name); } encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) @@ -45,26 +51,26 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin } else if (enc.lower()=="binary") { mimetype = MAILMIME_MECHANISM_BINARY; } int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, &result_text,&target_length); - + encodedString* result = new encodedString(); if (err == MAILIMF_NO_ERROR) { result->setContent(result_text,target_length); } qDebug("Decode string finished"); return result; } QString AbstractMail::convert_String(const char*text) { size_t index = 0; char*res = 0; - + /* attention - doesn't work with arm systems! */ int err = mailmime_encoded_phrase_parse("iso-8859-1", text, strlen(text),&index, "iso-8859-1",&res); if (err != MAILIMF_NO_ERROR) { if (res) free(res); return QString(text); diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index f93bab4..b6e1538 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -46,12 +46,13 @@ public: */ virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); virtual void logout()=0; static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); + static AbstractMail* getWrapper(NNTPaccount *a); /* mbox only! */ static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); static QString defaultLocalfolder(); virtual const QString&getType()const=0; diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro index 71f6cca..8ea04a4 100644 --- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro +++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro @@ -10,13 +10,14 @@ HEADERS = mailwrapper.h \ genericwrapper.h \ mboxwrapper.h \ settings.h \ logindialog.h \ sendmailprogress.h \ statusmail.h \ - mhwrapper.h + mhwrapper.h \ + nntpwrapper.h SOURCES = imapwrapper.cpp \ mailwrapper.cpp \ mailtypes.cpp \ pop3wrapper.cpp \ abstractmail.cpp \ @@ -24,13 +25,14 @@ SOURCES = imapwrapper.cpp \ genericwrapper.cpp \ mboxwrapper.cpp \ settings.cpp \ logindialog.cpp \ sendmailprogress.cpp \ statusmail.cpp \ - mhwrapper.cpp + mhwrapper.cpp \ + nntpwrapper.cpp INTERFACES = logindialogui.ui \ sendmailprogressui.ui INCLUDEPATH += $(OPIEDIR)/include diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp new file mode 100644 index 0000000..e73a890 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp @@ -0,0 +1,241 @@ +#include "nntpwrapper.h" +#include "logindialog.h" +#include "mailtypes.h" + +#include <qfile.h> + +#include <stdlib.h> + +#include <libetpan/libetpan.h> +#include <libetpan/nntpdriver.h> + + + +#define HARD_MSG_SIZE_LIMIT 5242880 + +NNTPwrapper::NNTPwrapper( NNTPaccount *a ) +: Genericwrapper() { + account = a; + m_nntp = NULL; + msgTempName = a->getFileName()+"_msg_cache"; + last_msg_id = 0; +} + +NNTPwrapper::~NNTPwrapper() { + logout(); + QFile msg_cache(msgTempName); + if (msg_cache.exists()) { + msg_cache.remove(); + } +} + +void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { + qDebug( "NNTP: %i of %i", current, maximum ); +} + + +RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { + int err = NEWSNNTP_NO_ERROR; + char *message = 0; + size_t length = 0; + + login(); + if ( !m_nntp ) { + return RecBody(); + } + + RecBody body; + mailmessage * mailmsg; + if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { + qDebug("Message to large: %i",mail.Msgsize()); + return body; + } + + QFile msg_cache(msgTempName); + + cleanMimeCache(); + + if (mail.getNumber()!=last_msg_id) { + if (msg_cache.exists()) { + msg_cache.remove(); + } + msg_cache.open(IO_ReadWrite|IO_Truncate); + last_msg_id = mail.getNumber(); + err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); + err = mailmessage_fetch(mailmsg,&message,&length); + msg_cache.writeBlock(message,length); + } else { + QString msg=""; + msg_cache.open(IO_ReadOnly); + message = new char[4096]; + memset(message,0,4096); + while (msg_cache.readBlock(message,4095)>0) { + msg+=message; + memset(message,0,4096); + } + delete message; + message = (char*)malloc(msg.length()+1*sizeof(char)); + memset(message,0,msg.length()+1); + memcpy(message,msg.latin1(),msg.length()); + /* transform to libetpan stuff */ + mailmsg = mailmessage_new(); + mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); + generic_message_t * msg_data; + msg_data = (generic_message_t *)mailmsg->msg_data; + msg_data->msg_fetched = 1; + msg_data->msg_message = message; + msg_data->msg_length = strlen(message); + } + body = parseMail(mailmsg); + + /* clean up */ + if (mailmsg) + mailmessage_free(mailmsg); + if (message) + free(message); + + return body; +} + + +void NNTPwrapper::listMessages(const QString &, QList<RecMail> &target ) +{ + login(); + if (!m_nntp) + return; + uint32_t res_messages,res_recent,res_unseen; + mailsession_status_folder(m_nntp->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); + parseList(target,m_nntp->sto_session,"INBOX"); +} + +void NNTPwrapper::login() +{ + if (account->getOffline()) + return; + /* we'll hold the line */ + if ( m_nntp != NULL ) + return; + + const char *server, *user, *pass; + uint16_t port; + int err = NEWSNNTP_NO_ERROR; + + server = account->getServer().latin1(); + port = account->getPort().toUInt(); + + if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { + LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); + login.show(); + if ( QDialog::Accepted == login.exec() ) { + // ok + user = login.getUser().latin1(); + pass = login.getPassword().latin1(); + } else { + // cancel + qDebug( "NNTP: Login canceled" ); + return; + } + } else { + user = account->getUser().latin1(); + pass = account->getPassword().latin1(); + } + + // bool ssl = account->getSSL(); + + m_nntp=mailstorage_new(NULL); + + int conntypeset = account->ConnectionType(); + int conntype = 0; + if ( conntypeset == 3 ) { + conntype = CONNECTION_TYPE_COMMAND; + } else if ( conntypeset == 2 ) { + conntype = CONNECTION_TYPE_TLS; + } else if ( conntypeset == 1 ) { + conntype = CONNECTION_TYPE_STARTTLS; + } else if ( conntypeset == 0 ) { + conntype = CONNECTION_TYPE_TRY_STARTTLS; + } + + nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, conntype, NNTP_AUTH_TYPE_PLAIN, + (char*)user,(char*)pass,0,0,0); + + err = mailstorage_connect(m_nntp); + + if (err != NEWSNNTP_NO_ERROR) { + qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); + // Global::statusMessage(tr("Error initializing folder")); + mailstorage_free(m_nntp); + m_nntp = 0; + } +} + +void NNTPwrapper::logout() +{ + int err = NEWSNNTP_NO_ERROR; + if ( m_nntp == NULL ) + return; + mailstorage_free(m_nntp); + m_nntp = 0; +} + +QList<Folder>* NNTPwrapper::listFolders() { + QList<Folder> * folders = new QList<Folder>(); + folders->setAutoDelete( false ); + clist *result = 0; + + // int err = +// if ( err == _NO_ERROR ) { +// current = result->first; +// for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { + + +// Folder*inb=new Folder("INBOX","/"); + + +// folders->append(inb); + return folders; +} + + +void NNTPwrapper::answeredMail(const RecMail&) {} + +void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { + login(); + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + if (!m_nntp) + return; + int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, + &target_stat.message_recent,&target_stat.message_unseen); +} + + +encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { + char*target=0; + size_t length=0; + encodedString*res = 0; + mailmessage * mailmsg = 0; + int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); + err = mailmessage_fetch(mailmsg,&target,&length); + if (mailmsg) + mailmessage_free(mailmsg); + if (target) { + res = new encodedString(target,length); + } + return res; +} + +const QString&NNTPwrapper::getType()const { + return account->getType(); +} + +const QString&NNTPwrapper::getName()const{ + return account->getAccountName(); +} + +void NNTPwrapper::deleteMail(const RecMail&mail) { +} + +int NNTPwrapper::deleteAllMail(const Folder*) { +} diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.h b/noncore/net/mail/libmailwrapper/nntpwrapper.h new file mode 100644 index 0000000..e47e68f --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.h @@ -0,0 +1,48 @@ +#ifndef __NNTPWRAPPER +#define __NNTPWRAPPER + +#include "mailwrapper.h" +#include "genericwrapper.h" +#include <qstring.h> +#include <libetpan/clist.h> + +class encodedString; +struct mailstorage; +struct mailfolder; + +class NNTPwrapper : public Genericwrapper +{ + + Q_OBJECT + +public: + NNTPwrapper( NNTPaccount *a ); + virtual ~NNTPwrapper(); + + /* mailbox will be ignored */ + virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); + /* should only get the subscribed one */ + virtual QList<Folder>* listFolders(); + /* mailbox will be ignored */ + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); + + virtual void deleteMail(const RecMail&mail); + virtual void answeredMail(const RecMail&mail); + virtual int deleteAllMail(const Folder*); + + virtual RecBody fetchBody( const RecMail &mail ); + virtual encodedString* fetchRawBody(const RecMail&mail); + virtual void logout(); + virtual const QString&getType()const; + virtual const QString&getName()const; + static void nntp_progress( size_t current, size_t maximum ); + +protected: + void login(); + NNTPaccount *account; + mailstorage* m_nntp; + + +}; + +#endif diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 14c2059..6fab401 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -2,13 +2,13 @@ #include "pop3wrapper.h" #include "mailtypes.h" #include "logindialog.h" #include <libetpan/libetpan.h> #include <qpe/global.h> #include <qfile.h> -#include <qstring.h> +//#include <qstring.h> /* we don't fetch messages larger than 5 MB */ #define HARD_MSG_SIZE_LIMIT 5242880 POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { @@ -90,13 +90,13 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) { if (message) free(message); return body; } -void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) +void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { login(); if (!m_pop3) return; uint32_t res_messages,res_recent,res_unseen; mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); @@ -164,13 +164,13 @@ void POP3wrapper::login() Global::statusMessage(tr("Error initializing folder")); mailstorage_free(m_pop3); m_pop3 = 0; } } -void POP3wrapper::logout() +void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; mailstorage_free(m_pop3); m_pop3 = 0; |