summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/nntpwrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/nntpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/nntpwrapper.cpp b/kmicromail/libmailwrapper/nntpwrapper.cpp
index 93cd2b5..b328ecd 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.cpp
+++ b/kmicromail/libmailwrapper/nntpwrapper.cpp
@@ -1,30 +1,32 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "nntpwrapper.h" 2#include "nntpwrapper.h"
3#include "logindialog.h" 3#include "logindialog.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qfile.h> 6#include <qfile.h>
7//Added by qt3to4:
8#include <Q3ValueList>
7 9
8#include <stdlib.h> 10#include <stdlib.h>
9 11
10#include <libetpan/libetpan.h> 12#include <libetpan/libetpan.h>
11 13
12 14
13 15
14#define HARD_MSG_SIZE_LIMIT 5242880 16#define HARD_MSG_SIZE_LIMIT 5242880
15 17
16using namespace Opie::Core; 18using namespace Opie::Core;
17NNTPwrapper::NNTPwrapper( NNTPaccount *a ) 19NNTPwrapper::NNTPwrapper( NNTPaccount *a )
18: Genericwrapper() { 20: Genericwrapper() {
19 account = a; 21 account = a;
20 m_nntp = NULL; 22 m_nntp = NULL;
21 msgTempName = a->getFileName()+"_msg_cache"; 23 msgTempName = a->getFileName()+"_msg_cache";
22 last_msg_id = 0; 24 last_msg_id = 0;
23} 25}
24 26
25NNTPwrapper::~NNTPwrapper() { 27NNTPwrapper::~NNTPwrapper() {
26 logout(); 28 logout();
27 QFile msg_cache(msgTempName); 29 QFile msg_cache(msgTempName);
28 if (msg_cache.exists()) { 30 if (msg_cache.exists()) {
29 msg_cache.remove(); 31 msg_cache.remove();
30 } 32 }
@@ -39,88 +41,88 @@ RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) {
39 int err = NEWSNNTP_NO_ERROR; 41 int err = NEWSNNTP_NO_ERROR;
40 char *message = 0; 42 char *message = 0;
41 size_t length = 0; 43 size_t length = 0;
42 44
43 RecBodyP body = new RecBody(); 45 RecBodyP body = new RecBody();
44 login(); 46 login();
45 if ( !m_nntp ) { 47 if ( !m_nntp ) {
46 return body; 48 return body;
47 } 49 }
48 50
49 mailmessage * mailmsg; 51 mailmessage * mailmsg;
50 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 52 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 ; // << "Message to large: " << mail->Msgsize() << "" << oendl; 53 ; // << "Message to large: " << mail->Msgsize() << "" << oendl;
52 return body; 54 return body;
53 } 55 }
54 56
55 QFile msg_cache(msgTempName); 57 QFile msg_cache(msgTempName);
56 58
57 cleanMimeCache(); 59 cleanMimeCache();
58 60
59 if (mail->getNumber()!=last_msg_id) { 61 if (mail->getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 62 if (msg_cache.exists()) {
61 msg_cache.remove(); 63 msg_cache.remove();
62 } 64 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 65 msg_cache.open(QIODevice::ReadWrite|QIODevice::Truncate);
64 last_msg_id = mail->getNumber(); 66 last_msg_id = mail->getNumber();
65 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); 67 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 68 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 69 msg_cache.writeBlock(message,length);
68 } else { 70 } else {
69 QString msg=""; 71 QString msg="";
70 msg_cache.open(IO_ReadOnly); 72 msg_cache.open(QIODevice::ReadOnly);
71 message = new char[4096]; 73 message = new char[4096];
72 memset(message,0,4096); 74 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 75 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 76 msg+=message;
75 memset(message,0,4096); 77 memset(message,0,4096);
76 } 78 }
77 delete message; 79 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 80 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 81 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 82 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 83 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 84 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 85 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 86 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 87 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 88 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 89 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 90 msg_data->msg_length = strlen(message);
89 } 91 }
90 body = parseMail(mailmsg); 92 body = parseMail(mailmsg);
91 93
92 /* clean up */ 94 /* clean up */
93 if (mailmsg) 95 if (mailmsg)
94 mailmessage_free(mailmsg); 96 mailmessage_free(mailmsg);
95 if (message) 97 if (message)
96 free(message); 98 free(message);
97 99
98 return body; 100 return body;
99} 101}
100 102
101 103
102void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb) 104void NNTPwrapper::listMessages(const QString & which, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb)
103{ 105{
104 login(); 106 login();
105 if (!m_nntp) 107 if (!m_nntp)
106 return; 108 return;
107 uint32_t res_messages,res_recent,res_unseen; 109 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); 110 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_nntp->sto_session,which,true, maxSizeInKb); 111 parseList(target,m_nntp->sto_session,which,true, maxSizeInKb);
110} 112}
111 113
112void NNTPwrapper::login() 114void NNTPwrapper::login()
113{ 115{
114 if (account->getOffline()) 116 if (account->getOffline())
115 return; 117 return;
116 /* we'll hold the line */ 118 /* we'll hold the line */
117 if ( m_nntp != NULL ) 119 if ( m_nntp != NULL )
118 return; 120 return;
119 121
120 QString server; 122 QString server;
121 QString User,Pass; 123 QString User,Pass;
122 uint16_t port; 124 uint16_t port;
123 int err = NEWSNNTP_NO_ERROR; 125 int err = NEWSNNTP_NO_ERROR;
124 126
125 server = account->getServer(); 127 server = account->getServer();
126 port = account->getPort().toUInt(); 128 port = account->getPort().toUInt();
@@ -165,51 +167,51 @@ void NNTPwrapper::login()
165 167
166 if (err != NEWSNNTP_NO_ERROR) { 168 if (err != NEWSNNTP_NO_ERROR) {
167 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 169 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 // Global::statusMessage(tr("Error initializing folder")); 170 // Global::statusMessage(tr("Error initializing folder"));
169 mailstorage_free(m_nntp); 171 mailstorage_free(m_nntp);
170 m_nntp = 0; 172 m_nntp = 0;
171 173
172 } else { 174 } else {
173 mailsession * session = m_nntp->sto_session; 175 mailsession * session = m_nntp->sto_session;
174 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 176 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
175 news->nntp_progr_fun = &nntp_progress; 177 news->nntp_progr_fun = &nntp_progress;
176 } 178 }
177 179
178} 180}
179 181
180void NNTPwrapper::logout() 182void NNTPwrapper::logout()
181{ 183{
182 int err = NEWSNNTP_NO_ERROR; 184 int err = NEWSNNTP_NO_ERROR;
183 if ( m_nntp == NULL ) 185 if ( m_nntp == NULL )
184 return; 186 return;
185 mailstorage_free(m_nntp); 187 mailstorage_free(m_nntp);
186 m_nntp = 0; 188 m_nntp = 0;
187} 189}
188 190
189QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { 191Q3ValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() {
190 192
191 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 193 Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >();
192 QStringList groups; 194 QStringList groups;
193 if (account) { 195 if (account) {
194 groups = account->getGroups(); 196 groups = account->getGroups();
195 } 197 }
196 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { 198 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
197 folders->append(new Folder((*it),".")); 199 folders->append(new Folder((*it),"."));
198 } 200 }
199 return folders; 201 return folders;
200} 202}
201 203
202/* we made this method in raw nntp access of etpan and not via generic interface 204/* we made this method in raw nntp access of etpan and not via generic interface
203 * 'cause in that case there will be doubled copy operations. eg. the etpan would 205 * 'cause in that case there will be doubled copy operations. eg. the etpan would
204 * copy that stuff into its own structures and we must copy it into useable c++ 206 * copy that stuff into its own structures and we must copy it into useable c++
205 * structures for our frontend. this would not make sense, so it is better to reimplement 207 * structures for our frontend. this would not make sense, so it is better to reimplement
206 * the stuff from generic interface of etpan but copy it direct to qt classes. 208 * the stuff from generic interface of etpan but copy it direct to qt classes.
207 */ 209 */
208QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { 210QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) {
209 login(); 211 login();
210 QStringList res; 212 QStringList res;
211 clist *result = 0; 213 clist *result = 0;
212 clistcell *current = 0; 214 clistcell *current = 0;
213 newsnntp_group_description *group; 215 newsnntp_group_description *group;
214 216
215 if ( m_nntp ) { 217 if ( m_nntp ) {