summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/pop3wrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 8d2f778..1edec9e 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -29,193 +29,193 @@ POP3wrapper::~POP3wrapper() {
29 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
30 msg_cache.remove(); 30 msg_cache.remove();
31 } 31 }
32} 32}
33 33
34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
36} 36}
37 37
38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
44 44
45 login(); 45 login();
46 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
47 return body; 47 return body;
48 } 48 }
49 49
50 mailmessage * mailmsg; 50 mailmessage * mailmsg;
51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
53 return body; 53 return body;
54 } 54 }
55 55
56 QFile msg_cache(msgTempName); 56 QFile msg_cache(msgTempName);
57 57
58 cleanMimeCache(); 58 cleanMimeCache();
59 59
60 if (mail->getNumber()!=last_msg_id) { 60 if (mail->getNumber()!=last_msg_id) {
61 if (msg_cache.exists()) { 61 if (msg_cache.exists()) {
62 msg_cache.remove(); 62 msg_cache.remove();
63 } 63 }
64 msg_cache.open(IO_ReadWrite|IO_Truncate); 64 msg_cache.open(IO_ReadWrite|IO_Truncate);
65 last_msg_id = mail->getNumber(); 65 last_msg_id = mail->getNumber();
66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
67 err = mailmessage_fetch(mailmsg,&message,&length); 67 err = mailmessage_fetch(mailmsg,&message,&length);
68 msg_cache.writeBlock(message,length); 68 msg_cache.writeBlock(message,length);
69 } else { 69 } else {
70 QString msg=""; 70 QString msg="";
71 msg_cache.open(IO_ReadOnly); 71 msg_cache.open(IO_ReadOnly);
72 message = new char[4096]; 72 message = new char[4096];
73 memset(message,0,4096); 73 memset(message,0,4096);
74 while (msg_cache.readBlock(message,4095)>0) { 74 while (msg_cache.readBlock(message,4095)>0) {
75 msg+=message; 75 msg+=message;
76 memset(message,0,4096); 76 memset(message,0,4096);
77 } 77 }
78 delete message; 78 delete message;
79 message = (char*)malloc(msg.length()+1*sizeof(char)); 79 message = (char*)malloc(msg.length()+1*sizeof(char));
80 memset(message,0,msg.length()+1); 80 memset(message,0,msg.length()+1);
81 memcpy(message,msg.latin1(),msg.length()); 81 memcpy(message,msg.latin1(),msg.length());
82 /* transform to libetpan stuff */ 82 /* transform to libetpan stuff */
83 mailmsg = mailmessage_new(); 83 mailmsg = mailmessage_new();
84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
85 generic_message_t * msg_data; 85 generic_message_t * msg_data;
86 msg_data = (generic_message_t *)mailmsg->msg_data; 86 msg_data = (generic_message_t *)mailmsg->msg_data;
87 msg_data->msg_fetched = 1; 87 msg_data->msg_fetched = 1;
88 msg_data->msg_message = message; 88 msg_data->msg_message = message;
89 msg_data->msg_length = strlen(message); 89 msg_data->msg_length = strlen(message);
90 } 90 }
91 body = parseMail(mailmsg); 91 body = parseMail(mailmsg);
92 92
93 /* clean up */ 93 /* clean up */
94 if (mailmsg) 94 if (mailmsg)
95 mailmessage_free(mailmsg); 95 mailmessage_free(mailmsg);
96 if (message) 96 if (message)
97 free(message); 97 free(message);
98 98
99 return body; 99 return body;
100} 100}
101 101
102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
103{ 103{
104 login(); 104 login();
105 if (!m_pop3) 105 if (!m_pop3)
106 return; 106 return;
107 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
111} 111}
112 112
113void POP3wrapper::login() 113void POP3wrapper::login()
114{ 114{
115 if (account->getOffline()) 115 if (account->getOffline())
116 return; 116 return;
117 /* we'll hold the line */ 117 /* we'll hold the line */
118 if ( m_pop3 != NULL ) 118 if ( m_pop3 != NULL )
119 return; 119 return;
120 120
121 QString server,user, pass; 121 QString server,user, pass;
122 uint16_t port; 122 uint16_t port;
123 int err = MAILPOP3_NO_ERROR; 123 int err = MAILPOP3_NO_ERROR;
124 124
125 server = account->getServer().latin1(); 125 server = account->getServer();
126 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
127 127
128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
129 qApp->processEvents(); 129 qApp->processEvents();
130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
131 login.show(); 131 login.show();
132 if ( QDialog::Accepted == login.exec() ) { 132 if ( QDialog::Accepted == login.exec() ) {
133 // ok 133 // ok
134 user = login.getUser(); 134 user = login.getUser();
135 pass = login.getPassword(); 135 pass = login.getPassword();
136 } else { 136 } else {
137 // cancel 137 // cancel
138 ; // odebug << "POP3: Login canceled" << oendl; 138 ; // odebug << "POP3: Login canceled" << oendl;
139 return; 139 return;
140 } 140 }
141 } else { 141 } else {
142 user = account->getUser(); 142 user = account->getUser();
143 pass = account->getPassword(); 143 pass = account->getPassword();
144 } 144 }
145 // bool ssl = account->getSSL(); 145 // bool ssl = account->getSSL();
146 146
147 m_pop3=mailstorage_new(NULL); 147 m_pop3=mailstorage_new(NULL);
148 int conntypeset = account->ConnectionType(); 148 int conntypeset = account->ConnectionType();
149 int conntype = 0; 149 int conntype = 0;
150 if ( conntypeset == 3 ) { 150 if ( conntypeset == 3 ) {
151 conntype = CONNECTION_TYPE_COMMAND; 151 conntype = CONNECTION_TYPE_COMMAND;
152 } else if ( conntypeset == 2 ) { 152 } else if ( conntypeset == 2 ) {
153 conntype = CONNECTION_TYPE_TLS; 153 conntype = CONNECTION_TYPE_TLS;
154 } else if ( conntypeset == 1 ) { 154 } else if ( conntypeset == 1 ) {
155 conntype = CONNECTION_TYPE_STARTTLS; 155 conntype = CONNECTION_TYPE_STARTTLS;
156 } else if ( conntypeset == 0 ) { 156 } else if ( conntypeset == 0 ) {
157 conntype = CONNECTION_TYPE_TRY_STARTTLS; 157 conntype = CONNECTION_TYPE_TRY_STARTTLS;
158 } 158 }
159 159
160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
161 161
162 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 162 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
163 (char*)user.latin1(),(char*)pass.latin1(),0,0,0); 163 (char*)user.latin1(),(char*)pass.latin1(),0,0,0);
164 164
165 err = mailstorage_connect(m_pop3); 165 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 166 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error %1 initializing folder").arg( err )); 168 Global::statusMessage(tr("Error %1 initializing folder").arg( err ));
169 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
170 m_pop3 = 0; 170 m_pop3 = 0;
171 } else { 171 } else {
172 mailsession * session = m_pop3->sto_session; 172 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 174 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 175 mail->pop3_progr_fun = &pop3_progress;
176 } 176 }
177 } 177 }
178} 178}
179 179
180void POP3wrapper::logout() 180void POP3wrapper::logout()
181{ 181{
182 if ( m_pop3 == NULL ) 182 if ( m_pop3 == NULL )
183 return; 183 return;
184 mailstorage_free(m_pop3); 184 mailstorage_free(m_pop3);
185 m_pop3 = 0; 185 m_pop3 = 0;
186} 186}
187 187
188 188
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 191 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 192 folders->append(inb);
193 return folders; 193 return folders;
194} 194}
195 195
196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) 196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 197{
198 login(); 198 login();
199 if (!m_pop3) 199 if (!m_pop3)
200 return; 200 return;
201 int iii = 0; 201 int iii = 0;
202 int count = target.count(); 202 int count = target.count();
203 QWidget wid; 203 QWidget wid;
204 wid.show(); 204 wid.show();
205 while (iii < count ) { 205 while (iii < count ) {
206 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 206 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
207 wid.raise(); 207 wid.raise();
208 qApp->processEvents(); 208 qApp->processEvents();
209 //qDebug("delete "); 209 //qDebug("delete ");
210 RecMailP mail = (*target.at( iii )); 210 RecMailP mail = (*target.at( iii ));
211 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 211 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
212 if (err != MAIL_NO_ERROR) { 212 if (err != MAIL_NO_ERROR) {
213 Global::statusMessage(tr("Error deleting mail")); 213 Global::statusMessage(tr("Error deleting mail"));
214 } 214 }
215 ++iii; 215 ++iii;
216 } 216 }
217} 217}
218void POP3wrapper::deleteMail(const RecMailP&mail) { 218void POP3wrapper::deleteMail(const RecMailP&mail) {
219 login(); 219 login();
220 if (!m_pop3) 220 if (!m_pop3)
221 return; 221 return;