author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kmicromail/libmailwrapper/nntpwrapper.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
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,281 +1,283 @@ | |||
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(); |
135 | } else { | 137 | } else { |
136 | // cancel | 138 | // cancel |
137 | ; // << "NNTP: Login canceled" << oendl; | 139 | ; // << "NNTP: Login canceled" << oendl; |
138 | return; | 140 | return; |
139 | } | 141 | } |
140 | } else { | 142 | } else { |
141 | User = account->getUser(); | 143 | User = account->getUser(); |
142 | Pass = account->getPassword(); | 144 | Pass = account->getPassword(); |
143 | } | 145 | } |
144 | 146 | ||
145 | // bool ssl = account->getSSL(); | 147 | // bool ssl = account->getSSL(); |
146 | 148 | ||
147 | m_nntp=mailstorage_new(NULL); | 149 | m_nntp=mailstorage_new(NULL); |
148 | 150 | ||
149 | int conntypeset = account->ConnectionType(); | 151 | int conntypeset = account->ConnectionType(); |
150 | int conntype = 0; | 152 | int conntype = 0; |
151 | if ( conntypeset == 3 ) { | 153 | if ( conntypeset == 3 ) { |
152 | conntype = CONNECTION_TYPE_COMMAND; | 154 | conntype = CONNECTION_TYPE_COMMAND; |
153 | } else if ( conntypeset == 2 ) { | 155 | } else if ( conntypeset == 2 ) { |
154 | conntype = CONNECTION_TYPE_TLS; | 156 | conntype = CONNECTION_TYPE_TLS; |
155 | } else if ( conntypeset == 1 ) { | 157 | } else if ( conntypeset == 1 ) { |
156 | conntype = CONNECTION_TYPE_STARTTLS; | 158 | conntype = CONNECTION_TYPE_STARTTLS; |
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+".*"; |
224 | err = newsnntp_list_active(news, nmask.latin1(), &result); | 226 | err = newsnntp_list_active(news, nmask.latin1(), &result); |
225 | } | 227 | } |
226 | if ( err == NEWSNNTP_NO_ERROR && result) { | 228 | if ( err == NEWSNNTP_NO_ERROR && result) { |
227 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { | 229 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { |
228 | group = ( newsnntp_group_description* ) current->data; | 230 | group = ( newsnntp_group_description* ) current->data; |
229 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; | 231 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; |
230 | res.append(group->grp_name); | 232 | res.append(group->grp_name); |
231 | } | 233 | } |
232 | } | 234 | } |
233 | } | 235 | } |
234 | if (result) { | 236 | if (result) { |
235 | newsnntp_list_free(result); | 237 | newsnntp_list_free(result); |
236 | } | 238 | } |
237 | return res; | 239 | return res; |
238 | } | 240 | } |
239 | 241 | ||
240 | void NNTPwrapper::answeredMail(const RecMailP&) {} | 242 | void NNTPwrapper::answeredMail(const RecMailP&) {} |
241 | 243 | ||
242 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | 244 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { |
243 | login(); | 245 | login(); |
244 | target_stat.message_count = 0; | 246 | target_stat.message_count = 0; |
245 | target_stat.message_unseen = 0; | 247 | target_stat.message_unseen = 0; |
246 | target_stat.message_recent = 0; | 248 | target_stat.message_recent = 0; |
247 | if (!m_nntp) | 249 | if (!m_nntp) |
248 | return; | 250 | return; |
249 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | 251 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, |
250 | &target_stat.message_recent,&target_stat.message_unseen); | 252 | &target_stat.message_recent,&target_stat.message_unseen); |
251 | } | 253 | } |
252 | 254 | ||
253 | 255 | ||
254 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { | 256 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { |
255 | char*target=0; | 257 | char*target=0; |
256 | size_t length=0; | 258 | size_t length=0; |
257 | encodedString*res = 0; | 259 | encodedString*res = 0; |
258 | mailmessage * mailmsg = 0; | 260 | mailmessage * mailmsg = 0; |
259 | int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | 261 | int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); |
260 | err = mailmessage_fetch(mailmsg,&target,&length); | 262 | err = mailmessage_fetch(mailmsg,&target,&length); |
261 | if (mailmsg) | 263 | if (mailmsg) |
262 | mailmessage_free(mailmsg); | 264 | mailmessage_free(mailmsg); |
263 | if (target) { | 265 | if (target) { |
264 | res = new encodedString(target,length); | 266 | res = new encodedString(target,length); |
265 | } | 267 | } |
266 | return res; | 268 | return res; |
267 | } | 269 | } |
268 | 270 | ||
269 | MAILLIB::ATYPE NNTPwrapper::getType()const { | 271 | MAILLIB::ATYPE NNTPwrapper::getType()const { |
270 | return account->getType(); | 272 | return account->getType(); |
271 | } | 273 | } |
272 | 274 | ||
273 | const QString&NNTPwrapper::getName()const{ | 275 | const QString&NNTPwrapper::getName()const{ |
274 | return account->getAccountName(); | 276 | return account->getAccountName(); |
275 | } | 277 | } |
276 | 278 | ||
277 | void NNTPwrapper::deleteMail(const RecMailP&) { | 279 | void NNTPwrapper::deleteMail(const RecMailP&) { |
278 | } | 280 | } |
279 | 281 | ||
280 | int NNTPwrapper::deleteAllMail(const FolderP&) { | 282 | int NNTPwrapper::deleteAllMail(const FolderP&) { |
281 | } | 283 | } |