-rw-r--r-- | noncore/net/mail/libmailwrapper/nntpwrapper.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp index e73a890..c68964d 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp @@ -95,147 +95,161 @@ RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { 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, + 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); + err = mailstorage_connect( m_nntp ); - if (err != NEWSNNTP_NO_ERROR) { + 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; + 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","/"); - + QList<Folder> * folders = new QList<Folder>(); + folders->setAutoDelete( false ); + clist *result = 0; + clistcell *current; + newsnntp_group_description *list; + + login(); + if ( m_nntp ) { + mailsession * session = m_nntp->sto_session; + newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; + int err = newsnntp_list_newsgroups(news, NULL, &result); + + if ( err == NEWSNNTP_NO_ERROR ) { + current = result->first; + for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { + list = ( newsnntp_group_description* ) current->data; + qDebug( list->grp_name ); + } +// 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*) { } |