Diffstat (limited to 'noncore/net/mail/libmailwrapper/nntpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/nntpwrapper.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp index cfded43..5d5011a 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp | |||
@@ -1,222 +1,222 @@ | |||
1 | #include "nntpwrapper.h" | 1 | #include "nntpwrapper.h" |
2 | #include "logindialog.h" | 2 | #include "logindialog.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | 4 | ||
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | 6 | ||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | 8 | ||
9 | #include <libetpan/libetpan.h> | 9 | #include <libetpan/libetpan.h> |
10 | 10 | ||
11 | 11 | ||
12 | #define HARD_MSG_SIZE_LIMIT 5242880 | 12 | #define HARD_MSG_SIZE_LIMIT 5242880 |
13 | 13 | ||
14 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
15 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | 15 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) |
16 | : Genericwrapper() { | 16 | : Genericwrapper() { |
17 | account = a; | 17 | account = a; |
18 | m_nntp = NULL; | 18 | m_nntp = NULL; |
19 | msgTempName = a->getFileName()+"_msg_cache"; | 19 | msgTempName = a->getFileName()+"_msg_cache"; |
20 | last_msg_id = 0; | 20 | last_msg_id = 0; |
21 | } | 21 | } |
22 | 22 | ||
23 | NNTPwrapper::~NNTPwrapper() { | 23 | NNTPwrapper::~NNTPwrapper() { |
24 | logout(); | 24 | logout(); |
25 | QFile msg_cache(msgTempName); | 25 | QFile msg_cache(msgTempName); |
26 | if (msg_cache.exists()) { | 26 | if (msg_cache.exists()) { |
27 | msg_cache.remove(); | 27 | msg_cache.remove(); |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | 31 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { |
32 | qDebug( "NNTP: %i of %i", current, maximum ); | 32 | odebug << "NNTP: " << current << " of " << maximum << "" << oendl; |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | 36 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { |
37 | int err = NEWSNNTP_NO_ERROR; | 37 | int err = NEWSNNTP_NO_ERROR; |
38 | char *message = 0; | 38 | char *message = 0; |
39 | size_t length = 0; | 39 | size_t length = 0; |
40 | 40 | ||
41 | RecBodyP body = new RecBody(); | 41 | RecBodyP body = new RecBody(); |
42 | login(); | 42 | login(); |
43 | if ( !m_nntp ) { | 43 | if ( !m_nntp ) { |
44 | return body; | 44 | return body; |
45 | } | 45 | } |
46 | 46 | ||
47 | mailmessage * mailmsg; | 47 | mailmessage * mailmsg; |
48 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 48 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
49 | qDebug("Message to large: %i",mail->Msgsize()); | 49 | odebug << "Message to large: " << mail->Msgsize() << "" << oendl; |
50 | return body; | 50 | return body; |
51 | } | 51 | } |
52 | 52 | ||
53 | QFile msg_cache(msgTempName); | 53 | QFile msg_cache(msgTempName); |
54 | 54 | ||
55 | cleanMimeCache(); | 55 | cleanMimeCache(); |
56 | 56 | ||
57 | if (mail->getNumber()!=last_msg_id) { | 57 | if (mail->getNumber()!=last_msg_id) { |
58 | if (msg_cache.exists()) { | 58 | if (msg_cache.exists()) { |
59 | msg_cache.remove(); | 59 | msg_cache.remove(); |
60 | } | 60 | } |
61 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 61 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
62 | last_msg_id = mail->getNumber(); | 62 | last_msg_id = mail->getNumber(); |
63 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | 63 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); |
64 | err = mailmessage_fetch(mailmsg,&message,&length); | 64 | err = mailmessage_fetch(mailmsg,&message,&length); |
65 | msg_cache.writeBlock(message,length); | 65 | msg_cache.writeBlock(message,length); |
66 | } else { | 66 | } else { |
67 | QString msg=""; | 67 | QString msg=""; |
68 | msg_cache.open(IO_ReadOnly); | 68 | msg_cache.open(IO_ReadOnly); |
69 | message = new char[4096]; | 69 | message = new char[4096]; |
70 | memset(message,0,4096); | 70 | memset(message,0,4096); |
71 | while (msg_cache.readBlock(message,4095)>0) { | 71 | while (msg_cache.readBlock(message,4095)>0) { |
72 | msg+=message; | 72 | msg+=message; |
73 | memset(message,0,4096); | 73 | memset(message,0,4096); |
74 | } | 74 | } |
75 | delete message; | 75 | delete message; |
76 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 76 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
77 | memset(message,0,msg.length()+1); | 77 | memset(message,0,msg.length()+1); |
78 | memcpy(message,msg.latin1(),msg.length()); | 78 | memcpy(message,msg.latin1(),msg.length()); |
79 | /* transform to libetpan stuff */ | 79 | /* transform to libetpan stuff */ |
80 | mailmsg = mailmessage_new(); | 80 | mailmsg = mailmessage_new(); |
81 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 81 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
82 | generic_message_t * msg_data; | 82 | generic_message_t * msg_data; |
83 | msg_data = (generic_message_t *)mailmsg->msg_data; | 83 | msg_data = (generic_message_t *)mailmsg->msg_data; |
84 | msg_data->msg_fetched = 1; | 84 | msg_data->msg_fetched = 1; |
85 | msg_data->msg_message = message; | 85 | msg_data->msg_message = message; |
86 | msg_data->msg_length = strlen(message); | 86 | msg_data->msg_length = strlen(message); |
87 | } | 87 | } |
88 | body = parseMail(mailmsg); | 88 | body = parseMail(mailmsg); |
89 | 89 | ||
90 | /* clean up */ | 90 | /* clean up */ |
91 | if (mailmsg) | 91 | if (mailmsg) |
92 | mailmessage_free(mailmsg); | 92 | mailmessage_free(mailmsg); |
93 | if (message) | 93 | if (message) |
94 | free(message); | 94 | free(message); |
95 | 95 | ||
96 | return body; | 96 | return body; |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 100 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
101 | { | 101 | { |
102 | login(); | 102 | login(); |
103 | if (!m_nntp) | 103 | if (!m_nntp) |
104 | return; | 104 | return; |
105 | uint32_t res_messages,res_recent,res_unseen; | 105 | uint32_t res_messages,res_recent,res_unseen; |
106 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); | 106 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); |
107 | parseList(target,m_nntp->sto_session,which,true); | 107 | parseList(target,m_nntp->sto_session,which,true); |
108 | } | 108 | } |
109 | 109 | ||
110 | void NNTPwrapper::login() | 110 | void NNTPwrapper::login() |
111 | { | 111 | { |
112 | if (account->getOffline()) | 112 | if (account->getOffline()) |
113 | return; | 113 | return; |
114 | /* we'll hold the line */ | 114 | /* we'll hold the line */ |
115 | if ( m_nntp != NULL ) | 115 | if ( m_nntp != NULL ) |
116 | return; | 116 | return; |
117 | 117 | ||
118 | const char *server, *user, *pass; | 118 | const char *server, *user, *pass; |
119 | QString User,Pass; | 119 | QString User,Pass; |
120 | uint16_t port; | 120 | uint16_t port; |
121 | int err = NEWSNNTP_NO_ERROR; | 121 | int err = NEWSNNTP_NO_ERROR; |
122 | 122 | ||
123 | server = account->getServer().latin1(); | 123 | server = account->getServer().latin1(); |
124 | port = account->getPort().toUInt(); | 124 | port = account->getPort().toUInt(); |
125 | 125 | ||
126 | user = pass = 0; | 126 | user = pass = 0; |
127 | 127 | ||
128 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | 128 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { |
129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
130 | login.show(); | 130 | login.show(); |
131 | if ( QDialog::Accepted == login.exec() ) { | 131 | if ( QDialog::Accepted == login.exec() ) { |
132 | // ok | 132 | // ok |
133 | User = login.getUser().latin1(); | 133 | User = login.getUser().latin1(); |
134 | Pass = login.getPassword().latin1(); | 134 | Pass = login.getPassword().latin1(); |
135 | } else { | 135 | } else { |
136 | // cancel | 136 | // cancel |
137 | qDebug( "NNTP: Login canceled" ); | 137 | odebug << "NNTP: Login canceled" << oendl; |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | } else { | 140 | } else { |
141 | User = account->getUser().latin1(); | 141 | User = account->getUser().latin1(); |
142 | Pass = account->getPassword().latin1(); | 142 | Pass = account->getPassword().latin1(); |
143 | } | 143 | } |
144 | 144 | ||
145 | if (User.isEmpty()) { | 145 | if (User.isEmpty()) { |
146 | user=0; | 146 | user=0; |
147 | pass = 0; | 147 | pass = 0; |
148 | } else { | 148 | } else { |
149 | user=User.latin1(); | 149 | user=User.latin1(); |
150 | pass=Pass.latin1(); | 150 | pass=Pass.latin1(); |
151 | } | 151 | } |
152 | // bool ssl = account->getSSL(); | 152 | // bool ssl = account->getSSL(); |
153 | 153 | ||
154 | m_nntp=mailstorage_new(NULL); | 154 | m_nntp=mailstorage_new(NULL); |
155 | 155 | ||
156 | int conntypeset = account->ConnectionType(); | 156 | int conntypeset = account->ConnectionType(); |
157 | int conntype = 0; | 157 | int conntype = 0; |
158 | if ( conntypeset == 3 ) { | 158 | if ( conntypeset == 3 ) { |
159 | conntype = CONNECTION_TYPE_COMMAND; | 159 | conntype = CONNECTION_TYPE_COMMAND; |
160 | } else if ( conntypeset == 2 ) { | 160 | } else if ( conntypeset == 2 ) { |
161 | conntype = CONNECTION_TYPE_TLS; | 161 | conntype = CONNECTION_TYPE_TLS; |
162 | } else if ( conntypeset == 1 ) { | 162 | } else if ( conntypeset == 1 ) { |
163 | conntype = CONNECTION_TYPE_STARTTLS; | 163 | conntype = CONNECTION_TYPE_STARTTLS; |
164 | } else if ( conntypeset == 0 ) { | 164 | } else if ( conntypeset == 0 ) { |
165 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 165 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
166 | } | 166 | } |
167 | 167 | ||
168 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, | 168 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, |
169 | (char*)user,(char*)pass,0,0,0); | 169 | (char*)user,(char*)pass,0,0,0); |
170 | 170 | ||
171 | err = mailstorage_connect( m_nntp ); | 171 | err = mailstorage_connect( m_nntp ); |
172 | 172 | ||
173 | if (err != NEWSNNTP_NO_ERROR) { | 173 | if (err != NEWSNNTP_NO_ERROR) { |
174 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); | 174 | odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
175 | // Global::statusMessage(tr("Error initializing folder")); | 175 | // Global::statusMessage(tr("Error initializing folder")); |
176 | mailstorage_free(m_nntp); | 176 | mailstorage_free(m_nntp); |
177 | m_nntp = 0; | 177 | m_nntp = 0; |
178 | 178 | ||
179 | } else { | 179 | } else { |
180 | mailsession * session = m_nntp->sto_session; | 180 | mailsession * session = m_nntp->sto_session; |
181 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 181 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
182 | news->nntp_progr_fun = &nntp_progress; | 182 | news->nntp_progr_fun = &nntp_progress; |
183 | } | 183 | } |
184 | 184 | ||
185 | } | 185 | } |
186 | 186 | ||
187 | void NNTPwrapper::logout() | 187 | void NNTPwrapper::logout() |
188 | { | 188 | { |
189 | int err = NEWSNNTP_NO_ERROR; | 189 | int err = NEWSNNTP_NO_ERROR; |
190 | if ( m_nntp == NULL ) | 190 | if ( m_nntp == NULL ) |
191 | return; | 191 | return; |
192 | mailstorage_free(m_nntp); | 192 | mailstorage_free(m_nntp); |
193 | m_nntp = 0; | 193 | m_nntp = 0; |
194 | } | 194 | } |
195 | 195 | ||
196 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { | 196 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { |
197 | 197 | ||
198 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 198 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
199 | QStringList groups; | 199 | QStringList groups; |
200 | if (account) { | 200 | if (account) { |
201 | groups = account->getGroups(); | 201 | groups = account->getGroups(); |
202 | } | 202 | } |
203 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { | 203 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { |
204 | folders->append(new Folder((*it),".")); | 204 | folders->append(new Folder((*it),".")); |
205 | } | 205 | } |
206 | return folders; | 206 | return folders; |
207 | } | 207 | } |
208 | 208 | ||
209 | /* we made this method in raw nntp access of etpan and not via generic interface | 209 | /* we made this method in raw nntp access of etpan and not via generic interface |
210 | * 'cause in that case there will be doubled copy operations. eg. the etpan would | 210 | * 'cause in that case there will be doubled copy operations. eg. the etpan would |
211 | * copy that stuff into its own structures and we must copy it into useable c++ | 211 | * copy that stuff into its own structures and we must copy it into useable c++ |
212 | * structures for our frontend. this would not make sense, so it is better to reimplement | 212 | * structures for our frontend. this would not make sense, so it is better to reimplement |
213 | * the stuff from generic interface of etpan but copy it direct to qt classes. | 213 | * the stuff from generic interface of etpan but copy it direct to qt classes. |
214 | */ | 214 | */ |
215 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | 215 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { |
216 | login(); | 216 | login(); |
217 | QStringList res; | 217 | QStringList res; |
218 | clist *result = 0; | 218 | clist *result = 0; |
219 | clistcell *current = 0; | 219 | clistcell *current = 0; |
220 | newsnntp_group_description *group; | 220 | newsnntp_group_description *group; |
221 | 221 | ||
222 | if ( m_nntp ) { | 222 | if ( m_nntp ) { |