-rw-r--r-- | noncore/net/mail/libmailwrapper/nntpwrapper.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp index e73a890..c68964d 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp | |||
@@ -63,179 +63,193 @@ RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { | |||
63 | last_msg_id = mail.getNumber(); | 63 | last_msg_id = mail.getNumber(); |
64 | err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); | 64 | err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); |
65 | err = mailmessage_fetch(mailmsg,&message,&length); | 65 | err = mailmessage_fetch(mailmsg,&message,&length); |
66 | msg_cache.writeBlock(message,length); | 66 | msg_cache.writeBlock(message,length); |
67 | } else { | 67 | } else { |
68 | QString msg=""; | 68 | QString msg=""; |
69 | msg_cache.open(IO_ReadOnly); | 69 | msg_cache.open(IO_ReadOnly); |
70 | message = new char[4096]; | 70 | message = new char[4096]; |
71 | memset(message,0,4096); | 71 | memset(message,0,4096); |
72 | while (msg_cache.readBlock(message,4095)>0) { | 72 | while (msg_cache.readBlock(message,4095)>0) { |
73 | msg+=message; | 73 | msg+=message; |
74 | memset(message,0,4096); | 74 | memset(message,0,4096); |
75 | } | 75 | } |
76 | delete message; | 76 | delete message; |
77 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 77 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
78 | memset(message,0,msg.length()+1); | 78 | memset(message,0,msg.length()+1); |
79 | memcpy(message,msg.latin1(),msg.length()); | 79 | memcpy(message,msg.latin1(),msg.length()); |
80 | /* transform to libetpan stuff */ | 80 | /* transform to libetpan stuff */ |
81 | mailmsg = mailmessage_new(); | 81 | mailmsg = mailmessage_new(); |
82 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 82 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
83 | generic_message_t * msg_data; | 83 | generic_message_t * msg_data; |
84 | msg_data = (generic_message_t *)mailmsg->msg_data; | 84 | msg_data = (generic_message_t *)mailmsg->msg_data; |
85 | msg_data->msg_fetched = 1; | 85 | msg_data->msg_fetched = 1; |
86 | msg_data->msg_message = message; | 86 | msg_data->msg_message = message; |
87 | msg_data->msg_length = strlen(message); | 87 | msg_data->msg_length = strlen(message); |
88 | } | 88 | } |
89 | body = parseMail(mailmsg); | 89 | body = parseMail(mailmsg); |
90 | 90 | ||
91 | /* clean up */ | 91 | /* clean up */ |
92 | if (mailmsg) | 92 | if (mailmsg) |
93 | mailmessage_free(mailmsg); | 93 | mailmessage_free(mailmsg); |
94 | if (message) | 94 | if (message) |
95 | free(message); | 95 | free(message); |
96 | 96 | ||
97 | return body; | 97 | return body; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | void NNTPwrapper::listMessages(const QString &, QList<RecMail> &target ) | 101 | void NNTPwrapper::listMessages(const QString &, QList<RecMail> &target ) |
102 | { | 102 | { |
103 | login(); | 103 | login(); |
104 | if (!m_nntp) | 104 | if (!m_nntp) |
105 | return; | 105 | return; |
106 | uint32_t res_messages,res_recent,res_unseen; | 106 | uint32_t res_messages,res_recent,res_unseen; |
107 | mailsession_status_folder(m_nntp->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 107 | mailsession_status_folder(m_nntp->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
108 | parseList(target,m_nntp->sto_session,"INBOX"); | 108 | parseList(target,m_nntp->sto_session,"INBOX"); |
109 | } | 109 | } |
110 | 110 | ||
111 | void NNTPwrapper::login() | 111 | void NNTPwrapper::login() |
112 | { | 112 | { |
113 | if (account->getOffline()) | 113 | if (account->getOffline()) |
114 | return; | 114 | return; |
115 | /* we'll hold the line */ | 115 | /* we'll hold the line */ |
116 | if ( m_nntp != NULL ) | 116 | if ( m_nntp != NULL ) |
117 | return; | 117 | return; |
118 | 118 | ||
119 | const char *server, *user, *pass; | 119 | const char *server, *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 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 126 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
127 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 127 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
128 | login.show(); | 128 | login.show(); |
129 | if ( QDialog::Accepted == login.exec() ) { | 129 | if ( QDialog::Accepted == login.exec() ) { |
130 | // ok | 130 | // ok |
131 | user = login.getUser().latin1(); | 131 | user = login.getUser().latin1(); |
132 | pass = login.getPassword().latin1(); | 132 | pass = login.getPassword().latin1(); |
133 | } else { | 133 | } else { |
134 | // cancel | 134 | // cancel |
135 | qDebug( "NNTP: Login canceled" ); | 135 | qDebug( "NNTP: Login canceled" ); |
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | user = account->getUser().latin1(); | 139 | user = account->getUser().latin1(); |
140 | pass = account->getPassword().latin1(); | 140 | pass = account->getPassword().latin1(); |
141 | } | 141 | } |
142 | 142 | ||
143 | // bool ssl = account->getSSL(); | 143 | // bool ssl = account->getSSL(); |
144 | 144 | ||
145 | m_nntp=mailstorage_new(NULL); | 145 | m_nntp=mailstorage_new(NULL); |
146 | 146 | ||
147 | int conntypeset = account->ConnectionType(); | 147 | int conntypeset = account->ConnectionType(); |
148 | int conntype = 0; | 148 | int conntype = 0; |
149 | if ( conntypeset == 3 ) { | 149 | if ( conntypeset == 3 ) { |
150 | conntype = CONNECTION_TYPE_COMMAND; | 150 | conntype = CONNECTION_TYPE_COMMAND; |
151 | } else if ( conntypeset == 2 ) { | 151 | } else if ( conntypeset == 2 ) { |
152 | conntype = CONNECTION_TYPE_TLS; | 152 | conntype = CONNECTION_TYPE_TLS; |
153 | } else if ( conntypeset == 1 ) { | 153 | } else if ( conntypeset == 1 ) { |
154 | conntype = CONNECTION_TYPE_STARTTLS; | 154 | conntype = CONNECTION_TYPE_STARTTLS; |
155 | } else if ( conntypeset == 0 ) { | 155 | } else if ( conntypeset == 0 ) { |
156 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 156 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
157 | } | 157 | } |
158 | 158 | ||
159 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, conntype, NNTP_AUTH_TYPE_PLAIN, | 159 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, conntype, NNTP_AUTH_TYPE_PLAIN, |
160 | (char*)user,(char*)pass,0,0,0); | 160 | (char*)user,(char*)pass,0,0,0); |
161 | 161 | ||
162 | err = mailstorage_connect(m_nntp); | 162 | err = mailstorage_connect( m_nntp ); |
163 | 163 | ||
164 | if (err != NEWSNNTP_NO_ERROR) { | 164 | if (err != NEWSNNTP_NO_ERROR) { |
165 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); | 165 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); |
166 | // Global::statusMessage(tr("Error initializing folder")); | 166 | // Global::statusMessage(tr("Error initializing folder")); |
167 | mailstorage_free(m_nntp); | 167 | mailstorage_free(m_nntp); |
168 | m_nntp = 0; | 168 | m_nntp = 0; |
169 | |||
169 | } | 170 | } |
171 | |||
170 | } | 172 | } |
171 | 173 | ||
172 | void NNTPwrapper::logout() | 174 | void NNTPwrapper::logout() |
173 | { | 175 | { |
174 | int err = NEWSNNTP_NO_ERROR; | 176 | int err = NEWSNNTP_NO_ERROR; |
175 | if ( m_nntp == NULL ) | 177 | if ( m_nntp == NULL ) |
176 | return; | 178 | return; |
177 | mailstorage_free(m_nntp); | 179 | mailstorage_free(m_nntp); |
178 | m_nntp = 0; | 180 | m_nntp = 0; |
179 | } | 181 | } |
180 | 182 | ||
181 | QList<Folder>* NNTPwrapper::listFolders() { | 183 | QList<Folder>* NNTPwrapper::listFolders() { |
182 | QList<Folder> * folders = new QList<Folder>(); | ||
183 | folders->setAutoDelete( false ); | ||
184 | clist *result = 0; | ||
185 | 184 | ||
186 | // int err = | ||
187 | // if ( err == _NO_ERROR ) { | ||
188 | // current = result->first; | ||
189 | // for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | ||
190 | 185 | ||
191 | 186 | ||
192 | // Folder*inb=new Folder("INBOX","/"); | ||
193 | |||
194 | 187 | ||
188 | QList<Folder> * folders = new QList<Folder>(); | ||
189 | folders->setAutoDelete( false ); | ||
190 | clist *result = 0; | ||
191 | clistcell *current; | ||
192 | newsnntp_group_description *list; | ||
193 | |||
194 | login(); | ||
195 | if ( m_nntp ) { | ||
196 | mailsession * session = m_nntp->sto_session; | ||
197 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | ||
198 | int err = newsnntp_list_newsgroups(news, NULL, &result); | ||
199 | |||
200 | if ( err == NEWSNNTP_NO_ERROR ) { | ||
201 | current = result->first; | ||
202 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | ||
203 | list = ( newsnntp_group_description* ) current->data; | ||
204 | qDebug( list->grp_name ); | ||
205 | } | ||
206 | // Folder*inb=new Folder("INBOX","/"); | ||
207 | } | ||
208 | } | ||
195 | // folders->append(inb); | 209 | // folders->append(inb); |
196 | return folders; | 210 | return folders; |
197 | } | 211 | } |
198 | 212 | ||
199 | 213 | ||
200 | void NNTPwrapper::answeredMail(const RecMail&) {} | 214 | void NNTPwrapper::answeredMail(const RecMail&) {} |
201 | 215 | ||
202 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | 216 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { |
203 | login(); | 217 | login(); |
204 | target_stat.message_count = 0; | 218 | target_stat.message_count = 0; |
205 | target_stat.message_unseen = 0; | 219 | target_stat.message_unseen = 0; |
206 | target_stat.message_recent = 0; | 220 | target_stat.message_recent = 0; |
207 | if (!m_nntp) | 221 | if (!m_nntp) |
208 | return; | 222 | return; |
209 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | 223 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, |
210 | &target_stat.message_recent,&target_stat.message_unseen); | 224 | &target_stat.message_recent,&target_stat.message_unseen); |
211 | } | 225 | } |
212 | 226 | ||
213 | 227 | ||
214 | encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { | 228 | encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { |
215 | char*target=0; | 229 | char*target=0; |
216 | size_t length=0; | 230 | size_t length=0; |
217 | encodedString*res = 0; | 231 | encodedString*res = 0; |
218 | mailmessage * mailmsg = 0; | 232 | mailmessage * mailmsg = 0; |
219 | int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); | 233 | int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); |
220 | err = mailmessage_fetch(mailmsg,&target,&length); | 234 | err = mailmessage_fetch(mailmsg,&target,&length); |
221 | if (mailmsg) | 235 | if (mailmsg) |
222 | mailmessage_free(mailmsg); | 236 | mailmessage_free(mailmsg); |
223 | if (target) { | 237 | if (target) { |
224 | res = new encodedString(target,length); | 238 | res = new encodedString(target,length); |
225 | } | 239 | } |
226 | return res; | 240 | return res; |
227 | } | 241 | } |
228 | 242 | ||
229 | const QString&NNTPwrapper::getType()const { | 243 | const QString&NNTPwrapper::getType()const { |
230 | return account->getType(); | 244 | return account->getType(); |
231 | } | 245 | } |
232 | 246 | ||
233 | const QString&NNTPwrapper::getName()const{ | 247 | const QString&NNTPwrapper::getName()const{ |
234 | return account->getAccountName(); | 248 | return account->getAccountName(); |
235 | } | 249 | } |
236 | 250 | ||
237 | void NNTPwrapper::deleteMail(const RecMail&mail) { | 251 | void NNTPwrapper::deleteMail(const RecMail&mail) { |
238 | } | 252 | } |
239 | 253 | ||
240 | int NNTPwrapper::deleteAllMail(const Folder*) { | 254 | int NNTPwrapper::deleteAllMail(const Folder*) { |
241 | } | 255 | } |