Diffstat (limited to 'kmicromail/libmailwrapper/nntpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/nntpwrapper.cpp | 12 |
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,134 +1,136 @@ | |||
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 | ||
16 | using namespace Opie::Core; | 18 | using namespace Opie::Core; |
17 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | 19 | NNTPwrapper::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 | ||
25 | NNTPwrapper::~NNTPwrapper() { | 27 | NNTPwrapper::~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 | } |
31 | } | 33 | } |
32 | 34 | ||
33 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | 35 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { |
34 | ; // << "NNTP: " << current << " of " << maximum << "" << oendl; | 36 | ; // << "NNTP: " << current << " of " << maximum << "" << oendl; |
35 | } | 37 | } |
36 | 38 | ||
37 | 39 | ||
38 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | 40 | 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 | ||
102 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb) | 104 | void 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 | ||
112 | void NNTPwrapper::login() | 114 | void 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(); |
127 | 129 | ||
128 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | 130 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { |
129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 131 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
130 | login.show(); | 132 | login.show(); |
131 | if ( QDialog::Accepted == login.exec() ) { | 133 | if ( QDialog::Accepted == login.exec() ) { |
132 | // ok | 134 | // ok |
133 | User = login.getUser(); | 135 | User = login.getUser(); |
134 | Pass = login.getPassword(); | 136 | Pass = login.getPassword(); |
@@ -157,67 +159,67 @@ void NNTPwrapper::login() | |||
157 | } else if ( conntypeset == 0 ) { | 159 | } else if ( conntypeset == 0 ) { |
158 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 160 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
159 | } | 161 | } |
160 | 162 | ||
161 | nntp_mailstorage_init(m_nntp,(char*)server.latin1(), port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, | 163 | nntp_mailstorage_init(m_nntp,(char*)server.latin1(), port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, |
162 | (char*)User.latin1(),(char*)Pass.latin1(),0,0,0); | 164 | (char*)User.latin1(),(char*)Pass.latin1(),0,0,0); |
163 | 165 | ||
164 | err = mailstorage_connect( m_nntp ); | 166 | err = mailstorage_connect( m_nntp ); |
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 | ||
180 | void NNTPwrapper::logout() | 182 | void 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 | ||
189 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { | 191 | Q3ValueList<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 | */ |
208 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | 210 | QStringList 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 ) { |
216 | mailsession * session = m_nntp->sto_session; | 218 | mailsession * session = m_nntp->sto_session; |
217 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 219 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
218 | int err = NEWSNNTP_NO_ERROR; | 220 | int err = NEWSNNTP_NO_ERROR; |
219 | if (mask.isEmpty()) { | 221 | if (mask.isEmpty()) { |
220 | err = newsnntp_list(news, &result); | 222 | err = newsnntp_list(news, &result); |
221 | } else { | 223 | } else { |
222 | /* taken from generic wrapper of etpan */ | 224 | /* taken from generic wrapper of etpan */ |
223 | QString nmask = mask+".*"; | 225 | QString nmask = mask+".*"; |