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