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,22 +1,24 @@ | |||
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; |
@@ -47,72 +49,72 @@ RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | |||
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; |
@@ -173,35 +175,35 @@ void NNTPwrapper::login() | |||
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 | */ |