-rw-r--r-- | kmicromail/composemail.cpp | 14 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 23 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.h | 4 |
3 files changed, 25 insertions, 16 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index 2c2e279..ca4f247 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp | |||
@@ -28,330 +28,336 @@ | |||
28 | #include <kabc/addresseedialog.h> | 28 | #include <kabc/addresseedialog.h> |
29 | #include <kabc/stdaddressbook.h> | 29 | #include <kabc/stdaddressbook.h> |
30 | #include <kabc/addressee.h> | 30 | #include <kabc/addressee.h> |
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | //using namespace Opie::Core; | 34 | //using namespace Opie::Core; |
35 | //using namespace Opie::Ui; | 35 | //using namespace Opie::Ui; |
36 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 36 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
37 | : ComposeMailUI( parent, name, modal, flags ) | 37 | : ComposeMailUI( parent, name, modal, flags ) |
38 | { | 38 | { |
39 | 39 | ||
40 | settings = s; | 40 | settings = s; |
41 | m_replyid = ""; | 41 | m_replyid = ""; |
42 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); | 42 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); |
43 | QStringList mails = con.emails(); | 43 | QStringList mails = con.emails(); |
44 | QString defmail = con.preferredEmail(); | 44 | QString defmail = con.preferredEmail(); |
45 | if ( mails.count() == 0) | 45 | if ( mails.count() == 0) |
46 | QMessageBox::information( parentWidget(), tr( "Hint" ), | 46 | QMessageBox::information( parentWidget(), tr( "Hint" ), |
47 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!" ), | 47 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!" ), |
48 | tr( "Ok" ) ); | 48 | tr( "Ok" ) ); |
49 | if (defmail.length()!=0) { | 49 | if (defmail.length()!=0) { |
50 | fromBox->insertItem(defmail); | 50 | fromBox->insertItem(defmail); |
51 | } | 51 | } |
52 | QStringList::ConstIterator sit = mails.begin(); | 52 | QStringList::ConstIterator sit = mails.begin(); |
53 | for (;sit!=mails.end();++sit) { | 53 | for (;sit!=mails.end();++sit) { |
54 | if ( (*sit)==defmail) | 54 | if ( (*sit)==defmail) |
55 | continue; | 55 | continue; |
56 | fromBox->insertItem((*sit)); | 56 | fromBox->insertItem((*sit)); |
57 | } | 57 | } |
58 | senderNameEdit->setText(con.formattedName()); | 58 | senderNameEdit->setText(con.formattedName()); |
59 | Config cfg( "mail" ); | 59 | Config cfg( "mail" ); |
60 | cfg.setGroup( "Compose" ); | 60 | cfg.setGroup( "Compose" ); |
61 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 61 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
62 | 62 | ||
63 | attList->addColumn( tr( "Name" ) ); | 63 | attList->addColumn( tr( "Name" ) ); |
64 | attList->addColumn( tr( "Size" ) ); | 64 | attList->addColumn( tr( "Size" ) ); |
65 | 65 | ||
66 | QList<Account> accounts = settings->getAccounts(); | 66 | QList<Account> accounts = settings->getAccounts(); |
67 | 67 | ||
68 | Account *it; | 68 | Account *it; |
69 | for ( it = accounts.first(); it; it = accounts.next() ) { | 69 | for ( it = accounts.first(); it; it = accounts.next() ) { |
70 | if ( it->getType()==MAILLIB::A_SMTP ) { | 70 | if ( it->getType()==MAILLIB::A_SMTP ) { |
71 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 71 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
72 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 72 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
73 | smtpAccounts.append( smtp ); | 73 | smtpAccounts.append( smtp ); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | if ( smtpAccounts.count() > 0 ) { | 76 | if ( smtpAccounts.count() > 0 ) { |
77 | fillValues( smtpAccountBox->currentItem() ); | 77 | fillValues( smtpAccountBox->currentItem() ); |
78 | } else { | 78 | } else { |
79 | QMessageBox::information( parentWidget(), tr( "Problem" ), | 79 | QMessageBox::information( parentWidget(), tr( "Problem" ), |
80 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail." ), | 80 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail." ), |
81 | tr( "Ok" ) ); | 81 | tr( "Ok" ) ); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 84 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
85 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 85 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
86 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 86 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
87 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 87 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
88 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 88 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
89 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 89 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
90 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 90 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
91 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); | 91 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); |
92 | mMail = 0; | 92 | mMail = 0; |
93 | warnAttach = true; | 93 | warnAttach = true; |
94 | } | 94 | } |
95 | void ComposeMail::saveAsDraft() | 95 | void ComposeMail::saveAsDraft() |
96 | { | 96 | { |
97 | 97 | ||
98 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); | 98 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); |
99 | mail->setMail(fromBox->currentText()); | 99 | mail->setMail(fromBox->currentText()); |
100 | mail->setTo( toLine->text() ); | 100 | mail->setTo( toLine->text() ); |
101 | mail->setName(senderNameEdit->text()); | 101 | mail->setName(senderNameEdit->text()); |
102 | mail->setCC( ccLine->text() ); | 102 | mail->setCC( ccLine->text() ); |
103 | mail->setBCC( bccLine->text() ); | 103 | mail->setBCC( bccLine->text() ); |
104 | mail->setReply( replyLine->text() ); | 104 | mail->setReply( replyLine->text() ); |
105 | mail->setSubject( subjectLine->text() ); | 105 | mail->setSubject( subjectLine->text() ); |
106 | if (!m_replyid.isEmpty()) { | 106 | if (!m_replyid.isEmpty()) { |
107 | QStringList ids; | 107 | QStringList ids; |
108 | ids.append(m_replyid); | 108 | ids.append(m_replyid); |
109 | mail->setInreply(ids); | 109 | mail->setInreply(ids); |
110 | } | 110 | } |
111 | QString txt = message->text(); | 111 | QString txt = message->text(); |
112 | if ( !sigMultiLine->text().isEmpty() ) { | 112 | if ( !sigMultiLine->text().isEmpty() ) { |
113 | txt.append( "\n--\n" ); | 113 | txt.append( "\n--\n" ); |
114 | txt.append( sigMultiLine->text() ); | 114 | txt.append( sigMultiLine->text() ); |
115 | } | 115 | } |
116 | mail->setMessage( txt ); | 116 | mail->setMessage( txt ); |
117 | 117 | ||
118 | /* only use the default drafts folder name! */ | 118 | /* only use the default drafts folder name! */ |
119 | Storemail wrapper(AbstractMail::draftFolder()); | 119 | Storemail wrapper(AbstractMail::draftFolder()); |
120 | wrapper.storeMail(mail); | 120 | wrapper.storeMail(mail); |
121 | 121 | ||
122 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 122 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
123 | /* attachments we will ignore! */ | 123 | /* attachments we will ignore! */ |
124 | if ( it != NULL ) { | 124 | if ( it != 0 ) { |
125 | if ( warnAttach ) | 125 | if ( warnAttach ) |
126 | QMessageBox::warning(0,tr("Store message"), | 126 | QMessageBox::warning(0,tr("Store message"), |
127 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 127 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
128 | warnAttach = false; | 128 | warnAttach = false; |
129 | } | 129 | } |
130 | setStatus( tr("Mail saved as draft!") ); | 130 | setStatus( tr("Mail saved as draft!") ); |
131 | } | 131 | } |
132 | void ComposeMail::clearStatus() | 132 | void ComposeMail::clearStatus() |
133 | { | 133 | { |
134 | topLevelWidget()->setCaption( tr("Compose mail") ); | 134 | topLevelWidget()->setCaption( tr("Compose mail") ); |
135 | } | 135 | } |
136 | void ComposeMail::setStatus( QString status ) | 136 | void ComposeMail::setStatus( QString status ) |
137 | { | 137 | { |
138 | topLevelWidget()->setCaption( status ); | 138 | topLevelWidget()->setCaption( status ); |
139 | QTimer::singleShot ( 5000, this, SLOT( clearStatus() ) ) ; | 139 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; |
140 | } | 140 | } |
141 | void ComposeMail::pickAddress( QLineEdit *line ) | 141 | void ComposeMail::pickAddress( QLineEdit *line ) |
142 | { | 142 | { |
143 | //qDebug(" ComposeMail::pickAddress "); | 143 | //qDebug(" ComposeMail::pickAddress "); |
144 | QString names ;//= AddressPicker::getNames(); | 144 | QString names ;//= AddressPicker::getNames(); |
145 | 145 | ||
146 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 146 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
147 | uint i=0; | 147 | uint i=0; |
148 | for (i=0; i < list.count(); i++) { | 148 | for (i=0; i < list.count(); i++) { |
149 | if ( !list[i].preferredEmail().isEmpty()) { | 149 | if ( !list[i].preferredEmail().isEmpty()) { |
150 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; | 150 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; |
151 | if ( i < list.count() -1 ) | 151 | if ( i < list.count() -1 ) |
152 | names+= ","; | 152 | names+= ","; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | if ( line->text().isEmpty() ) { | 157 | if ( line->text().isEmpty() ) { |
158 | line->setText( names ); | 158 | line->setText( names ); |
159 | } else if ( !names.isEmpty() ) { | 159 | } else if ( !names.isEmpty() ) { |
160 | line->setText( line->text() + ", " + names ); | 160 | line->setText( line->text() + ", " + names ); |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void ComposeMail::setTo( const QString & to ) | 165 | void ComposeMail::setTo( const QString & to ) |
166 | { | 166 | { |
167 | toLine->setText( to ); | 167 | toLine->setText( to ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void ComposeMail::setSubject( const QString & subject ) | 170 | void ComposeMail::setSubject( const QString & subject ) |
171 | { | 171 | { |
172 | subjectLine->setText( subject ); | 172 | subjectLine->setText( subject ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void ComposeMail::setInReplyTo( const QString & messageId ) | 175 | void ComposeMail::setInReplyTo( const QString & messageId ) |
176 | { | 176 | { |
177 | m_replyid = messageId; | 177 | m_replyid = messageId; |
178 | } | 178 | } |
179 | 179 | ||
180 | void ComposeMail::setMessage( const QString & text ) | 180 | void ComposeMail::setMessage( const QString & text ) |
181 | { | 181 | { |
182 | message->setText( text ); | 182 | message->setText( text ); |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | void ComposeMail::pickAddressTo() | 186 | void ComposeMail::pickAddressTo() |
187 | { | 187 | { |
188 | pickAddress( toLine ); | 188 | pickAddress( toLine ); |
189 | } | 189 | } |
190 | 190 | ||
191 | void ComposeMail::pickAddressCC() | 191 | void ComposeMail::pickAddressCC() |
192 | { | 192 | { |
193 | pickAddress( ccLine ); | 193 | pickAddress( ccLine ); |
194 | } | 194 | } |
195 | 195 | ||
196 | void ComposeMail::pickAddressBCC() | 196 | void ComposeMail::pickAddressBCC() |
197 | { | 197 | { |
198 | pickAddress( bccLine ); | 198 | pickAddress( bccLine ); |
199 | } | 199 | } |
200 | 200 | ||
201 | void ComposeMail::pickAddressReply() | 201 | void ComposeMail::pickAddressReply() |
202 | { | 202 | { |
203 | pickAddress( replyLine ); | 203 | pickAddress( replyLine ); |
204 | } | 204 | } |
205 | 205 | ||
206 | void ComposeMail::fillValues( int ) | 206 | void ComposeMail::fillValues( int ) |
207 | { | 207 | { |
208 | #if 0 | 208 | #if 0 |
209 | SMTPaccount *smtp = smtpAccounts.at( current ); | 209 | SMTPaccount *smtp = smtpAccounts.at( current ); |
210 | ccLine->clear(); | 210 | ccLine->clear(); |
211 | if ( smtp->getUseCC() ) { | 211 | if ( smtp->getUseCC() ) { |
212 | ccLine->setText( smtp->getCC() ); | 212 | ccLine->setText( smtp->getCC() ); |
213 | } | 213 | } |
214 | bccLine->clear(); | 214 | bccLine->clear(); |
215 | if ( smtp->getUseBCC() ) { | 215 | if ( smtp->getUseBCC() ) { |
216 | bccLine->setText( smtp->getBCC() ); | 216 | bccLine->setText( smtp->getBCC() ); |
217 | } | 217 | } |
218 | replyLine->clear(); | 218 | replyLine->clear(); |
219 | if ( smtp->getUseReply() ) { | 219 | if ( smtp->getUseReply() ) { |
220 | replyLine->setText( smtp->getReply() ); | 220 | replyLine->setText( smtp->getReply() ); |
221 | } | 221 | } |
222 | sigMultiLine->setText( smtp->getSignature() ); | 222 | sigMultiLine->setText( smtp->getSignature() ); |
223 | #endif | 223 | #endif |
224 | } | 224 | } |
225 | 225 | ||
226 | void ComposeMail::slotAdjustColumns() | 226 | void ComposeMail::slotAdjustColumns() |
227 | { | 227 | { |
228 | int currPage = tabWidget->currentPageIndex(); | 228 | int currPage = tabWidget->currentPageIndex(); |
229 | 229 | ||
230 | tabWidget->showPage( attachTab ); | 230 | tabWidget->showPage( attachTab ); |
231 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | 231 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); |
232 | attList->setColumnWidth( 1, 80 ); | 232 | attList->setColumnWidth( 1, 80 ); |
233 | 233 | ||
234 | tabWidget->setCurrentPage( currPage ); | 234 | tabWidget->setCurrentPage( currPage ); |
235 | } | 235 | } |
236 | 236 | ||
237 | void ComposeMail::addAttachment() | 237 | void ComposeMail::addAttachment() |
238 | { | 238 | { |
239 | QString lnk = KFileDialog::getOpenFileName( "", "Add Attachment", this ); | 239 | QString lnk = KFileDialog::getOpenFileName( "", "Add Attachment", this ); |
240 | if ( !lnk.isEmpty() ) { | 240 | if ( !lnk.isEmpty() ) { |
241 | Attachment *att = new Attachment( lnk ); | 241 | Attachment *att = new Attachment( lnk ); |
242 | (void) new AttachViewItem( attList, att ); | 242 | (void) new AttachViewItem( attList, att ); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | void ComposeMail::removeAttachment() | 246 | void ComposeMail::removeAttachment() |
247 | { | 247 | { |
248 | if ( !attList->currentItem() ) { | 248 | if ( !attList->currentItem() ) { |
249 | QMessageBox::information( this, tr( "Error" ), | 249 | QMessageBox::information( this, tr( "Error" ), |
250 | tr( "<p>Please select a File.</p>" ), | 250 | tr( "<p>Please select a File.</p>" ), |
251 | tr( "Ok" ) ); | 251 | tr( "Ok" ) ); |
252 | } else { | 252 | } else { |
253 | attList->takeItem( attList->currentItem() ); | 253 | attList->takeItem( attList->currentItem() ); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | void ComposeMail::accept() | 257 | void ComposeMail::accept() |
258 | { | 258 | { |
259 | if (! checkBoxLater->isChecked() ) { | 259 | if (! checkBoxLater->isChecked() ) { |
260 | int yesno = QMessageBox::warning(0,tr("Stop editing message"), | 260 | int yesno = QMessageBox::warning(0,tr("Stop editing message"), |
261 | tr("Send this message?"), | 261 | tr("Send this message?"), |
262 | tr("Yes"), | 262 | tr("Yes"), |
263 | tr("Cancel")); | 263 | tr("Cancel")); |
264 | 264 | ||
265 | if (yesno == 1) { | 265 | if (yesno == 1) { |
266 | return; | 266 | return; |
267 | } | 267 | } |
268 | } | 268 | } |
269 | #if 0 | 269 | #if 0 |
270 | odebug << "Sending Mail with " | 270 | odebug << "Sending Mail with " |
271 | << smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() << oendl; | 271 | << smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() << oendl; |
272 | #endif | 272 | #endif |
273 | Opie::Core::OSmartPointer<Mail> mail=new Mail; | 273 | Opie::Core::OSmartPointer<Mail> mail=new Mail; |
274 | 274 | ||
275 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); | 275 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); |
276 | mail->setMail(fromBox->currentText()); | 276 | mail->setMail(fromBox->currentText()); |
277 | 277 | ||
278 | if ( !toLine->text().isEmpty() ) { | 278 | if ( !toLine->text().isEmpty() ) { |
279 | mail->setTo( toLine->text() ); | 279 | mail->setTo( toLine->text() ); |
280 | } else { | 280 | } else { |
281 | QMessageBox::warning(0,tr("Sending mail"), | 281 | QMessageBox::warning(0,tr("Sending mail"), |
282 | tr("No Receiver spezified" ) ); | 282 | tr("No Receiver spezified" ) ); |
283 | return; | 283 | return; |
284 | } | 284 | } |
285 | 285 | ||
286 | mail->setName(senderNameEdit->text()); | 286 | mail->setName(senderNameEdit->text()); |
287 | mail->setCC( ccLine->text() ); | 287 | mail->setCC( ccLine->text() ); |
288 | mail->setBCC( bccLine->text() ); | 288 | mail->setBCC( bccLine->text() ); |
289 | mail->setReply( replyLine->text() ); | 289 | mail->setReply( replyLine->text() ); |
290 | mail->setSubject( subjectLine->text() ); | 290 | mail->setSubject( subjectLine->text() ); |
291 | if (!m_replyid.isEmpty()) { | 291 | if (!m_replyid.isEmpty()) { |
292 | QStringList ids; | 292 | QStringList ids; |
293 | ids.append(m_replyid); | 293 | ids.append(m_replyid); |
294 | mail->setInreply(ids); | 294 | mail->setInreply(ids); |
295 | } | 295 | } |
296 | QString txt = message->text(); | 296 | QString txt = message->text(); |
297 | if ( !sigMultiLine->text().isEmpty() ) { | 297 | if ( !sigMultiLine->text().isEmpty() ) { |
298 | txt.append( "\n--\n" ); | 298 | txt.append( "\n--\n" ); |
299 | txt.append( sigMultiLine->text() ); | 299 | txt.append( sigMultiLine->text() ); |
300 | } | 300 | } |
301 | mail->setMessage( txt ); | 301 | mail->setMessage( txt ); |
302 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 302 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
303 | while ( it != NULL ) { | 303 | while ( it != 0 ) { |
304 | mail->addAttachment( it->getAttachment() ); | 304 | mail->addAttachment( it->getAttachment() ); |
305 | it = (AttachViewItem *) it->nextSibling(); | 305 | it = (AttachViewItem *) it->nextSibling(); |
306 | } | 306 | } |
307 | 307 | ||
308 | SMTPwrapper wrapper( smtp ); | 308 | SMTPwrapper wrapper( smtp ); |
309 | wrapper.sendMail( mail,checkBoxLater->isChecked() ); | 309 | if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) ) |
310 | setStatus( tr ("Mail sent")); | ||
311 | else { | ||
312 | setStatus( tr ("Error: Something went wrong. Nothing sent")); | ||
313 | return; | ||
314 | } | ||
315 | |||
310 | 316 | ||
311 | QDialog::accept(); | 317 | QDialog::accept(); |
312 | } | 318 | } |
313 | 319 | ||
314 | void ComposeMail::reject() | 320 | void ComposeMail::reject() |
315 | { | 321 | { |
316 | //qDebug("ComposeMail::reject() "); | 322 | //qDebug("ComposeMail::reject() "); |
317 | int yesno = QMessageBox::warning(0,tr("Stop editing message"), | 323 | int yesno = QMessageBox::warning(0,tr("Stop editing message"), |
318 | tr("Store message into drafts?"), | 324 | tr("Store message into drafts?"), |
319 | tr("Yes"), | 325 | tr("Yes"), |
320 | tr("No")); | 326 | tr("No")); |
321 | 327 | ||
322 | //qDebug("button %d ", yesno); | 328 | //qDebug("button %d ", yesno); |
323 | if (yesno == 0) { | 329 | if (yesno == 0) { |
324 | saveAsDraft(); | 330 | saveAsDraft(); |
325 | } | 331 | } |
326 | if (yesno == 2) { | 332 | if (yesno == 2) { |
327 | qDebug("return "); | 333 | qDebug("return "); |
328 | return; | 334 | return; |
329 | } | 335 | } |
330 | QDialog::reject(); | 336 | QDialog::reject(); |
331 | } | 337 | } |
332 | 338 | ||
333 | ComposeMail::~ComposeMail() | 339 | ComposeMail::~ComposeMail() |
334 | { | 340 | { |
335 | } | 341 | } |
336 | 342 | ||
337 | void ComposeMail::reEditMail(const RecMailP¤t) | 343 | void ComposeMail::reEditMail(const RecMailP¤t) |
338 | { | 344 | { |
339 | RecMailP data = current; | 345 | RecMailP data = current; |
340 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); | 346 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); |
341 | subjectLine->setText( data->getSubject()); | 347 | subjectLine->setText( data->getSubject()); |
342 | toLine->setText(data->To().join(",")); | 348 | toLine->setText(data->To().join(",")); |
343 | ccLine->setText(data->CC().join(",")); | 349 | ccLine->setText(data->CC().join(",")); |
344 | bccLine->setText(data->Bcc().join(",")); | 350 | bccLine->setText(data->Bcc().join(",")); |
345 | replyLine->setText(data->Replyto()); | 351 | replyLine->setText(data->Replyto()); |
346 | } | 352 | } |
347 | 353 | ||
348 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 354 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
349 | : QListViewItem( parent ) | 355 | : QListViewItem( parent ) |
350 | { | 356 | { |
351 | attachment = att; | 357 | attachment = att; |
352 | if ( !attachment->getPixmap().isNull() ) | 358 | if ( !attachment->getPixmap().isNull() ) |
353 | setPixmap( 0,attachment->getPixmap() ); | 359 | setPixmap( 0,attachment->getPixmap() ); |
354 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 360 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
355 | setText( 1, QString::number( att->getSize() ) ); | 361 | setText( 1, QString::number( att->getSize() ) ); |
356 | } | 362 | } |
357 | 363 | ||
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 04a21ea..6a1b505 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -9,424 +9,427 @@ | |||
9 | //#include <qt.h> | 9 | //#include <qt.h> |
10 | #include <qapplication.h> | 10 | #include <qapplication.h> |
11 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | #include <qpe/config.h> | 13 | #include <qpe/config.h> |
14 | #include <qpe/qcopenvelope_qws.h> | 14 | #include <qpe/qcopenvelope_qws.h> |
15 | 15 | ||
16 | #include <libetpan/libetpan.h> | 16 | #include <libetpan/libetpan.h> |
17 | 17 | ||
18 | 18 | ||
19 | using namespace Opie::Core; | 19 | using namespace Opie::Core; |
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 20 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 21 | ||
22 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 22 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
23 | : Generatemail() | 23 | : Generatemail() |
24 | { | 24 | { |
25 | m_SmtpAccount = aSmtp; | 25 | m_SmtpAccount = aSmtp; |
26 | Config cfg( "mail" ); | 26 | Config cfg( "mail" ); |
27 | cfg.setGroup( "Status" ); | 27 | cfg.setGroup( "Status" ); |
28 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 28 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
29 | emit queuedMails( m_queuedMail ); | 29 | emit queuedMails( m_queuedMail ); |
30 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 30 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
31 | m_smtp = 0; | 31 | m_smtp = 0; |
32 | } | 32 | } |
33 | 33 | ||
34 | SMTPwrapper::~SMTPwrapper() | 34 | SMTPwrapper::~SMTPwrapper() |
35 | { | 35 | { |
36 | disc_server(); | 36 | disc_server(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void SMTPwrapper::emitQCop( int queued ) { | 39 | void SMTPwrapper::emitQCop( int queued ) { |
40 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 40 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
41 | env << queued; | 41 | env << queued; |
42 | } | 42 | } |
43 | 43 | ||
44 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 44 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
45 | switch ( errnum ) { | 45 | switch ( errnum ) { |
46 | case MAILSMTP_NO_ERROR: | 46 | case MAILSMTP_NO_ERROR: |
47 | return tr( "No error" ); | 47 | return tr( "No error" ); |
48 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 48 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
49 | return tr( "Unexpected error code" ); | 49 | return tr( "Unexpected error code" ); |
50 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 50 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
51 | return tr( "Service not available" ); | 51 | return tr( "Service not available" ); |
52 | case MAILSMTP_ERROR_STREAM: | 52 | case MAILSMTP_ERROR_STREAM: |
53 | return tr( "Stream error" ); | 53 | return tr( "Stream error" ); |
54 | case MAILSMTP_ERROR_HOSTNAME: | 54 | case MAILSMTP_ERROR_HOSTNAME: |
55 | return tr( "gethostname() failed" ); | 55 | return tr( "gethostname() failed" ); |
56 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 56 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
57 | return tr( "Not implemented" ); | 57 | return tr( "Not implemented" ); |
58 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 58 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
59 | return tr( "Error, action not taken" ); | 59 | return tr( "Error, action not taken" ); |
60 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 60 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
61 | return tr( "Data exceeds storage allocation" ); | 61 | return tr( "Data exceeds storage allocation" ); |
62 | case MAILSMTP_ERROR_IN_PROCESSING: | 62 | case MAILSMTP_ERROR_IN_PROCESSING: |
63 | return tr( "Error in processing" ); | 63 | return tr( "Error in processing" ); |
64 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 64 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
65 | return tr( "Starttls not supported" ); | 65 | return tr( "Starttls not supported" ); |
66 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 66 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
67 | // return tr( "Insufficient system storage" ); | 67 | // return tr( "Insufficient system storage" ); |
68 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 68 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
69 | return tr( "Mailbox unavailable" ); | 69 | return tr( "Mailbox unavailable" ); |
70 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 70 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
71 | return tr( "Mailbox name not allowed" ); | 71 | return tr( "Mailbox name not allowed" ); |
72 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 72 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
73 | return tr( "Bad command sequence" ); | 73 | return tr( "Bad command sequence" ); |
74 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 74 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
75 | return tr( "User not local" ); | 75 | return tr( "User not local" ); |
76 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 76 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
77 | return tr( "Transaction failed" ); | 77 | return tr( "Transaction failed" ); |
78 | case MAILSMTP_ERROR_MEMORY: | 78 | case MAILSMTP_ERROR_MEMORY: |
79 | return tr( "Memory error" ); | 79 | return tr( "Memory error" ); |
80 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 80 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
81 | return tr( "Connection refused" ); | 81 | return tr( "Connection refused" ); |
82 | default: | 82 | default: |
83 | return tr( "Unknown error code" ); | 83 | return tr( "Unknown error code" ); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 88 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
89 | if (SMTPwrapper::sendProgress) { | 89 | if (SMTPwrapper::sendProgress) { |
90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
91 | qApp->processEvents(); | 91 | qApp->processEvents(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
96 | if (!mail) | 96 | if (!mail) |
97 | return; | 97 | return; |
98 | QString localfolders = AbstractMail::defaultLocalfolder(); | 98 | QString localfolders = AbstractMail::defaultLocalfolder(); |
99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
100 | wrap->createMbox(box); | 100 | wrap->createMbox(box); |
101 | wrap->storeMessage(mail,length,box); | 101 | wrap->storeMessage(mail,length,box); |
102 | delete wrap; | 102 | delete wrap; |
103 | } | 103 | } |
104 | 104 | ||
105 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 105 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
106 | clist *rcpts = 0; | 106 | clist *rcpts = 0; |
107 | char *from, *data; | 107 | char *from, *data; |
108 | size_t size; | 108 | size_t size; |
109 | 109 | ||
110 | from = data = 0; | 110 | from = data = 0; |
111 | 111 | ||
112 | mailmessage * msg = 0; | 112 | mailmessage * msg = 0; |
113 | msg = mime_message_init(mail); | 113 | msg = mime_message_init(mail); |
114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
115 | int r = mailmessage_fetch(msg,&data,&size); | 115 | int r = mailmessage_fetch(msg,&data,&size); |
116 | mime_message_detach_mime(msg); | 116 | mime_message_detach_mime(msg); |
117 | mailmessage_free(msg); | 117 | mailmessage_free(msg); |
118 | if (r != MAIL_NO_ERROR || !data) { | 118 | if (r != MAIL_NO_ERROR || !data) { |
119 | if (data) | 119 | if (data) |
120 | free(data); | 120 | free(data); |
121 | ; // odebug << "Error fetching mime..." << oendl; | 121 | qDebug("Error fetching mime... "); |
122 | return; | 122 | return false; |
123 | } | 123 | } |
124 | msg = 0; | 124 | msg = 0; |
125 | if (later) { | 125 | if (later) { |
126 | storeMail(data,size,"Outgoing"); | 126 | storeMail(data,size,"Outgoing"); |
127 | if (data) | 127 | if (data) |
128 | free( data ); | 128 | free( data ); |
129 | Config cfg( "mail" ); | 129 | Config cfg( "mail" ); |
130 | cfg.setGroup( "Status" ); | 130 | cfg.setGroup( "Status" ); |
131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
132 | emit queuedMails( m_queuedMail ); | 132 | emit queuedMails( m_queuedMail ); |
133 | return; | 133 | return true; |
134 | } | 134 | } |
135 | from = getFrom( mail ); | 135 | from = getFrom( mail ); |
136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
137 | smtpSend(from,rcpts,data,size); | 137 | bool result = smtpSend(from,rcpts,data,size); |
138 | if (data) { | 138 | if (data) { |
139 | free(data); | 139 | free(data); |
140 | } | 140 | } |
141 | if (from) { | 141 | if (from) { |
142 | free(from); | 142 | free(from); |
143 | } | 143 | } |
144 | if (rcpts) | 144 | if (rcpts) |
145 | smtp_address_list_free( rcpts ); | 145 | smtp_address_list_free( rcpts ); |
146 | return result; | ||
146 | } | 147 | } |
147 | 148 | ||
148 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 149 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
149 | { | 150 | { |
150 | if (data) { | 151 | if (data) { |
151 | storeMail(data,size,"Sendfailed"); | 152 | storeMail(data,size,"Sendfailed"); |
152 | } | 153 | } |
153 | if (failuremessage) { | 154 | if (failuremessage) { |
154 | QMessageBox::critical(0,tr("Error sending mail"), | 155 | QMessageBox::critical(0,tr("Error sending mail"), |
155 | tr("<center>%1</center>").arg(failuremessage)); | 156 | tr("<center>%1</center>").arg(failuremessage)); |
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
159 | int SMTPwrapper::start_smtp_tls() | 160 | int SMTPwrapper::start_smtp_tls() |
160 | { | 161 | { |
161 | if (!m_smtp) { | 162 | if (!m_smtp) { |
162 | return MAILSMTP_ERROR_IN_PROCESSING; | 163 | return MAILSMTP_ERROR_IN_PROCESSING; |
163 | } | 164 | } |
164 | int err = mailesmtp_starttls(m_smtp); | 165 | int err = mailesmtp_starttls(m_smtp); |
165 | if (err != MAILSMTP_NO_ERROR) return err; | 166 | if (err != MAILSMTP_NO_ERROR) return err; |
166 | mailstream_low * low; | 167 | mailstream_low * low; |
167 | mailstream_low * new_low; | 168 | mailstream_low * new_low; |
168 | low = mailstream_get_low(m_smtp->stream); | 169 | low = mailstream_get_low(m_smtp->stream); |
169 | if (!low) { | 170 | if (!low) { |
170 | return MAILSMTP_ERROR_IN_PROCESSING; | 171 | return MAILSMTP_ERROR_IN_PROCESSING; |
171 | } | 172 | } |
172 | int fd = mailstream_low_get_fd(low); | 173 | int fd = mailstream_low_get_fd(low); |
173 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 174 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
174 | mailstream_low_free(low); | 175 | mailstream_low_free(low); |
175 | mailstream_set_low(m_smtp->stream, new_low); | 176 | mailstream_set_low(m_smtp->stream, new_low); |
176 | } else { | 177 | } else { |
177 | return MAILSMTP_ERROR_IN_PROCESSING; | 178 | return MAILSMTP_ERROR_IN_PROCESSING; |
178 | } | 179 | } |
179 | return err; | 180 | return err; |
180 | } | 181 | } |
181 | 182 | ||
182 | void SMTPwrapper::connect_server() | 183 | void SMTPwrapper::connect_server() |
183 | { | 184 | { |
184 | const char *server, *user, *pass; | 185 | const char *server, *user, *pass; |
185 | bool ssl; | 186 | bool ssl; |
186 | uint16_t port; | 187 | uint16_t port; |
187 | ssl = false; | 188 | ssl = false; |
188 | bool try_tls = true; | 189 | bool try_tls = true; |
189 | bool force_tls=false; | 190 | bool force_tls=false; |
190 | server = user = pass = 0; | 191 | server = user = pass = 0; |
191 | QString failuretext = ""; | 192 | QString failuretext = ""; |
192 | 193 | ||
193 | if (m_smtp || !m_SmtpAccount) { | 194 | if (m_smtp || !m_SmtpAccount) { |
194 | return; | 195 | return; |
195 | } | 196 | } |
196 | server = m_SmtpAccount->getServer().latin1(); | 197 | server = m_SmtpAccount->getServer().latin1(); |
197 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 198 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
198 | ssl = true; | 199 | ssl = true; |
199 | try_tls = false; | 200 | try_tls = false; |
200 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 201 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
201 | force_tls = true; | 202 | force_tls = true; |
202 | } | 203 | } |
203 | int result = 1; | 204 | int result = 1; |
204 | port = m_SmtpAccount->getPort().toUInt(); | 205 | port = m_SmtpAccount->getPort().toUInt(); |
205 | 206 | ||
206 | m_smtp = mailsmtp_new( 20, &progress ); | 207 | m_smtp = mailsmtp_new( 20, &progress ); |
207 | if ( m_smtp == NULL ) { | 208 | if ( m_smtp == NULL ) { |
208 | /* no failure message cause this happens when problems with memory - than we | 209 | /* no failure message cause this happens when problems with memory - than we |
209 | we can not display any messagebox */ | 210 | we can not display any messagebox */ |
210 | return; | 211 | return; |
211 | } | 212 | } |
212 | 213 | ||
213 | int err = MAILSMTP_NO_ERROR; | 214 | int err = MAILSMTP_NO_ERROR; |
214 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; | 215 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; |
215 | if ( ssl ) { | 216 | if ( ssl ) { |
216 | ; // odebug << "SSL session" << oendl; | 217 | ; // odebug << "SSL session" << oendl; |
217 | err = mailsmtp_ssl_connect( m_smtp, server, port ); | 218 | err = mailsmtp_ssl_connect( m_smtp, server, port ); |
218 | } else { | 219 | } else { |
219 | ; // odebug << "No SSL session" << oendl; | 220 | ; // odebug << "No SSL session" << oendl; |
220 | err = mailsmtp_socket_connect( m_smtp, server, port ); | 221 | err = mailsmtp_socket_connect( m_smtp, server, port ); |
221 | } | 222 | } |
222 | if ( err != MAILSMTP_NO_ERROR ) { | 223 | if ( err != MAILSMTP_NO_ERROR ) { |
223 | ; // odebug << "Error init connection" << oendl; | 224 | ; // odebug << "Error init connection" << oendl; |
224 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 225 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
225 | result = 0; | 226 | result = 0; |
226 | } | 227 | } |
227 | 228 | ||
228 | /* switch to tls after init 'cause there it will send the ehlo */ | 229 | /* switch to tls after init 'cause there it will send the ehlo */ |
229 | if (result) { | 230 | if (result) { |
230 | err = mailsmtp_init( m_smtp ); | 231 | err = mailsmtp_init( m_smtp ); |
231 | if (err != MAILSMTP_NO_ERROR) { | 232 | if (err != MAILSMTP_NO_ERROR) { |
232 | result = 0; | 233 | result = 0; |
233 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 234 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | 237 | ||
237 | if (try_tls) { | 238 | if (try_tls) { |
238 | err = start_smtp_tls(); | 239 | err = start_smtp_tls(); |
239 | if (err != MAILSMTP_NO_ERROR) { | 240 | if (err != MAILSMTP_NO_ERROR) { |
240 | try_tls = false; | 241 | try_tls = false; |
241 | } else { | 242 | } else { |
242 | err = mailesmtp_ehlo(m_smtp); | 243 | err = mailesmtp_ehlo(m_smtp); |
243 | } | 244 | } |
244 | } | 245 | } |
245 | 246 | ||
246 | if (!try_tls && force_tls) { | 247 | if (!try_tls && force_tls) { |
247 | result = 0; | 248 | result = 0; |
248 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 249 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
249 | } | 250 | } |
250 | 251 | ||
251 | if (result==1 && m_SmtpAccount->getLogin() ) { | 252 | if (result==1 && m_SmtpAccount->getLogin() ) { |
252 | ; // odebug << "smtp with auth" << oendl; | 253 | ; // odebug << "smtp with auth" << oendl; |
253 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 254 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
254 | // get'em | 255 | // get'em |
255 | LoginDialog login( m_SmtpAccount->getUser(), | 256 | LoginDialog login( m_SmtpAccount->getUser(), |
256 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 257 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
257 | login.show(); | 258 | login.show(); |
258 | if ( QDialog::Accepted == login.exec() ) { | 259 | if ( QDialog::Accepted == login.exec() ) { |
259 | // ok | 260 | // ok |
260 | user = login.getUser().latin1(); | 261 | user = login.getUser().latin1(); |
261 | pass = login.getPassword().latin1(); | 262 | pass = login.getPassword().latin1(); |
262 | } else { | 263 | } else { |
263 | result = 0; | 264 | result = 0; |
264 | failuretext=tr("Login aborted - storing mail to localfolder"); | 265 | failuretext=tr("Login aborted - storing mail to localfolder"); |
265 | } | 266 | } |
266 | } else { | 267 | } else { |
267 | user = m_SmtpAccount->getUser().latin1(); | 268 | user = m_SmtpAccount->getUser().latin1(); |
268 | pass = m_SmtpAccount->getPassword().latin1(); | 269 | pass = m_SmtpAccount->getPassword().latin1(); |
269 | } | 270 | } |
270 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; | 271 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; |
271 | if (result) { | 272 | if (result) { |
272 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); | 273 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); |
273 | if ( err == MAILSMTP_NO_ERROR ) { | 274 | if ( err == MAILSMTP_NO_ERROR ) { |
274 | ; // odebug << "auth ok" << oendl; | 275 | ; // odebug << "auth ok" << oendl; |
275 | } else { | 276 | } else { |
276 | failuretext = tr("Authentification failed"); | 277 | failuretext = tr("Authentification failed"); |
277 | result = 0; | 278 | result = 0; |
278 | } | 279 | } |
279 | } | 280 | } |
280 | } | 281 | } |
281 | } | 282 | } |
282 | 283 | ||
283 | void SMTPwrapper::disc_server() | 284 | void SMTPwrapper::disc_server() |
284 | { | 285 | { |
285 | if (m_smtp) { | 286 | if (m_smtp) { |
286 | mailsmtp_quit( m_smtp ); | 287 | mailsmtp_quit( m_smtp ); |
287 | mailsmtp_free( m_smtp ); | 288 | mailsmtp_free( m_smtp ); |
288 | m_smtp = 0; | 289 | m_smtp = 0; |
289 | } | 290 | } |
290 | } | 291 | } |
291 | 292 | ||
292 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 293 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
293 | { | 294 | { |
294 | int err,result; | 295 | int err,result; |
295 | QString failuretext = ""; | 296 | QString failuretext = ""; |
296 | 297 | ||
297 | connect_server(); | 298 | connect_server(); |
298 | 299 | ||
299 | result = 1; | 300 | result = 1; |
300 | if (m_smtp) { | 301 | if (m_smtp) { |
301 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 302 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
302 | if ( err != MAILSMTP_NO_ERROR ) { | 303 | if ( err != MAILSMTP_NO_ERROR ) { |
303 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 304 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
304 | result = 0; | 305 | result = 0; |
305 | } | 306 | } |
306 | } else { | 307 | } else { |
307 | result = 0; | 308 | result = 0; |
308 | } | 309 | } |
309 | 310 | ||
310 | if (!result) { | 311 | if (!result) { |
311 | storeFailedMail(data,size,failuretext); | 312 | storeFailedMail(data,size,failuretext); |
312 | } else { | 313 | } else { |
313 | ; // odebug << "Mail sent." << oendl; | 314 | ; // odebug << "Mail sent." << oendl; |
314 | storeMail(data,size,"Sent"); | 315 | storeMail(data,size,"Sent"); |
315 | } | 316 | } |
316 | return result; | 317 | return result; |
317 | } | 318 | } |
318 | 319 | ||
319 | void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 320 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
320 | { | 321 | { |
321 | mailmime * mimeMail; | 322 | mailmime * mimeMail; |
322 | 323 | bool result = true; | |
323 | mimeMail = createMimeMail(mail ); | 324 | mimeMail = createMimeMail(mail ); |
324 | if ( mimeMail == NULL ) { | 325 | if ( mimeMail == 0 ) { |
325 | ; // odebug << "sendMail: error creating mime mail" << oendl; | 326 | qDebug("SMTP wrapper:Error creating mail! "); |
327 | return false; | ||
326 | } else { | 328 | } else { |
327 | sendProgress = new progressMailSend(); | 329 | sendProgress = new progressMailSend(); |
328 | sendProgress->show(); | 330 | sendProgress->show(); |
329 | sendProgress->setMaxMails(1); | 331 | sendProgress->setMaxMails(1); |
330 | smtpSend( mimeMail,later); | 332 | result = smtpSend( mimeMail,later); |
331 | ; // odebug << "Clean up done" << oendl; | 333 | ; // odebug << "Clean up done" << oendl; |
332 | sendProgress->hide(); | 334 | sendProgress->hide(); |
333 | delete sendProgress; | 335 | delete sendProgress; |
334 | sendProgress = 0; | 336 | sendProgress = 0; |
335 | mailmime_free( mimeMail ); | 337 | mailmime_free( mimeMail ); |
336 | } | 338 | } |
339 | return result; | ||
337 | } | 340 | } |
338 | 341 | ||
339 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 342 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
340 | size_t curTok = 0; | 343 | size_t curTok = 0; |
341 | mailimf_fields *fields = 0; | 344 | mailimf_fields *fields = 0; |
342 | mailimf_field*ffrom = 0; | 345 | mailimf_field*ffrom = 0; |
343 | clist *rcpts = 0; | 346 | clist *rcpts = 0; |
344 | char*from = 0; | 347 | char*from = 0; |
345 | int res = 0; | 348 | int res = 0; |
346 | 349 | ||
347 | encodedString * data = wrap->fetchRawBody(which); | 350 | encodedString * data = wrap->fetchRawBody(which); |
348 | if (!data) | 351 | if (!data) |
349 | return 0; | 352 | return 0; |
350 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 353 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
351 | if (err != MAILIMF_NO_ERROR) { | 354 | if (err != MAILIMF_NO_ERROR) { |
352 | delete data; | 355 | delete data; |
353 | delete wrap; | 356 | delete wrap; |
354 | return 0; | 357 | return 0; |
355 | } | 358 | } |
356 | 359 | ||
357 | rcpts = createRcptList( fields ); | 360 | rcpts = createRcptList( fields ); |
358 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 361 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
359 | from = getFrom(ffrom); | 362 | from = getFrom(ffrom); |
360 | 363 | ||
361 | if (rcpts && from) { | 364 | if (rcpts && from) { |
362 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 365 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
363 | } | 366 | } |
364 | if (fields) { | 367 | if (fields) { |
365 | mailimf_fields_free(fields); | 368 | mailimf_fields_free(fields); |
366 | fields = 0; | 369 | fields = 0; |
367 | } | 370 | } |
368 | if (data) { | 371 | if (data) { |
369 | delete data; | 372 | delete data; |
370 | } | 373 | } |
371 | if (from) { | 374 | if (from) { |
372 | free(from); | 375 | free(from); |
373 | } | 376 | } |
374 | if (rcpts) { | 377 | if (rcpts) { |
375 | smtp_address_list_free( rcpts ); | 378 | smtp_address_list_free( rcpts ); |
376 | } | 379 | } |
377 | return res; | 380 | return res; |
378 | } | 381 | } |
379 | 382 | ||
380 | /* this is a special fun */ | 383 | /* this is a special fun */ |
381 | bool SMTPwrapper::flushOutbox() { | 384 | bool SMTPwrapper::flushOutbox() { |
382 | bool returnValue = true; | 385 | bool returnValue = true; |
383 | 386 | ||
384 | ; // odebug << "Sending the queue" << oendl; | 387 | ; // odebug << "Sending the queue" << oendl; |
385 | if (!m_SmtpAccount) { | 388 | if (!m_SmtpAccount) { |
386 | ; // odebug << "No smtp account given" << oendl; | 389 | ; // odebug << "No smtp account given" << oendl; |
387 | return false; | 390 | return false; |
388 | } | 391 | } |
389 | 392 | ||
390 | bool reset_user_value = false; | 393 | bool reset_user_value = false; |
391 | QString localfolders = AbstractMail::defaultLocalfolder(); | 394 | QString localfolders = AbstractMail::defaultLocalfolder(); |
392 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 395 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
393 | if (!wrap) { | 396 | if (!wrap) { |
394 | ; // odebug << "memory error" << oendl; | 397 | ; // odebug << "memory error" << oendl; |
395 | return false; | 398 | return false; |
396 | } | 399 | } |
397 | QString oldPw, oldUser; | 400 | QString oldPw, oldUser; |
398 | QValueList<RecMailP> mailsToSend; | 401 | QValueList<RecMailP> mailsToSend; |
399 | QValueList<RecMailP> mailsToRemove; | 402 | QValueList<RecMailP> mailsToRemove; |
400 | QString mbox("Outgoing"); | 403 | QString mbox("Outgoing"); |
401 | wrap->listMessages(mbox,mailsToSend); | 404 | wrap->listMessages(mbox,mailsToSend); |
402 | if (mailsToSend.count()==0) { | 405 | if (mailsToSend.count()==0) { |
403 | delete wrap; | 406 | delete wrap; |
404 | ; // odebug << "No mails to send" << oendl; | 407 | ; // odebug << "No mails to send" << oendl; |
405 | return false; | 408 | return false; |
406 | } | 409 | } |
407 | 410 | ||
408 | oldPw = m_SmtpAccount->getPassword(); | 411 | oldPw = m_SmtpAccount->getPassword(); |
409 | oldUser = m_SmtpAccount->getUser(); | 412 | oldUser = m_SmtpAccount->getUser(); |
410 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 413 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
411 | // get'em | 414 | // get'em |
412 | QString user,pass; | 415 | QString user,pass; |
413 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 416 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
414 | login.show(); | 417 | login.show(); |
415 | if ( QDialog::Accepted == login.exec() ) { | 418 | if ( QDialog::Accepted == login.exec() ) { |
416 | // ok | 419 | // ok |
417 | user = login.getUser().latin1(); | 420 | user = login.getUser().latin1(); |
418 | pass = login.getPassword().latin1(); | 421 | pass = login.getPassword().latin1(); |
419 | reset_user_value = true; | 422 | reset_user_value = true; |
420 | m_SmtpAccount->setUser(user); | 423 | m_SmtpAccount->setUser(user); |
421 | m_SmtpAccount->setPassword(pass); | 424 | m_SmtpAccount->setPassword(pass); |
422 | } else { | 425 | } else { |
423 | return true; | 426 | return true; |
424 | } | 427 | } |
425 | } | 428 | } |
426 | 429 | ||
427 | 430 | ||
428 | sendProgress = new progressMailSend(); | 431 | sendProgress = new progressMailSend(); |
429 | sendProgress->show(); | 432 | sendProgress->show(); |
430 | sendProgress->setMaxMails(mailsToSend.count()); | 433 | sendProgress->setMaxMails(mailsToSend.count()); |
431 | 434 | ||
432 | while (mailsToSend.count()>0) { | 435 | while (mailsToSend.count()>0) { |
diff --git a/kmicromail/libmailwrapper/smtpwrapper.h b/kmicromail/libmailwrapper/smtpwrapper.h index 6c5bbe8..105cbf5 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.h +++ b/kmicromail/libmailwrapper/smtpwrapper.h | |||
@@ -1,63 +1,63 @@ | |||
1 | // -*- Mode: C++; -*- | 1 | // -*- Mode: C++; -*- |
2 | #ifndef SMTPwrapper_H | 2 | #ifndef SMTPwrapper_H |
3 | #define SMTPwrapper_H | 3 | #define SMTPwrapper_H |
4 | 4 | ||
5 | #include <qpe/applnk.h> | 5 | #include <qpe/applnk.h> |
6 | 6 | ||
7 | #include <qbitarray.h> | 7 | #include <qbitarray.h> |
8 | #include <qdatetime.h> | 8 | #include <qdatetime.h> |
9 | #include <libetpan/clist.h> | 9 | #include <libetpan/clist.h> |
10 | 10 | ||
11 | #include "settings.h" | 11 | #include "settings.h" |
12 | #include "generatemail.h" | 12 | #include "generatemail.h" |
13 | 13 | ||
14 | #include <opie2/osmartpointer.h> | 14 | #include <opie2/osmartpointer.h> |
15 | 15 | ||
16 | class SMTPaccount; | 16 | class SMTPaccount; |
17 | class AbstractMail; | 17 | class AbstractMail; |
18 | 18 | ||
19 | class SMTPwrapper : public Generatemail | 19 | class SMTPwrapper : public Generatemail |
20 | { | 20 | { |
21 | Q_OBJECT | 21 | Q_OBJECT |
22 | 22 | ||
23 | public: | 23 | public: |
24 | SMTPwrapper(SMTPaccount * aSmtp); | 24 | SMTPwrapper(SMTPaccount * aSmtp); |
25 | virtual ~SMTPwrapper(); | 25 | virtual ~SMTPwrapper(); |
26 | void sendMail(const Opie::Core::OSmartPointer<Mail>& mail,bool later=false ); | 26 | bool sendMail(const Opie::Core::OSmartPointer<Mail>& mail,bool later=false ); |
27 | bool flushOutbox(); | 27 | bool flushOutbox(); |
28 | 28 | ||
29 | static progressMailSend*sendProgress; | 29 | static progressMailSend*sendProgress; |
30 | 30 | ||
31 | signals: | 31 | signals: |
32 | void queuedMails( int ); | 32 | void queuedMails( int ); |
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | mailsmtp *m_smtp; | 35 | mailsmtp *m_smtp; |
36 | SMTPaccount * m_SmtpAccount; | 36 | SMTPaccount * m_SmtpAccount; |
37 | 37 | ||
38 | void connect_server(); | 38 | void connect_server(); |
39 | void disc_server(); | 39 | void disc_server(); |
40 | int start_smtp_tls(); | 40 | int start_smtp_tls(); |
41 | 41 | ||
42 | 42 | ||
43 | void smtpSend( mailmime *mail,bool later); | 43 | bool smtpSend( mailmime *mail,bool later); |
44 | 44 | ||
45 | static void storeMail(const char*mail, size_t length, const QString&box); | 45 | static void storeMail(const char*mail, size_t length, const QString&box); |
46 | static QString mailsmtpError( int err ); | 46 | static QString mailsmtpError( int err ); |
47 | static void progress( size_t current, size_t maximum ); | 47 | static void progress( size_t current, size_t maximum ); |
48 | 48 | ||
49 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); | 49 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); |
50 | 50 | ||
51 | void storeMail(mailmime*mail, const QString&box); | 51 | void storeMail(mailmime*mail, const QString&box); |
52 | 52 | ||
53 | int sendQueuedMail(AbstractMail*wrap,const Opie::Core::OSmartPointer<RecMail>&which); | 53 | int sendQueuedMail(AbstractMail*wrap,const Opie::Core::OSmartPointer<RecMail>&which); |
54 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); | 54 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); |
55 | 55 | ||
56 | int m_queuedMail; | 56 | int m_queuedMail; |
57 | 57 | ||
58 | protected slots: | 58 | protected slots: |
59 | void emitQCop( int queued ); | 59 | void emitQCop( int queued ); |
60 | 60 | ||
61 | }; | 61 | }; |
62 | 62 | ||
63 | #endif | 63 | #endif |