summaryrefslogtreecommitdiff
authoralwin <alwin>2004-03-07 01:42:07 (UTC)
committer alwin <alwin>2004-03-07 01:42:07 (UTC)
commit9b3af0c792777462126317a0335d2c355b4d8b13 (patch) (unidiff)
tree5d6a7c478fff7d3931cbe5d28cf2d0e87d44b8ce
parent5bc69a9731634c55b9a01b9de6909201f422893b (diff)
downloadopie-9b3af0c792777462126317a0335d2c355b4d8b13.zip
opie-9b3af0c792777462126317a0335d2c355b4d8b13.tar.gz
opie-9b3af0c792777462126317a0335d2c355b4d8b13.tar.bz2
-resolved that not all newsgroups where listed
-resolved a memory leak -newsgroups list enhanced for usage with wildcards
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.h2
2 files changed, 17 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
index a766a59..5a8c224 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
@@ -77,195 +77,208 @@ RecBody NNTPwrapper::fetchBody( const RecMail &mail ) {
77 memcpy(message,msg.latin1(),msg.length()); 77 memcpy(message,msg.latin1(),msg.length());
78 /* transform to libetpan stuff */ 78 /* transform to libetpan stuff */
79 mailmsg = mailmessage_new(); 79 mailmsg = mailmessage_new();
80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
81 generic_message_t * msg_data; 81 generic_message_t * msg_data;
82 msg_data = (generic_message_t *)mailmsg->msg_data; 82 msg_data = (generic_message_t *)mailmsg->msg_data;
83 msg_data->msg_fetched = 1; 83 msg_data->msg_fetched = 1;
84 msg_data->msg_message = message; 84 msg_data->msg_message = message;
85 msg_data->msg_length = strlen(message); 85 msg_data->msg_length = strlen(message);
86 } 86 }
87 body = parseMail(mailmsg); 87 body = parseMail(mailmsg);
88 88
89 /* clean up */ 89 /* clean up */
90 if (mailmsg) 90 if (mailmsg)
91 mailmessage_free(mailmsg); 91 mailmessage_free(mailmsg);
92 if (message) 92 if (message)
93 free(message); 93 free(message);
94 94
95 return body; 95 return body;
96} 96}
97 97
98 98
99void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target ) 99void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_nntp) 102 if (!m_nntp)
103 return; 103 return;
104 uint32_t res_messages,res_recent,res_unseen; 104 uint32_t res_messages,res_recent,res_unseen;
105 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); 105 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
106 parseList(target,m_nntp->sto_session,which); 106 parseList(target,m_nntp->sto_session,which);
107} 107}
108 108
109void NNTPwrapper::login() 109void NNTPwrapper::login()
110{ 110{
111 if (account->getOffline()) 111 if (account->getOffline())
112 return; 112 return;
113 /* we'll hold the line */ 113 /* we'll hold the line */
114 if ( m_nntp != NULL ) 114 if ( m_nntp != NULL )
115 return; 115 return;
116 116
117 const char *server, *user, *pass; 117 const char *server, *user, *pass;
118 QString User,Pass; 118 QString User,Pass;
119 uint16_t port; 119 uint16_t port;
120 int err = NEWSNNTP_NO_ERROR; 120 int err = NEWSNNTP_NO_ERROR;
121 121
122 server = account->getServer().latin1(); 122 server = account->getServer().latin1();
123 port = account->getPort().toUInt(); 123 port = account->getPort().toUInt();
124 124
125 user = pass = 0; 125 user = pass = 0;
126 126
127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { 127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) {
128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
129 login.show(); 129 login.show();
130 if ( QDialog::Accepted == login.exec() ) { 130 if ( QDialog::Accepted == login.exec() ) {
131 // ok 131 // ok
132 User = login.getUser().latin1(); 132 User = login.getUser().latin1();
133 Pass = login.getPassword().latin1(); 133 Pass = login.getPassword().latin1();
134 } else { 134 } else {
135 // cancel 135 // cancel
136 qDebug( "NNTP: Login canceled" ); 136 qDebug( "NNTP: Login canceled" );
137 return; 137 return;
138 } 138 }
139 } else { 139 } else {
140 User = account->getUser().latin1(); 140 User = account->getUser().latin1();
141 Pass = account->getPassword().latin1(); 141 Pass = account->getPassword().latin1();
142 } 142 }
143 143
144 if (User.isEmpty()) { 144 if (User.isEmpty()) {
145 user=0; 145 user=0;
146 pass = 0; 146 pass = 0;
147 } else { 147 } else {
148 user=User.latin1(); 148 user=User.latin1();
149 pass=Pass.latin1(); 149 pass=Pass.latin1();
150 } 150 }
151 // bool ssl = account->getSSL(); 151 // bool ssl = account->getSSL();
152 152
153 m_nntp=mailstorage_new(NULL); 153 m_nntp=mailstorage_new(NULL);
154 154
155 int conntypeset = account->ConnectionType(); 155 int conntypeset = account->ConnectionType();
156 int conntype = 0; 156 int conntype = 0;
157 if ( conntypeset == 3 ) { 157 if ( conntypeset == 3 ) {
158 conntype = CONNECTION_TYPE_COMMAND; 158 conntype = CONNECTION_TYPE_COMMAND;
159 } else if ( conntypeset == 2 ) { 159 } else if ( conntypeset == 2 ) {
160 conntype = CONNECTION_TYPE_TLS; 160 conntype = CONNECTION_TYPE_TLS;
161 } else if ( conntypeset == 1 ) { 161 } else if ( conntypeset == 1 ) {
162 conntype = CONNECTION_TYPE_STARTTLS; 162 conntype = CONNECTION_TYPE_STARTTLS;
163 } else if ( conntypeset == 0 ) { 163 } else if ( conntypeset == 0 ) {
164 conntype = CONNECTION_TYPE_TRY_STARTTLS; 164 conntype = CONNECTION_TYPE_TRY_STARTTLS;
165 } 165 }
166 166
167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, 167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN,
168 (char*)user,(char*)pass,0,0,0); 168 (char*)user,(char*)pass,0,0,0);
169 169
170 err = mailstorage_connect( m_nntp ); 170 err = mailstorage_connect( m_nntp );
171 171
172 if (err != NEWSNNTP_NO_ERROR) { 172 if (err != NEWSNNTP_NO_ERROR) {
173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); 173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
174 // Global::statusMessage(tr("Error initializing folder")); 174 // Global::statusMessage(tr("Error initializing folder"));
175 mailstorage_free(m_nntp); 175 mailstorage_free(m_nntp);
176 m_nntp = 0; 176 m_nntp = 0;
177 177
178 } 178 }
179 179
180} 180}
181 181
182void NNTPwrapper::logout() 182void NNTPwrapper::logout()
183{ 183{
184 int err = NEWSNNTP_NO_ERROR; 184 int err = NEWSNNTP_NO_ERROR;
185 if ( m_nntp == NULL ) 185 if ( m_nntp == NULL )
186 return; 186 return;
187 mailstorage_free(m_nntp); 187 mailstorage_free(m_nntp);
188 m_nntp = 0; 188 m_nntp = 0;
189} 189}
190 190
191QList<Folder>* NNTPwrapper::listFolders() { 191QList<Folder>* NNTPwrapper::listFolders() {
192 192
193 QList<Folder> * folders = new QList<Folder>(); 193 QList<Folder> * folders = new QList<Folder>();
194 folders->setAutoDelete( false ); 194 folders->setAutoDelete( false );
195 QStringList groups; 195 QStringList groups;
196 if (account) { 196 if (account) {
197 groups = account->getGroups(); 197 groups = account->getGroups();
198 } 198 }
199 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { 199 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
200 folders->append(new Folder((*it),".")); 200 folders->append(new Folder((*it),"."));
201 } 201 }
202 return folders; 202 return folders;
203} 203}
204 204
205QStringList NNTPwrapper::listAllNewsgroups() { 205/* we made this method in raw nntp access of etpan and not via generic interface
206 * 'cause in that case there will be doubled copy operations. eg. the etpan would
207 * copy that stuff into its own structures and we must copy it into useable c++
208 * structures for our frontend. this would not make sense, so it is better to reimplement
209 * the stuff from generic interface of etpan but copy it direct to qt classes.
210 */
211QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) {
206 login(); 212 login();
207 QStringList res; 213 QStringList res;
208 clist *result = 0; 214 clist *result = 0;
209 clistcell *current = 0; 215 clistcell *current = 0;
210 newsnntp_group_description *group; 216 newsnntp_group_description *group;
211 217
212 if ( m_nntp ) { 218 if ( m_nntp ) {
213 mailsession * session = m_nntp->sto_session; 219 mailsession * session = m_nntp->sto_session;
214 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 220 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
215 int err = newsnntp_list_newsgroups(news, NULL, &result); 221 int err = NEWSNNTP_NO_ERROR;
222 if (mask.isEmpty()) {
223 err = newsnntp_list(news, &result);
224 } else {
225 /* taken from generic wrapper of etpan */
226 QString nmask = mask+".*";
227 err = newsnntp_list_active(news, nmask.latin1(), &result);
228 }
216 if ( err == NEWSNNTP_NO_ERROR && result) { 229 if ( err == NEWSNNTP_NO_ERROR && result) {
217 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { 230 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) {
218 group = ( newsnntp_group_description* ) current->data; 231 group = ( newsnntp_group_description* ) current->data;
219 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; 232 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue;
220 res.append(group->grp_name); 233 res.append(group->grp_name);
221 } 234 }
222 } 235 }
223 } 236 }
224 if (result) { 237 if (result) {
225 clist_free(result); 238 newsnntp_list_free(result);
226 } 239 }
227 return res; 240 return res;
228} 241}
229 242
230void NNTPwrapper::answeredMail(const RecMail&) {} 243void NNTPwrapper::answeredMail(const RecMail&) {}
231 244
232void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { 245void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
233 login(); 246 login();
234 target_stat.message_count = 0; 247 target_stat.message_count = 0;
235 target_stat.message_unseen = 0; 248 target_stat.message_unseen = 0;
236 target_stat.message_recent = 0; 249 target_stat.message_recent = 0;
237 if (!m_nntp) 250 if (!m_nntp)
238 return; 251 return;
239 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, 252 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
240 &target_stat.message_recent,&target_stat.message_unseen); 253 &target_stat.message_recent,&target_stat.message_unseen);
241} 254}
242 255
243 256
244encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { 257encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) {
245 char*target=0; 258 char*target=0;
246 size_t length=0; 259 size_t length=0;
247 encodedString*res = 0; 260 encodedString*res = 0;
248 mailmessage * mailmsg = 0; 261 mailmessage * mailmsg = 0;
249 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); 262 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg);
250 err = mailmessage_fetch(mailmsg,&target,&length); 263 err = mailmessage_fetch(mailmsg,&target,&length);
251 if (mailmsg) 264 if (mailmsg)
252 mailmessage_free(mailmsg); 265 mailmessage_free(mailmsg);
253 if (target) { 266 if (target) {
254 res = new encodedString(target,length); 267 res = new encodedString(target,length);
255 } 268 }
256 return res; 269 return res;
257} 270}
258 271
259const QString&NNTPwrapper::getType()const { 272const QString&NNTPwrapper::getType()const {
260 return account->getType(); 273 return account->getType();
261} 274}
262 275
263const QString&NNTPwrapper::getName()const{ 276const QString&NNTPwrapper::getName()const{
264 return account->getAccountName(); 277 return account->getAccountName();
265} 278}
266 279
267void NNTPwrapper::deleteMail(const RecMail&mail) { 280void NNTPwrapper::deleteMail(const RecMail&mail) {
268} 281}
269 282
270int NNTPwrapper::deleteAllMail(const Folder*) { 283int NNTPwrapper::deleteAllMail(const Folder*) {
271} 284}
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.h b/noncore/net/mail/libmailwrapper/nntpwrapper.h
index 4d03754..d51c955 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.h
@@ -1,48 +1,48 @@
1#ifndef __NNTPWRAPPER 1#ifndef __NNTPWRAPPER
2#define __NNTPWRAPPER 2#define __NNTPWRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class NNTPwrapper : public Genericwrapper 13class NNTPwrapper : public Genericwrapper
14{ 14{
15 15
16 Q_OBJECT 16 Q_OBJECT
17 17
18public: 18public:
19 NNTPwrapper( NNTPaccount *a ); 19 NNTPwrapper( NNTPaccount *a );
20 virtual ~NNTPwrapper(); 20 virtual ~NNTPwrapper();
21 21
22 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
24 /* should only get the subscribed one */ 24 /* should only get the subscribed one */
25 virtual QList<Folder>* listFolders(); 25 virtual QList<Folder>* listFolders();
26 /* mailbox will be ignored */ 26 /* mailbox will be ignored */
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
28 QStringList listAllNewsgroups(); 28 QStringList listAllNewsgroups(const QString&mask = QString::null);
29 virtual void deleteMail(const RecMail&mail); 29 virtual void deleteMail(const RecMail&mail);
30 virtual void answeredMail(const RecMail&mail); 30 virtual void answeredMail(const RecMail&mail);
31 virtual int deleteAllMail(const Folder*); 31 virtual int deleteAllMail(const Folder*);
32 32
33 virtual RecBody fetchBody( const RecMail &mail ); 33 virtual RecBody fetchBody( const RecMail &mail );
34 virtual encodedString* fetchRawBody(const RecMail&mail); 34 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void logout(); 35 virtual void logout();
36 virtual const QString&getType()const; 36 virtual const QString&getType()const;
37 virtual const QString&getName()const; 37 virtual const QString&getName()const;
38 static void nntp_progress( size_t current, size_t maximum ); 38 static void nntp_progress( size_t current, size_t maximum );
39 39
40protected: 40protected:
41 void login(); 41 void login();
42 NNTPaccount *account; 42 NNTPaccount *account;
43 mailstorage* m_nntp; 43 mailstorage* m_nntp;
44 44
45 45
46}; 46};
47 47
48#endif 48#endif