summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp10
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h1
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro6
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.cpp241
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.h48
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp6
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
@@ -3,2 +3,3 @@
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "nntpwrapper.h"
4#include "mhwrapper.h" 5#include "mhwrapper.h"
@@ -24,2 +25,7 @@ AbstractMail* AbstractMail::getWrapper(POP3account *a)
24 25
26AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
27{
28 return new NNTPwrapper(a);
29}
30
25AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 31AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
@@ -50,3 +56,3 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin
50 &result_text,&target_length); 56 &result_text,&target_length);
51 57
52 encodedString* result = new encodedString(); 58 encodedString* result = new encodedString();
@@ -63,3 +69,3 @@ QString AbstractMail::convert_String(const char*text)
63 char*res = 0; 69 char*res = 0;
64 70
65 /* attention - doesn't work with arm systems! */ 71 /* attention - doesn't work with arm systems! */
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
@@ -51,2 +51,3 @@ public:
51 static AbstractMail* getWrapper(POP3account *a); 51 static AbstractMail* getWrapper(POP3account *a);
52 static AbstractMail* getWrapper(NNTPaccount *a);
52 /* mbox only! */ 53 /* mbox only! */
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
@@ -15,3 +15,4 @@ HEADERS = mailwrapper.h \
15 statusmail.h \ 15 statusmail.h \
16 mhwrapper.h 16 mhwrapper.h \
17 nntpwrapper.h
17 18
@@ -29,3 +30,4 @@ SOURCES = imapwrapper.cpp \
29 statusmail.cpp \ 30 statusmail.cpp \
30 mhwrapper.cpp 31 mhwrapper.cpp \
32 nntpwrapper.cpp
31 33
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 @@
1#include "nntpwrapper.h"
2#include "logindialog.h"
3#include "mailtypes.h"
4
5#include <qfile.h>
6
7#include <stdlib.h>
8
9#include <libetpan/libetpan.h>
10#include <libetpan/nntpdriver.h>
11
12
13
14#define HARD_MSG_SIZE_LIMIT 5242880
15
16NNTPwrapper::NNTPwrapper( NNTPaccount *a )
17: Genericwrapper() {
18 account = a;
19 m_nntp = NULL;
20 msgTempName = a->getFileName()+"_msg_cache";
21 last_msg_id = 0;
22}
23
24NNTPwrapper::~NNTPwrapper() {
25 logout();
26 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) {
28 msg_cache.remove();
29 }
30}
31
32void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) {
33 qDebug( "NNTP: %i of %i", current, maximum );
34}
35
36
37RecBody NNTPwrapper::fetchBody( const RecMail &mail ) {
38 int err = NEWSNNTP_NO_ERROR;
39 char *message = 0;
40 size_t length = 0;
41
42 login();
43 if ( !m_nntp ) {
44 return RecBody();
45 }
46
47 RecBody body;
48 mailmessage * mailmsg;
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize());
51 return body;
52 }
53
54 QFile msg_cache(msgTempName);
55
56 cleanMimeCache();
57
58 if (mail.getNumber()!=last_msg_id) {
59 if (msg_cache.exists()) {
60 msg_cache.remove();
61 }
62 msg_cache.open(IO_ReadWrite|IO_Truncate);
63 last_msg_id = mail.getNumber();
64 err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg);
65 err = mailmessage_fetch(mailmsg,&message,&length);
66 msg_cache.writeBlock(message,length);
67 } else {
68 QString msg="";
69 msg_cache.open(IO_ReadOnly);
70 message = new char[4096];
71 memset(message,0,4096);
72 while (msg_cache.readBlock(message,4095)>0) {
73 msg+=message;
74 memset(message,0,4096);
75 }
76 delete message;
77 message = (char*)malloc(msg.length()+1*sizeof(char));
78 memset(message,0,msg.length()+1);
79 memcpy(message,msg.latin1(),msg.length());
80 /* transform to libetpan stuff */
81 mailmsg = mailmessage_new();
82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
83 generic_message_t * msg_data;
84 msg_data = (generic_message_t *)mailmsg->msg_data;
85 msg_data->msg_fetched = 1;
86 msg_data->msg_message = message;
87 msg_data->msg_length = strlen(message);
88 }
89 body = parseMail(mailmsg);
90
91 /* clean up */
92 if (mailmsg)
93 mailmessage_free(mailmsg);
94 if (message)
95 free(message);
96
97 return body;
98}
99
100
101void NNTPwrapper::listMessages(const QString &, QList<RecMail> &target )
102{
103 login();
104 if (!m_nntp)
105 return;
106 uint32_t res_messages,res_recent,res_unseen;
107 mailsession_status_folder(m_nntp->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
108 parseList(target,m_nntp->sto_session,"INBOX");
109}
110
111void NNTPwrapper::login()
112{
113 if (account->getOffline())
114 return;
115 /* we'll hold the line */
116 if ( m_nntp != NULL )
117 return;
118
119 const char *server, *user, *pass;
120 uint16_t port;
121 int err = NEWSNNTP_NO_ERROR;
122
123 server = account->getServer().latin1();
124 port = account->getPort().toUInt();
125
126 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
127 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
128 login.show();
129 if ( QDialog::Accepted == login.exec() ) {
130 // ok
131 user = login.getUser().latin1();
132 pass = login.getPassword().latin1();
133 } else {
134 // cancel
135 qDebug( "NNTP: Login canceled" );
136 return;
137 }
138 } else {
139 user = account->getUser().latin1();
140 pass = account->getPassword().latin1();
141 }
142
143 // bool ssl = account->getSSL();
144
145 m_nntp=mailstorage_new(NULL);
146
147 int conntypeset = account->ConnectionType();
148 int conntype = 0;
149 if ( conntypeset == 3 ) {
150 conntype = CONNECTION_TYPE_COMMAND;
151 } else if ( conntypeset == 2 ) {
152 conntype = CONNECTION_TYPE_TLS;
153 } else if ( conntypeset == 1 ) {
154 conntype = CONNECTION_TYPE_STARTTLS;
155 } else if ( conntypeset == 0 ) {
156 conntype = CONNECTION_TYPE_TRY_STARTTLS;
157 }
158
159 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, conntype, NNTP_AUTH_TYPE_PLAIN,
160 (char*)user,(char*)pass,0,0,0);
161
162 err = mailstorage_connect(m_nntp);
163
164 if (err != NEWSNNTP_NO_ERROR) {
165 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
166 // Global::statusMessage(tr("Error initializing folder"));
167 mailstorage_free(m_nntp);
168 m_nntp = 0;
169 }
170}
171
172void NNTPwrapper::logout()
173{
174 int err = NEWSNNTP_NO_ERROR;
175 if ( m_nntp == NULL )
176 return;
177 mailstorage_free(m_nntp);
178 m_nntp = 0;
179}
180
181QList<Folder>* NNTPwrapper::listFolders() {
182 QList<Folder> * folders = new QList<Folder>();
183 folders->setAutoDelete( false );
184 clist *result = 0;
185
186 // int err =
187// if ( err == _NO_ERROR ) {
188// current = result->first;
189// for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
190
191
192// Folder*inb=new Folder("INBOX","/");
193
194
195// folders->append(inb);
196 return folders;
197}
198
199
200void NNTPwrapper::answeredMail(const RecMail&) {}
201
202void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
203 login();
204 target_stat.message_count = 0;
205 target_stat.message_unseen = 0;
206 target_stat.message_recent = 0;
207 if (!m_nntp)
208 return;
209 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
210 &target_stat.message_recent,&target_stat.message_unseen);
211}
212
213
214encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) {
215 char*target=0;
216 size_t length=0;
217 encodedString*res = 0;
218 mailmessage * mailmsg = 0;
219 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg);
220 err = mailmessage_fetch(mailmsg,&target,&length);
221 if (mailmsg)
222 mailmessage_free(mailmsg);
223 if (target) {
224 res = new encodedString(target,length);
225 }
226 return res;
227}
228
229const QString&NNTPwrapper::getType()const {
230 return account->getType();
231}
232
233const QString&NNTPwrapper::getName()const{
234 return account->getAccountName();
235}
236
237void NNTPwrapper::deleteMail(const RecMail&mail) {
238}
239
240int NNTPwrapper::deleteAllMail(const Folder*) {
241}
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 @@
1#ifndef __NNTPWRAPPER
2#define __NNTPWRAPPER
3
4#include "mailwrapper.h"
5#include "genericwrapper.h"
6#include <qstring.h>
7#include <libetpan/clist.h>
8
9class encodedString;
10struct mailstorage;
11struct mailfolder;
12
13class NNTPwrapper : public Genericwrapper
14{
15
16 Q_OBJECT
17
18public:
19 NNTPwrapper( NNTPaccount *a );
20 virtual ~NNTPwrapper();
21
22 /* mailbox will be ignored */
23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
24 /* should only get the subscribed one */
25 virtual QList<Folder>* listFolders();
26 /* mailbox will be ignored */
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
28
29 virtual void deleteMail(const RecMail&mail);
30 virtual void answeredMail(const RecMail&mail);
31 virtual int deleteAllMail(const Folder*);
32
33 virtual RecBody fetchBody( const RecMail &mail );
34 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void logout();
36 virtual const QString&getType()const;
37 virtual const QString&getName()const;
38 static void nntp_progress( size_t current, size_t maximum );
39
40protected:
41 void login();
42 NNTPaccount *account;
43 mailstorage* m_nntp;
44
45
46};
47
48#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
@@ -7,3 +7,3 @@
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h> 8//#include <qstring.h>
9 9
@@ -95,3 +95,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) {
95 95
96void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 96void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
97{ 97{
@@ -169,3 +169,3 @@ void POP3wrapper::login()
169 169
170void POP3wrapper::logout() 170void POP3wrapper::logout()
171{ 171{