author | alwin <alwin> | 2004-02-13 02:52:41 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-13 02:52:41 (UTC) |
commit | aca5ba5ed24b4da61517560ea91f566afd132d28 (patch) (unidiff) | |
tree | 86085c6042e591dc9f211a8716cb63ff30cb5f4e | |
parent | 2fd9c32e07714b7caf38994c0b0f1da8ffb27aa9 (diff) | |
download | opie-aca5ba5ed24b4da61517560ea91f566afd132d28.zip opie-aca5ba5ed24b4da61517560ea91f566afd132d28.tar.gz opie-aca5ba5ed24b4da61517560ea91f566afd132d28.tar.bz2 |
interface changes
-rw-r--r-- | noncore/net/mail/composemail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 156 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 27 | ||||
-rw-r--r-- | noncore/net/mail/opiemail.cpp | 5 |
4 files changed, 107 insertions, 85 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index 5e823e8..abcc3f6 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp | |||
@@ -1,240 +1,240 @@ | |||
1 | #include <qt.h> | 1 | #include <qt.h> |
2 | 2 | ||
3 | #include <opie/ofiledialog.h> | 3 | #include <opie/ofiledialog.h> |
4 | #include <qpe/resource.h> | 4 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | #include <qpe/global.h> | 6 | #include <qpe/global.h> |
7 | #include <qpe/contact.h> | 7 | #include <qpe/contact.h> |
8 | 8 | ||
9 | #include "composemail.h" | 9 | #include "composemail.h" |
10 | 10 | ||
11 | #include <libmailwrapper/smtpwrapper.h> | 11 | #include <libmailwrapper/smtpwrapper.h> |
12 | 12 | ||
13 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 13 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
14 | : ComposeMailUI( parent, name, modal, flags ) | 14 | : ComposeMailUI( parent, name, modal, flags ) |
15 | { | 15 | { |
16 | settings = s; | 16 | settings = s; |
17 | 17 | ||
18 | QString vfilename = Global::applicationFileName("addressbook", | 18 | QString vfilename = Global::applicationFileName("addressbook", |
19 | "businesscard.vcf"); | 19 | "businesscard.vcf"); |
20 | Contact c; | 20 | Contact c; |
21 | if (QFile::exists(vfilename)) { | 21 | if (QFile::exists(vfilename)) { |
22 | c = Contact::readVCard( vfilename )[0]; | 22 | c = Contact::readVCard( vfilename )[0]; |
23 | } | 23 | } |
24 | 24 | ||
25 | QStringList mails = c.emailList(); | 25 | QStringList mails = c.emailList(); |
26 | QString defmail = c.defaultEmail(); | 26 | QString defmail = c.defaultEmail(); |
27 | 27 | ||
28 | if (defmail.length()!=0) { | 28 | if (defmail.length()!=0) { |
29 | fromBox->insertItem(defmail); | 29 | fromBox->insertItem(defmail); |
30 | } | 30 | } |
31 | QStringList::ConstIterator sit = mails.begin(); | 31 | QStringList::ConstIterator sit = mails.begin(); |
32 | for (;sit!=mails.end();++sit) { | 32 | for (;sit!=mails.end();++sit) { |
33 | if ( (*sit)==defmail) | 33 | if ( (*sit)==defmail) |
34 | continue; | 34 | continue; |
35 | fromBox->insertItem((*sit)); | 35 | fromBox->insertItem((*sit)); |
36 | } | 36 | } |
37 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); | 37 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); |
38 | Config cfg( "mail" ); | 38 | Config cfg( "mail" ); |
39 | cfg.setGroup( "Compose" ); | 39 | cfg.setGroup( "Compose" ); |
40 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 40 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
41 | 41 | ||
42 | attList->addColumn( tr( "Name" ) ); | 42 | attList->addColumn( tr( "Name" ) ); |
43 | attList->addColumn( tr( "Size" ) ); | 43 | attList->addColumn( tr( "Size" ) ); |
44 | 44 | ||
45 | QList<Account> accounts = settings->getAccounts(); | 45 | QList<Account> accounts = settings->getAccounts(); |
46 | 46 | ||
47 | Account *it; | 47 | Account *it; |
48 | for ( it = accounts.first(); it; it = accounts.next() ) { | 48 | for ( it = accounts.first(); it; it = accounts.next() ) { |
49 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 49 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
50 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 50 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
51 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 51 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
52 | smtpAccounts.append( smtp ); | 52 | smtpAccounts.append( smtp ); |
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | if ( smtpAccounts.count() > 0 ) { | 56 | if ( smtpAccounts.count() > 0 ) { |
57 | fillValues( smtpAccountBox->currentItem() ); | 57 | fillValues( smtpAccountBox->currentItem() ); |
58 | } else { | 58 | } else { |
59 | QMessageBox::information( this, tr( "Problem" ), | 59 | QMessageBox::information( this, tr( "Problem" ), |
60 | tr( "<p>Please create an SMTP account first.</p>" ), | 60 | tr( "<p>Please create an SMTP account first.</p>" ), |
61 | tr( "Ok" ) ); | 61 | tr( "Ok" ) ); |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | 64 | ||
65 | connect( smtpAccountBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); | 65 | connect( smtpAccountBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); |
66 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 66 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
67 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 67 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
68 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 68 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
69 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 69 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
70 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 70 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
71 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 71 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
72 | } | 72 | } |
73 | 73 | ||
74 | void ComposeMail::pickAddress( QLineEdit *line ) | 74 | void ComposeMail::pickAddress( QLineEdit *line ) |
75 | { | 75 | { |
76 | QString names = AddressPicker::getNames(); | 76 | QString names = AddressPicker::getNames(); |
77 | if ( line->text().isEmpty() ) { | 77 | if ( line->text().isEmpty() ) { |
78 | line->setText( names ); | 78 | line->setText( names ); |
79 | } else if ( !names.isEmpty() ) { | 79 | } else if ( !names.isEmpty() ) { |
80 | line->setText( line->text() + ", " + names ); | 80 | line->setText( line->text() + ", " + names ); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | void ComposeMail::setTo( const QString & to ) | 85 | void ComposeMail::setTo( const QString & to ) |
86 | { | 86 | { |
87 | /* QString toline; | 87 | /* QString toline; |
88 | QStringList toEntry = to; | 88 | QStringList toEntry = to; |
89 | for ( QStringList::Iterator it = toEntry.begin(); it != toEntry.end(); ++it ) { | 89 | for ( QStringList::Iterator it = toEntry.begin(); it != toEntry.end(); ++it ) { |
90 | toline += (*it); | 90 | toline += (*it); |
91 | } | 91 | } |
92 | toLine->setText( toline ); | 92 | toLine->setText( toline ); |
93 | */ | 93 | */ |
94 | toLine->setText( to ); | 94 | toLine->setText( to ); |
95 | } | 95 | } |
96 | 96 | ||
97 | void ComposeMail::setSubject( const QString & subject ) | 97 | void ComposeMail::setSubject( const QString & subject ) |
98 | { | 98 | { |
99 | subjectLine->setText( subject ); | 99 | subjectLine->setText( subject ); |
100 | } | 100 | } |
101 | 101 | ||
102 | void ComposeMail::setInReplyTo( const QString & messageId ) | 102 | void ComposeMail::setInReplyTo( const QString & messageId ) |
103 | { | 103 | { |
104 | 104 | ||
105 | } | 105 | } |
106 | 106 | ||
107 | void ComposeMail::setMessage( const QString & text ) | 107 | void ComposeMail::setMessage( const QString & text ) |
108 | { | 108 | { |
109 | message->setText( text ); | 109 | message->setText( text ); |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | void ComposeMail::pickAddressTo() | 113 | void ComposeMail::pickAddressTo() |
114 | { | 114 | { |
115 | pickAddress( toLine ); | 115 | pickAddress( toLine ); |
116 | } | 116 | } |
117 | 117 | ||
118 | void ComposeMail::pickAddressCC() | 118 | void ComposeMail::pickAddressCC() |
119 | { | 119 | { |
120 | pickAddress( ccLine ); | 120 | pickAddress( ccLine ); |
121 | } | 121 | } |
122 | 122 | ||
123 | void ComposeMail::pickAddressBCC() | 123 | void ComposeMail::pickAddressBCC() |
124 | { | 124 | { |
125 | pickAddress( bccLine ); | 125 | pickAddress( bccLine ); |
126 | } | 126 | } |
127 | 127 | ||
128 | void ComposeMail::pickAddressReply() | 128 | void ComposeMail::pickAddressReply() |
129 | { | 129 | { |
130 | pickAddress( replyLine ); | 130 | pickAddress( replyLine ); |
131 | } | 131 | } |
132 | 132 | ||
133 | void ComposeMail::fillValues( int current ) | 133 | void ComposeMail::fillValues( int current ) |
134 | { | 134 | { |
135 | #if 0 | 135 | #if 0 |
136 | SMTPaccount *smtp = smtpAccounts.at( current ); | 136 | SMTPaccount *smtp = smtpAccounts.at( current ); |
137 | ccLine->clear(); | 137 | ccLine->clear(); |
138 | if ( smtp->getUseCC() ) { | 138 | if ( smtp->getUseCC() ) { |
139 | ccLine->setText( smtp->getCC() ); | 139 | ccLine->setText( smtp->getCC() ); |
140 | } | 140 | } |
141 | bccLine->clear(); | 141 | bccLine->clear(); |
142 | if ( smtp->getUseBCC() ) { | 142 | if ( smtp->getUseBCC() ) { |
143 | bccLine->setText( smtp->getBCC() ); | 143 | bccLine->setText( smtp->getBCC() ); |
144 | } | 144 | } |
145 | replyLine->clear(); | 145 | replyLine->clear(); |
146 | if ( smtp->getUseReply() ) { | 146 | if ( smtp->getUseReply() ) { |
147 | replyLine->setText( smtp->getReply() ); | 147 | replyLine->setText( smtp->getReply() ); |
148 | } | 148 | } |
149 | sigMultiLine->setText( smtp->getSignature() ); | 149 | sigMultiLine->setText( smtp->getSignature() ); |
150 | #endif | 150 | #endif |
151 | } | 151 | } |
152 | 152 | ||
153 | void ComposeMail::slotAdjustColumns() | 153 | void ComposeMail::slotAdjustColumns() |
154 | { | 154 | { |
155 | int currPage = tabWidget->currentPageIndex(); | 155 | int currPage = tabWidget->currentPageIndex(); |
156 | 156 | ||
157 | tabWidget->showPage( attachTab ); | 157 | tabWidget->showPage( attachTab ); |
158 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | 158 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); |
159 | attList->setColumnWidth( 1, 80 ); | 159 | attList->setColumnWidth( 1, 80 ); |
160 | 160 | ||
161 | tabWidget->setCurrentPage( currPage ); | 161 | tabWidget->setCurrentPage( currPage ); |
162 | } | 162 | } |
163 | 163 | ||
164 | void ComposeMail::addAttachment() | 164 | void ComposeMail::addAttachment() |
165 | { | 165 | { |
166 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); | 166 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); |
167 | if ( !lnk.name().isEmpty() ) { | 167 | if ( !lnk.name().isEmpty() ) { |
168 | Attachment *att = new Attachment( lnk ); | 168 | Attachment *att = new Attachment( lnk ); |
169 | (void) new AttachViewItem( attList, att ); | 169 | (void) new AttachViewItem( attList, att ); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | void ComposeMail::removeAttachment() | 173 | void ComposeMail::removeAttachment() |
174 | { | 174 | { |
175 | if ( !attList->currentItem() ) { | 175 | if ( !attList->currentItem() ) { |
176 | QMessageBox::information( this, tr( "Error" ), | 176 | QMessageBox::information( this, tr( "Error" ), |
177 | tr( "<p>Please select a File.</p>" ), | 177 | tr( "<p>Please select a File.</p>" ), |
178 | tr( "Ok" ) ); | 178 | tr( "Ok" ) ); |
179 | } else { | 179 | } else { |
180 | attList->takeItem( attList->currentItem() ); | 180 | attList->takeItem( attList->currentItem() ); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | void ComposeMail::accept() | 184 | void ComposeMail::accept() |
185 | { | 185 | { |
186 | if ( checkBoxLater->isChecked() ) { | 186 | if ( checkBoxLater->isChecked() ) { |
187 | qDebug( "Send later" ); | 187 | qDebug( "Send later" ); |
188 | } | 188 | } |
189 | 189 | ||
190 | #if 0 | 190 | #if 0 |
191 | qDebug( "Sending Mail with " + | 191 | qDebug( "Sending Mail with " + |
192 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); | 192 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); |
193 | #endif | 193 | #endif |
194 | Mail *mail = new Mail(); | 194 | Mail *mail = new Mail(); |
195 | 195 | ||
196 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); | 196 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); |
197 | mail->setMail(fromBox->currentText()); | 197 | mail->setMail(fromBox->currentText()); |
198 | 198 | ||
199 | if ( !toLine->text().isEmpty() ) { | 199 | if ( !toLine->text().isEmpty() ) { |
200 | mail->setTo( toLine->text() ); | 200 | mail->setTo( toLine->text() ); |
201 | } else { | 201 | } else { |
202 | qDebug( "No Reciever spezified -> returning" ); | 202 | qDebug( "No Reciever spezified -> returning" ); |
203 | return; | 203 | return; |
204 | } | 204 | } |
205 | mail->setName(senderNameEdit->text()); | 205 | mail->setName(senderNameEdit->text()); |
206 | mail->setCC( ccLine->text() ); | 206 | mail->setCC( ccLine->text() ); |
207 | mail->setBCC( bccLine->text() ); | 207 | mail->setBCC( bccLine->text() ); |
208 | mail->setReply( replyLine->text() ); | 208 | mail->setReply( replyLine->text() ); |
209 | mail->setSubject( subjectLine->text() ); | 209 | mail->setSubject( subjectLine->text() ); |
210 | QString txt = message->text(); | 210 | QString txt = message->text(); |
211 | if ( !sigMultiLine->text().isEmpty() ) { | 211 | if ( !sigMultiLine->text().isEmpty() ) { |
212 | txt.append( "\n--\n" ); | 212 | txt.append( "\n--\n" ); |
213 | txt.append( sigMultiLine->text() ); | 213 | txt.append( sigMultiLine->text() ); |
214 | } | 214 | } |
215 | qDebug(txt); | 215 | qDebug(txt); |
216 | mail->setMessage( txt ); | 216 | mail->setMessage( txt ); |
217 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 217 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
218 | while ( it != NULL ) { | 218 | while ( it != NULL ) { |
219 | mail->addAttachment( it->getAttachment() ); | 219 | mail->addAttachment( it->getAttachment() ); |
220 | it = (AttachViewItem *) it->nextSibling(); | 220 | it = (AttachViewItem *) it->nextSibling(); |
221 | } | 221 | } |
222 | 222 | ||
223 | SMTPwrapper wrapper( settings ); | 223 | SMTPwrapper wrapper( smtp ); |
224 | wrapper.sendMail( *mail,smtp,checkBoxLater->isChecked() ); | 224 | wrapper.sendMail( *mail,checkBoxLater->isChecked() ); |
225 | 225 | ||
226 | QDialog::accept(); | 226 | QDialog::accept(); |
227 | } | 227 | } |
228 | 228 | ||
229 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 229 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
230 | : QListViewItem( parent ) | 230 | : QListViewItem( parent ) |
231 | { | 231 | { |
232 | attachment = att; | 232 | attachment = att; |
233 | qDebug( att->getMimeType() ); | 233 | qDebug( att->getMimeType() ); |
234 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | 234 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? |
235 | Resource::loadPixmap( "UnknownDocument-14" ) : | 235 | Resource::loadPixmap( "UnknownDocument-14" ) : |
236 | attachment->getDocLnk().pixmap() ); | 236 | attachment->getDocLnk().pixmap() ); |
237 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 237 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
238 | setText( 1, QString::number( att->getSize() ) ); | 238 | setText( 1, QString::number( att->getSize() ) ); |
239 | } | 239 | } |
240 | 240 | ||
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 3ab6b77..a3c68ae 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,861 +1,875 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | 8 | #include <qt.h> |
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | 10 | ||
11 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
12 | #include <qpe/qcopenvelope_qws.h> | 12 | #include <qpe/qcopenvelope_qws.h> |
13 | 13 | ||
14 | #include <libetpan/libetpan.h> | 14 | #include <libetpan/libetpan.h> |
15 | 15 | ||
16 | #include "smtpwrapper.h" | 16 | #include "smtpwrapper.h" |
17 | #include "mailwrapper.h" | 17 | #include "mailwrapper.h" |
18 | #include "abstractmail.h" | 18 | #include "abstractmail.h" |
19 | #include "logindialog.h" | 19 | #include "logindialog.h" |
20 | #include "mailtypes.h" | 20 | #include "mailtypes.h" |
21 | #include "sendmailprogress.h" | 21 | #include "sendmailprogress.h" |
22 | 22 | ||
23 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; | 23 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; |
24 | 24 | ||
25 | progressMailSend*SMTPwrapper::sendProgress = 0; | 25 | progressMailSend*SMTPwrapper::sendProgress = 0; |
26 | 26 | ||
27 | SMTPwrapper::SMTPwrapper( Settings *s ) | 27 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
28 | : QObject() { | 28 | : QObject() |
29 | settings = s; | 29 | { |
30 | m_SmtpAccount = aSmtp; | ||
30 | Config cfg( "mail" ); | 31 | Config cfg( "mail" ); |
31 | cfg.setGroup( "Status" ); | 32 | cfg.setGroup( "Status" ); |
32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 33 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
33 | emit queuedMails( m_queuedMail ); | 34 | emit queuedMails( m_queuedMail ); |
34 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); | 35 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); |
36 | m_smtp = 0; | ||
37 | } | ||
38 | |||
39 | SMTPwrapper::~SMTPwrapper() | ||
40 | { | ||
41 | disc_server(); | ||
35 | } | 42 | } |
36 | 43 | ||
37 | void SMTPwrapper::emitQCop( int queued ) { | 44 | void SMTPwrapper::emitQCop( int queued ) { |
38 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 45 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
39 | env << queued; | 46 | env << queued; |
40 | } | 47 | } |
41 | 48 | ||
42 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 49 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
43 | switch ( errnum ) { | 50 | switch ( errnum ) { |
44 | case MAILSMTP_NO_ERROR: | 51 | case MAILSMTP_NO_ERROR: |
45 | return tr( "No error" ); | 52 | return tr( "No error" ); |
46 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 53 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
47 | return tr( "Unexpected error code" ); | 54 | return tr( "Unexpected error code" ); |
48 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 55 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
49 | return tr( "Service not available" ); | 56 | return tr( "Service not available" ); |
50 | case MAILSMTP_ERROR_STREAM: | 57 | case MAILSMTP_ERROR_STREAM: |
51 | return tr( "Stream error" ); | 58 | return tr( "Stream error" ); |
52 | case MAILSMTP_ERROR_HOSTNAME: | 59 | case MAILSMTP_ERROR_HOSTNAME: |
53 | return tr( "gethostname() failed" ); | 60 | return tr( "gethostname() failed" ); |
54 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 61 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
55 | return tr( "Not implemented" ); | 62 | return tr( "Not implemented" ); |
56 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 63 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
57 | return tr( "Error, action not taken" ); | 64 | return tr( "Error, action not taken" ); |
58 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 65 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
59 | return tr( "Data exceeds storage allocation" ); | 66 | return tr( "Data exceeds storage allocation" ); |
60 | case MAILSMTP_ERROR_IN_PROCESSING: | 67 | case MAILSMTP_ERROR_IN_PROCESSING: |
61 | return tr( "Error in processing" ); | 68 | return tr( "Error in processing" ); |
62 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 69 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
63 | return tr( "Starttls not supported" ); | 70 | return tr( "Starttls not supported" ); |
64 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 71 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
65 | // return tr( "Insufficient system storage" ); | 72 | // return tr( "Insufficient system storage" ); |
66 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 73 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
67 | return tr( "Mailbox unavailable" ); | 74 | return tr( "Mailbox unavailable" ); |
68 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 75 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
69 | return tr( "Mailbox name not allowed" ); | 76 | return tr( "Mailbox name not allowed" ); |
70 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 77 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
71 | return tr( "Bad command sequence" ); | 78 | return tr( "Bad command sequence" ); |
72 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 79 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
73 | return tr( "User not local" ); | 80 | return tr( "User not local" ); |
74 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 81 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
75 | return tr( "Transaction failed" ); | 82 | return tr( "Transaction failed" ); |
76 | case MAILSMTP_ERROR_MEMORY: | 83 | case MAILSMTP_ERROR_MEMORY: |
77 | return tr( "Memory error" ); | 84 | return tr( "Memory error" ); |
78 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 85 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
79 | return tr( "Connection refused" ); | 86 | return tr( "Connection refused" ); |
80 | default: | 87 | default: |
81 | return tr( "Unknown error code" ); | 88 | return tr( "Unknown error code" ); |
82 | } | 89 | } |
83 | } | 90 | } |
84 | 91 | ||
85 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) { | 92 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) { |
86 | return mailimf_mailbox_new( strdup( name.latin1() ), | 93 | return mailimf_mailbox_new( strdup( name.latin1() ), |
87 | strdup( mail.latin1() ) ); | 94 | strdup( mail.latin1() ) ); |
88 | } | 95 | } |
89 | 96 | ||
90 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { | 97 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { |
91 | mailimf_address_list *addresses; | 98 | mailimf_address_list *addresses; |
92 | 99 | ||
93 | if ( addr.isEmpty() ) | 100 | if ( addr.isEmpty() ) |
94 | return NULL; | 101 | return NULL; |
95 | 102 | ||
96 | addresses = mailimf_address_list_new_empty(); | 103 | addresses = mailimf_address_list_new_empty(); |
97 | 104 | ||
98 | bool literal_open = false; | 105 | bool literal_open = false; |
99 | unsigned int startpos = 0; | 106 | unsigned int startpos = 0; |
100 | QStringList list; | 107 | QStringList list; |
101 | QString s; | 108 | QString s; |
102 | unsigned int i = 0; | 109 | unsigned int i = 0; |
103 | for (; i < addr.length();++i) { | 110 | for (; i < addr.length();++i) { |
104 | switch (addr[i]) { | 111 | switch (addr[i]) { |
105 | case '\"': | 112 | case '\"': |
106 | literal_open = !literal_open; | 113 | literal_open = !literal_open; |
107 | break; | 114 | break; |
108 | case ',': | 115 | case ',': |
109 | if (!literal_open) { | 116 | if (!literal_open) { |
110 | s = addr.mid(startpos,i-startpos); | 117 | s = addr.mid(startpos,i-startpos); |
111 | if (!s.isEmpty()) { | 118 | if (!s.isEmpty()) { |
112 | list.append(s); | 119 | list.append(s); |
113 | qDebug("Appended %s",s.latin1()); | 120 | qDebug("Appended %s",s.latin1()); |
114 | } | 121 | } |
115 | // !!!! this is a MUST BE! | 122 | // !!!! this is a MUST BE! |
116 | startpos = ++i; | 123 | startpos = ++i; |
117 | } | 124 | } |
118 | break; | 125 | break; |
119 | default: | 126 | default: |
120 | break; | 127 | break; |
121 | } | 128 | } |
122 | } | 129 | } |
123 | s = addr.mid(startpos,i-startpos); | 130 | s = addr.mid(startpos,i-startpos); |
124 | if (!s.isEmpty()) { | 131 | if (!s.isEmpty()) { |
125 | list.append(s); | 132 | list.append(s); |
126 | qDebug("Appended %s",s.latin1()); | 133 | qDebug("Appended %s",s.latin1()); |
127 | } | 134 | } |
128 | QStringList::Iterator it; | 135 | QStringList::Iterator it; |
129 | for ( it = list.begin(); it != list.end(); it++ ) { | 136 | for ( it = list.begin(); it != list.end(); it++ ) { |
130 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 137 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
131 | if ( err != MAILIMF_NO_ERROR ) { | 138 | if ( err != MAILIMF_NO_ERROR ) { |
132 | qDebug( "Error parsing" ); | 139 | qDebug( "Error parsing" ); |
133 | qDebug( *it ); | 140 | qDebug( *it ); |
134 | } else { | 141 | } else { |
135 | qDebug( "Parse success! %s",(*it).latin1()); | 142 | qDebug( "Parse success! %s",(*it).latin1()); |
136 | } | 143 | } |
137 | } | 144 | } |
138 | return addresses; | 145 | return addresses; |
139 | } | 146 | } |
140 | 147 | ||
141 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { | 148 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { |
142 | mailimf_fields *fields; | 149 | mailimf_fields *fields; |
143 | mailimf_field *xmailer; | 150 | mailimf_field *xmailer; |
144 | mailimf_mailbox *sender=0,*fromBox=0; | 151 | mailimf_mailbox *sender=0,*fromBox=0; |
145 | mailimf_mailbox_list *from=0; | 152 | mailimf_mailbox_list *from=0; |
146 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 153 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
147 | char *subject = strdup( mail.getSubject().latin1() ); | 154 | char *subject = strdup( mail.getSubject().latin1() ); |
148 | int err; | 155 | int err; |
149 | 156 | ||
150 | sender = newMailbox( mail.getName(), mail.getMail() ); | 157 | sender = newMailbox( mail.getName(), mail.getMail() ); |
151 | if ( sender == NULL ) | 158 | if ( sender == NULL ) |
152 | goto err_free; | 159 | goto err_free; |
153 | 160 | ||
154 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 161 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
155 | if ( fromBox == NULL ) | 162 | if ( fromBox == NULL ) |
156 | goto err_free_sender; | 163 | goto err_free_sender; |
157 | 164 | ||
158 | from = mailimf_mailbox_list_new_empty(); | 165 | from = mailimf_mailbox_list_new_empty(); |
159 | if ( from == NULL ) | 166 | if ( from == NULL ) |
160 | goto err_free_fromBox; | 167 | goto err_free_fromBox; |
161 | 168 | ||
162 | err = mailimf_mailbox_list_add( from, fromBox ); | 169 | err = mailimf_mailbox_list_add( from, fromBox ); |
163 | if ( err != MAILIMF_NO_ERROR ) | 170 | if ( err != MAILIMF_NO_ERROR ) |
164 | goto err_free_from; | 171 | goto err_free_from; |
165 | 172 | ||
166 | to = parseAddresses( mail.getTo() ); | 173 | to = parseAddresses( mail.getTo() ); |
167 | if ( to == NULL ) | 174 | if ( to == NULL ) |
168 | goto err_free_from; | 175 | goto err_free_from; |
169 | 176 | ||
170 | cc = parseAddresses( mail.getCC() ); | 177 | cc = parseAddresses( mail.getCC() ); |
171 | bcc = parseAddresses( mail.getBCC() ); | 178 | bcc = parseAddresses( mail.getBCC() ); |
172 | reply = parseAddresses( mail.getReply() ); | 179 | reply = parseAddresses( mail.getReply() ); |
173 | 180 | ||
174 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 181 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
175 | NULL, NULL, subject ); | 182 | NULL, NULL, subject ); |
176 | if ( fields == NULL ) | 183 | if ( fields == NULL ) |
177 | goto err_free_reply; | 184 | goto err_free_reply; |
178 | 185 | ||
179 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 186 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
180 | strdup( USER_AGENT ) ); | 187 | strdup( USER_AGENT ) ); |
181 | if ( xmailer == NULL ) | 188 | if ( xmailer == NULL ) |
182 | goto err_free_fields; | 189 | goto err_free_fields; |
183 | 190 | ||
184 | err = mailimf_fields_add( fields, xmailer ); | 191 | err = mailimf_fields_add( fields, xmailer ); |
185 | if ( err != MAILIMF_NO_ERROR ) | 192 | if ( err != MAILIMF_NO_ERROR ) |
186 | goto err_free_xmailer; | 193 | goto err_free_xmailer; |
187 | 194 | ||
188 | return fields; // Success :) | 195 | return fields; // Success :) |
189 | 196 | ||
190 | err_free_xmailer: | 197 | err_free_xmailer: |
191 | if (xmailer) | 198 | if (xmailer) |
192 | mailimf_field_free( xmailer ); | 199 | mailimf_field_free( xmailer ); |
193 | err_free_fields: | 200 | err_free_fields: |
194 | if (fields) | 201 | if (fields) |
195 | mailimf_fields_free( fields ); | 202 | mailimf_fields_free( fields ); |
196 | err_free_reply: | 203 | err_free_reply: |
197 | if (reply) | 204 | if (reply) |
198 | mailimf_address_list_free( reply ); | 205 | mailimf_address_list_free( reply ); |
199 | if (bcc) | 206 | if (bcc) |
200 | mailimf_address_list_free( bcc ); | 207 | mailimf_address_list_free( bcc ); |
201 | if (cc) | 208 | if (cc) |
202 | mailimf_address_list_free( cc ); | 209 | mailimf_address_list_free( cc ); |
203 | if (to) | 210 | if (to) |
204 | mailimf_address_list_free( to ); | 211 | mailimf_address_list_free( to ); |
205 | err_free_from: | 212 | err_free_from: |
206 | if (from) | 213 | if (from) |
207 | mailimf_mailbox_list_free( from ); | 214 | mailimf_mailbox_list_free( from ); |
208 | err_free_fromBox: | 215 | err_free_fromBox: |
209 | mailimf_mailbox_free( fromBox ); | 216 | mailimf_mailbox_free( fromBox ); |
210 | err_free_sender: | 217 | err_free_sender: |
211 | if (sender) | 218 | if (sender) |
212 | mailimf_mailbox_free( sender ); | 219 | mailimf_mailbox_free( sender ); |
213 | err_free: | 220 | err_free: |
214 | if (subject) | 221 | if (subject) |
215 | free( subject ); | 222 | free( subject ); |
216 | qDebug( "createImfFields - error" ); | 223 | qDebug( "createImfFields - error" ); |
217 | 224 | ||
218 | return NULL; // Error :( | 225 | return NULL; // Error :( |
219 | } | 226 | } |
220 | 227 | ||
221 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { | 228 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { |
222 | mailmime *txtPart; | 229 | mailmime *txtPart; |
223 | mailmime_fields *fields; | 230 | mailmime_fields *fields; |
224 | mailmime_content *content; | 231 | mailmime_content *content; |
225 | mailmime_parameter *param; | 232 | mailmime_parameter *param; |
226 | int err; | 233 | int err; |
227 | 234 | ||
228 | param = mailmime_parameter_new( strdup( "charset" ), | 235 | param = mailmime_parameter_new( strdup( "charset" ), |
229 | strdup( "iso-8859-1" ) ); | 236 | strdup( "iso-8859-1" ) ); |
230 | if ( param == NULL ) | 237 | if ( param == NULL ) |
231 | goto err_free; | 238 | goto err_free; |
232 | 239 | ||
233 | content = mailmime_content_new_with_str( "text/plain" ); | 240 | content = mailmime_content_new_with_str( "text/plain" ); |
234 | if ( content == NULL ) | 241 | if ( content == NULL ) |
235 | goto err_free_param; | 242 | goto err_free_param; |
236 | 243 | ||
237 | err = clist_append( content->ct_parameters, param ); | 244 | err = clist_append( content->ct_parameters, param ); |
238 | if ( err != MAILIMF_NO_ERROR ) | 245 | if ( err != MAILIMF_NO_ERROR ) |
239 | goto err_free_content; | 246 | goto err_free_content; |
240 | 247 | ||
241 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 248 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
242 | if ( fields == NULL ) | 249 | if ( fields == NULL ) |
243 | goto err_free_content; | 250 | goto err_free_content; |
244 | 251 | ||
245 | txtPart = mailmime_new_empty( content, fields ); | 252 | txtPart = mailmime_new_empty( content, fields ); |
246 | if ( txtPart == NULL ) | 253 | if ( txtPart == NULL ) |
247 | goto err_free_fields; | 254 | goto err_free_fields; |
248 | 255 | ||
249 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 256 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
250 | if ( err != MAILIMF_NO_ERROR ) | 257 | if ( err != MAILIMF_NO_ERROR ) |
251 | goto err_free_txtPart; | 258 | goto err_free_txtPart; |
252 | 259 | ||
253 | return txtPart; // Success :) | 260 | return txtPart; // Success :) |
254 | 261 | ||
255 | err_free_txtPart: | 262 | err_free_txtPart: |
256 | mailmime_free( txtPart ); | 263 | mailmime_free( txtPart ); |
257 | err_free_fields: | 264 | err_free_fields: |
258 | mailmime_fields_free( fields ); | 265 | mailmime_fields_free( fields ); |
259 | err_free_content: | 266 | err_free_content: |
260 | mailmime_content_free( content ); | 267 | mailmime_content_free( content ); |
261 | err_free_param: | 268 | err_free_param: |
262 | mailmime_parameter_free( param ); | 269 | mailmime_parameter_free( param ); |
263 | err_free: | 270 | err_free: |
264 | qDebug( "buildTxtPart - error" ); | 271 | qDebug( "buildTxtPart - error" ); |
265 | 272 | ||
266 | return NULL; // Error :( | 273 | return NULL; // Error :( |
267 | } | 274 | } |
268 | 275 | ||
269 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | 276 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { |
270 | mailmime * filePart = 0; | 277 | mailmime * filePart = 0; |
271 | mailmime_fields * fields = 0; | 278 | mailmime_fields * fields = 0; |
272 | mailmime_content * content = 0; | 279 | mailmime_content * content = 0; |
273 | mailmime_parameter * param = 0; | 280 | mailmime_parameter * param = 0; |
274 | char*name = 0; | 281 | char*name = 0; |
275 | char*file = 0; | 282 | char*file = 0; |
276 | int err; | 283 | int err; |
277 | 284 | ||
278 | int pos = filename.findRev( '/' ); | 285 | int pos = filename.findRev( '/' ); |
279 | 286 | ||
280 | if (filename.length()>0) { | 287 | if (filename.length()>0) { |
281 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 288 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
282 | name = strdup( tmp.latin1() ); // just filename | 289 | name = strdup( tmp.latin1() ); // just filename |
283 | file = strdup( filename.latin1() ); // full name with path | 290 | file = strdup( filename.latin1() ); // full name with path |
284 | } | 291 | } |
285 | 292 | ||
286 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 293 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
287 | int mechanism = MAILMIME_MECHANISM_BASE64; | 294 | int mechanism = MAILMIME_MECHANISM_BASE64; |
288 | 295 | ||
289 | if ( mimetype.startsWith( "text/" ) ) { | 296 | if ( mimetype.startsWith( "text/" ) ) { |
290 | param = mailmime_parameter_new( strdup( "charset" ), | 297 | param = mailmime_parameter_new( strdup( "charset" ), |
291 | strdup( "iso-8859-1" ) ); | 298 | strdup( "iso-8859-1" ) ); |
292 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 299 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
293 | } | 300 | } |
294 | 301 | ||
295 | fields = mailmime_fields_new_filename( | 302 | fields = mailmime_fields_new_filename( |
296 | disptype, name, | 303 | disptype, name, |
297 | mechanism ); | 304 | mechanism ); |
298 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 305 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
299 | if (content!=0 && fields != 0) { | 306 | if (content!=0 && fields != 0) { |
300 | if (param) { | 307 | if (param) { |
301 | clist_append(content->ct_parameters,param); | 308 | clist_append(content->ct_parameters,param); |
302 | param = 0; | 309 | param = 0; |
303 | } | 310 | } |
304 | if (filename.length()>0) { | 311 | if (filename.length()>0) { |
305 | QFileInfo f(filename); | 312 | QFileInfo f(filename); |
306 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 313 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
307 | clist_append(content->ct_parameters,param); | 314 | clist_append(content->ct_parameters,param); |
308 | param = 0; | 315 | param = 0; |
309 | } | 316 | } |
310 | filePart = mailmime_new_empty( content, fields ); | 317 | filePart = mailmime_new_empty( content, fields ); |
311 | } | 318 | } |
312 | if (filePart) { | 319 | if (filePart) { |
313 | if (filename.length()>0) { | 320 | if (filename.length()>0) { |
314 | err = mailmime_set_body_file( filePart, file ); | 321 | err = mailmime_set_body_file( filePart, file ); |
315 | } else { | 322 | } else { |
316 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | 323 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); |
317 | } | 324 | } |
318 | if (err != MAILIMF_NO_ERROR) { | 325 | if (err != MAILIMF_NO_ERROR) { |
319 | qDebug("Error setting body with file %s",file); | 326 | qDebug("Error setting body with file %s",file); |
320 | mailmime_free( filePart ); | 327 | mailmime_free( filePart ); |
321 | filePart = 0; | 328 | filePart = 0; |
322 | } | 329 | } |
323 | } | 330 | } |
324 | 331 | ||
325 | if (!filePart) { | 332 | if (!filePart) { |
326 | if ( param != NULL ) { | 333 | if ( param != NULL ) { |
327 | mailmime_parameter_free( param ); | 334 | mailmime_parameter_free( param ); |
328 | } | 335 | } |
329 | if (content) { | 336 | if (content) { |
330 | mailmime_content_free( content ); | 337 | mailmime_content_free( content ); |
331 | } | 338 | } |
332 | if (fields) { | 339 | if (fields) { |
333 | mailmime_fields_free( fields ); | 340 | mailmime_fields_free( fields ); |
334 | } else { | 341 | } else { |
335 | if (name) { | 342 | if (name) { |
336 | free( name ); | 343 | free( name ); |
337 | } | 344 | } |
338 | if (file) { | 345 | if (file) { |
339 | free( file ); | 346 | free( file ); |
340 | } | 347 | } |
341 | } | 348 | } |
342 | } | 349 | } |
343 | return filePart; // Success :) | 350 | return filePart; // Success :) |
344 | 351 | ||
345 | } | 352 | } |
346 | 353 | ||
347 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) { | 354 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) { |
348 | const Attachment *it; | 355 | const Attachment *it; |
349 | unsigned int count = files.count(); | 356 | unsigned int count = files.count(); |
350 | qDebug("List contains %i values",count); | 357 | qDebug("List contains %i values",count); |
351 | for ( unsigned int i = 0; i < count; ++i ) { | 358 | for ( unsigned int i = 0; i < count; ++i ) { |
352 | qDebug( "Adding file" ); | 359 | qDebug( "Adding file" ); |
353 | mailmime *filePart; | 360 | mailmime *filePart; |
354 | int err; | 361 | int err; |
355 | it = ((QList<Attachment>)files).at(i); | 362 | it = ((QList<Attachment>)files).at(i); |
356 | 363 | ||
357 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 364 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
358 | if ( filePart == NULL ) { | 365 | if ( filePart == NULL ) { |
359 | qDebug( "addFileParts: error adding file:" ); | 366 | qDebug( "addFileParts: error adding file:" ); |
360 | qDebug( it->getFileName() ); | 367 | qDebug( it->getFileName() ); |
361 | continue; | 368 | continue; |
362 | } | 369 | } |
363 | err = mailmime_smart_add_part( message, filePart ); | 370 | err = mailmime_smart_add_part( message, filePart ); |
364 | if ( err != MAILIMF_NO_ERROR ) { | 371 | if ( err != MAILIMF_NO_ERROR ) { |
365 | mailmime_free( filePart ); | 372 | mailmime_free( filePart ); |
366 | qDebug("error smart add"); | 373 | qDebug("error smart add"); |
367 | } | 374 | } |
368 | } | 375 | } |
369 | } | 376 | } |
370 | 377 | ||
371 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) { | 378 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) { |
372 | mailmime *message, *txtPart; | 379 | mailmime *message, *txtPart; |
373 | mailimf_fields *fields; | 380 | mailimf_fields *fields; |
374 | int err; | 381 | int err; |
375 | 382 | ||
376 | fields = createImfFields( mail ); | 383 | fields = createImfFields( mail ); |
377 | if ( fields == NULL ) | 384 | if ( fields == NULL ) |
378 | goto err_free; | 385 | goto err_free; |
379 | 386 | ||
380 | message = mailmime_new_message_data( NULL ); | 387 | message = mailmime_new_message_data( NULL ); |
381 | if ( message == NULL ) | 388 | if ( message == NULL ) |
382 | goto err_free_fields; | 389 | goto err_free_fields; |
383 | 390 | ||
384 | mailmime_set_imf_fields( message, fields ); | 391 | mailmime_set_imf_fields( message, fields ); |
385 | 392 | ||
386 | txtPart = buildTxtPart( mail.getMessage() ); | 393 | txtPart = buildTxtPart( mail.getMessage() ); |
387 | 394 | ||
388 | if ( txtPart == NULL ) | 395 | if ( txtPart == NULL ) |
389 | goto err_free_message; | 396 | goto err_free_message; |
390 | 397 | ||
391 | err = mailmime_smart_add_part( message, txtPart ); | 398 | err = mailmime_smart_add_part( message, txtPart ); |
392 | if ( err != MAILIMF_NO_ERROR ) | 399 | if ( err != MAILIMF_NO_ERROR ) |
393 | goto err_free_txtPart; | 400 | goto err_free_txtPart; |
394 | 401 | ||
395 | addFileParts( message, mail.getAttachments() ); | 402 | addFileParts( message, mail.getAttachments() ); |
396 | 403 | ||
397 | return message; // Success :) | 404 | return message; // Success :) |
398 | 405 | ||
399 | err_free_txtPart: | 406 | err_free_txtPart: |
400 | mailmime_free( txtPart ); | 407 | mailmime_free( txtPart ); |
401 | err_free_message: | 408 | err_free_message: |
402 | mailmime_free( message ); | 409 | mailmime_free( message ); |
403 | err_free_fields: | 410 | err_free_fields: |
404 | mailimf_fields_free( fields ); | 411 | mailimf_fields_free( fields ); |
405 | err_free: | 412 | err_free: |
406 | qDebug( "createMimeMail: error" ); | 413 | qDebug( "createMimeMail: error" ); |
407 | 414 | ||
408 | return NULL; // Error :( | 415 | return NULL; // Error :( |
409 | } | 416 | } |
410 | 417 | ||
411 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) { | 418 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) { |
412 | mailimf_field *field; | 419 | mailimf_field *field; |
413 | clistiter *it; | 420 | clistiter *it; |
414 | 421 | ||
415 | it = clist_begin( fields->fld_list ); | 422 | it = clist_begin( fields->fld_list ); |
416 | while ( it ) { | 423 | while ( it ) { |
417 | field = (mailimf_field *) it->data; | 424 | field = (mailimf_field *) it->data; |
418 | if ( field->fld_type == type ) { | 425 | if ( field->fld_type == type ) { |
419 | return field; | 426 | return field; |
420 | } | 427 | } |
421 | it = it->next; | 428 | it = it->next; |
422 | } | 429 | } |
423 | 430 | ||
424 | return NULL; | 431 | return NULL; |
425 | } | 432 | } |
426 | 433 | ||
427 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) { | 434 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) { |
428 | clistiter *it, *it2; | 435 | clistiter *it, *it2; |
429 | 436 | ||
430 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 437 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
431 | mailimf_address *addr; | 438 | mailimf_address *addr; |
432 | addr = (mailimf_address *) it->data; | 439 | addr = (mailimf_address *) it->data; |
433 | 440 | ||
434 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 441 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
435 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 442 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
436 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 443 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
437 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 444 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
438 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 445 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
439 | mailimf_mailbox *mbox; | 446 | mailimf_mailbox *mbox; |
440 | mbox = (mailimf_mailbox *) it2->data; | 447 | mbox = (mailimf_mailbox *) it2->data; |
441 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 448 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
442 | } | 449 | } |
443 | } | 450 | } |
444 | } | 451 | } |
445 | } | 452 | } |
446 | 453 | ||
447 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) { | 454 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) { |
448 | clist *rcptList; | 455 | clist *rcptList; |
449 | mailimf_field *field; | 456 | mailimf_field *field; |
450 | 457 | ||
451 | rcptList = esmtp_address_list_new(); | 458 | rcptList = esmtp_address_list_new(); |
452 | 459 | ||
453 | field = getField( fields, MAILIMF_FIELD_TO ); | 460 | field = getField( fields, MAILIMF_FIELD_TO ); |
454 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 461 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
455 | && field->fld_data.fld_to->to_addr_list ) { | 462 | && field->fld_data.fld_to->to_addr_list ) { |
456 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 463 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
457 | } | 464 | } |
458 | 465 | ||
459 | field = getField( fields, MAILIMF_FIELD_CC ); | 466 | field = getField( fields, MAILIMF_FIELD_CC ); |
460 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 467 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
461 | && field->fld_data.fld_cc->cc_addr_list ) { | 468 | && field->fld_data.fld_cc->cc_addr_list ) { |
462 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 469 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
463 | } | 470 | } |
464 | 471 | ||
465 | field = getField( fields, MAILIMF_FIELD_BCC ); | 472 | field = getField( fields, MAILIMF_FIELD_BCC ); |
466 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 473 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
467 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 474 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
468 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 475 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
469 | } | 476 | } |
470 | 477 | ||
471 | return rcptList; | 478 | return rcptList; |
472 | } | 479 | } |
473 | 480 | ||
474 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) { | 481 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) { |
475 | char *from = NULL; | 482 | char *from = NULL; |
476 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 483 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
477 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 484 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
478 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 485 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
479 | clistiter *it; | 486 | clistiter *it; |
480 | for ( it = clist_begin( cl ); it; it = it->next ) { | 487 | for ( it = clist_begin( cl ); it; it = it->next ) { |
481 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 488 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
482 | from = strdup( mb->mb_addr_spec ); | 489 | from = strdup( mb->mb_addr_spec ); |
483 | } | 490 | } |
484 | } | 491 | } |
485 | 492 | ||
486 | return from; | 493 | return from; |
487 | } | 494 | } |
488 | 495 | ||
489 | char *SMTPwrapper::getFrom( mailmime *mail ) { | 496 | char *SMTPwrapper::getFrom( mailmime *mail ) { |
490 | /* no need to delete - its just a pointer to structure content */ | 497 | /* no need to delete - its just a pointer to structure content */ |
491 | mailimf_field *ffrom = 0; | 498 | mailimf_field *ffrom = 0; |
492 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 499 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
493 | return getFrom(ffrom); | 500 | return getFrom(ffrom); |
494 | } | 501 | } |
495 | 502 | ||
496 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 503 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
497 | if (SMTPwrapper::sendProgress) { | 504 | if (SMTPwrapper::sendProgress) { |
498 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 505 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
499 | qApp->processEvents(); | 506 | qApp->processEvents(); |
500 | } | 507 | } |
501 | } | 508 | } |
502 | 509 | ||
503 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 510 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
504 | if (!mail) | 511 | if (!mail) |
505 | return; | 512 | return; |
506 | QString localfolders = AbstractMail::defaultLocalfolder(); | 513 | QString localfolders = AbstractMail::defaultLocalfolder(); |
507 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 514 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
508 | wrap->createMbox(box); | 515 | wrap->createMbox(box); |
509 | wrap->storeMessage(mail,length,box); | 516 | wrap->storeMessage(mail,length,box); |
510 | delete wrap; | 517 | delete wrap; |
511 | } | 518 | } |
512 | 519 | ||
513 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { | 520 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
514 | clist *rcpts = 0; | 521 | clist *rcpts = 0; |
515 | char *from, *data; | 522 | char *from, *data; |
516 | size_t size; | 523 | size_t size; |
517 | 524 | ||
518 | if ( smtp == NULL ) { | ||
519 | return; | ||
520 | } | ||
521 | from = data = 0; | 525 | from = data = 0; |
522 | 526 | ||
523 | mailmessage * msg = 0; | 527 | mailmessage * msg = 0; |
524 | msg = mime_message_init(mail); | 528 | msg = mime_message_init(mail); |
525 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 529 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
526 | int r = mailmessage_fetch(msg,&data,&size); | 530 | int r = mailmessage_fetch(msg,&data,&size); |
527 | mime_message_detach_mime(msg); | 531 | mime_message_detach_mime(msg); |
528 | mailmessage_free(msg); | 532 | mailmessage_free(msg); |
529 | if (r != MAIL_NO_ERROR || !data) { | 533 | if (r != MAIL_NO_ERROR || !data) { |
530 | if (data) | 534 | if (data) |
531 | free(data); | 535 | free(data); |
532 | qDebug("Error fetching mime..."); | 536 | qDebug("Error fetching mime..."); |
533 | return; | 537 | return; |
534 | } | 538 | } |
535 | msg = 0; | 539 | msg = 0; |
536 | if (later) { | 540 | if (later) { |
537 | storeMail(data,size,"Outgoing"); | 541 | storeMail(data,size,"Outgoing"); |
538 | if (data) | 542 | if (data) |
539 | free( data ); | 543 | free( data ); |
540 | Config cfg( "mail" ); | 544 | Config cfg( "mail" ); |
541 | cfg.setGroup( "Status" ); | 545 | cfg.setGroup( "Status" ); |
542 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 546 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
543 | emit queuedMails( m_queuedMail ); | 547 | emit queuedMails( m_queuedMail ); |
544 | return; | 548 | return; |
545 | } | 549 | } |
546 | from = getFrom( mail ); | 550 | from = getFrom( mail ); |
547 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 551 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
548 | smtpSend(from,rcpts,data,size,smtp); | 552 | smtpSend(from,rcpts,data,size); |
549 | if (data) { | 553 | if (data) { |
550 | free(data); | 554 | free(data); |
551 | } | 555 | } |
552 | if (from) { | 556 | if (from) { |
553 | free(from); | 557 | free(from); |
554 | } | 558 | } |
555 | if (rcpts) | 559 | if (rcpts) |
556 | smtp_address_list_free( rcpts ); | 560 | smtp_address_list_free( rcpts ); |
557 | } | 561 | } |
558 | 562 | ||
559 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 563 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
560 | { | 564 | { |
561 | if (data) { | 565 | if (data) { |
562 | storeMail(data,size,"Sendfailed"); | 566 | storeMail(data,size,"Sendfailed"); |
563 | } | 567 | } |
564 | if (failuremessage) { | 568 | if (failuremessage) { |
565 | QMessageBox::critical(0,tr("Error sending mail"), | 569 | QMessageBox::critical(0,tr("Error sending mail"), |
566 | tr("<center>%1</center>").arg(failuremessage)); | 570 | tr("<center>%1</center>").arg(failuremessage)); |
567 | } | 571 | } |
568 | } | 572 | } |
569 | 573 | ||
570 | int SMTPwrapper::start_smtp_tls(mailsmtp *session) | 574 | int SMTPwrapper::start_smtp_tls() |
571 | { | 575 | { |
572 | if (!session) { | 576 | if (!m_smtp) { |
573 | return MAILSMTP_ERROR_IN_PROCESSING; | 577 | return MAILSMTP_ERROR_IN_PROCESSING; |
574 | } | 578 | } |
575 | int err = mailesmtp_starttls(session); | 579 | int err = mailesmtp_starttls(m_smtp); |
576 | if (err != MAILSMTP_NO_ERROR) return err; | 580 | if (err != MAILSMTP_NO_ERROR) return err; |
577 | mailstream_low * low; | 581 | mailstream_low * low; |
578 | mailstream_low * new_low; | 582 | mailstream_low * new_low; |
579 | low = mailstream_get_low(session->stream); | 583 | low = mailstream_get_low(m_smtp->stream); |
580 | if (!low) { | 584 | if (!low) { |
581 | return MAILSMTP_ERROR_IN_PROCESSING; | 585 | return MAILSMTP_ERROR_IN_PROCESSING; |
582 | } | 586 | } |
583 | int fd = mailstream_low_get_fd(low); | 587 | int fd = mailstream_low_get_fd(low); |
584 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 588 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
585 | mailstream_low_free(low); | 589 | mailstream_low_free(low); |
586 | mailstream_set_low(session->stream, new_low); | 590 | mailstream_set_low(m_smtp->stream, new_low); |
587 | } else { | 591 | } else { |
588 | return MAILSMTP_ERROR_IN_PROCESSING; | 592 | return MAILSMTP_ERROR_IN_PROCESSING; |
589 | } | 593 | } |
590 | return err; | 594 | return err; |
591 | } | 595 | } |
592 | 596 | ||
593 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { | 597 | void SMTPwrapper::connect_server() |
598 | { | ||
594 | const char *server, *user, *pass; | 599 | const char *server, *user, *pass; |
595 | bool ssl; | 600 | bool ssl; |
596 | uint16_t port; | 601 | uint16_t port; |
597 | mailsmtp *session; | ||
598 | int err,result; | ||
599 | QString failuretext = ""; | ||
600 | |||
601 | result = 1; | ||
602 | server = user = pass = 0; | ||
603 | server = smtp->getServer().latin1(); | ||
604 | |||
605 | // FIXME: currently only TLS and Plain work. | ||
606 | |||
607 | ssl = false; | 602 | ssl = false; |
608 | bool try_tls = true; | 603 | bool try_tls = true; |
609 | bool force_tls=false; | 604 | bool force_tls=false; |
610 | 605 | server = user = pass = 0; | |
611 | if ( smtp->ConnectionType() == 2 ) { | 606 | QString failuretext = ""; |
607 | |||
608 | if (m_smtp || !m_SmtpAccount) { | ||
609 | return; | ||
610 | } | ||
611 | server = m_SmtpAccount->getServer().latin1(); | ||
612 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | ||
612 | ssl = true; | 613 | ssl = true; |
613 | try_tls = false; | 614 | try_tls = false; |
614 | } else if (smtp->ConnectionType() == 1) { | 615 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
615 | force_tls = true; | 616 | force_tls = true; |
616 | } | 617 | } |
618 | int result = 1; | ||
619 | port = m_SmtpAccount->getPort().toUInt(); | ||
617 | 620 | ||
618 | port = smtp->getPort().toUInt(); | 621 | m_smtp = mailsmtp_new( 20, &progress ); |
619 | 622 | if ( m_smtp == NULL ) { | |
620 | session = mailsmtp_new( 20, &progress ); | ||
621 | if ( session == NULL ) { | ||
622 | /* no failure message cause this happens when problems with memory - than we | 623 | /* no failure message cause this happens when problems with memory - than we |
623 | we can not display any messagebox */ | 624 | we can not display any messagebox */ |
624 | return 0; | 625 | return; |
625 | } | 626 | } |
626 | 627 | ||
628 | int err = MAILSMTP_NO_ERROR; | ||
627 | qDebug( "Servername %s at port %i", server, port ); | 629 | qDebug( "Servername %s at port %i", server, port ); |
628 | if ( ssl ) { | 630 | if ( ssl ) { |
629 | qDebug( "SSL session" ); | 631 | qDebug( "SSL session" ); |
630 | err = mailsmtp_ssl_connect( session, server, port ); | 632 | err = mailsmtp_ssl_connect( m_smtp, server, port ); |
631 | } else { | 633 | } else { |
632 | qDebug( "No SSL session" ); | 634 | qDebug( "No SSL session" ); |
633 | err = mailsmtp_socket_connect( session, server, port ); | 635 | err = mailsmtp_socket_connect( m_smtp, server, port ); |
634 | } | 636 | } |
635 | if ( err != MAILSMTP_NO_ERROR ) { | 637 | if ( err != MAILSMTP_NO_ERROR ) { |
636 | qDebug("Error init connection"); | 638 | qDebug("Error init connection"); |
637 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 639 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
638 | result = 0; | 640 | result = 0; |
639 | } | 641 | } |
640 | 642 | ||
641 | /* switch to tls after init 'cause there it will send the ehlo */ | 643 | /* switch to tls after init 'cause there it will send the ehlo */ |
642 | if (result) { | 644 | if (result) { |
643 | err = mailsmtp_init( session ); | 645 | err = mailsmtp_init( m_smtp ); |
644 | if (err != MAILSMTP_NO_ERROR) { | 646 | if (err != MAILSMTP_NO_ERROR) { |
645 | result = 0; | 647 | result = 0; |
646 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 648 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
647 | } | 649 | } |
648 | } | 650 | } |
649 | 651 | ||
650 | if (try_tls) { | 652 | if (try_tls) { |
651 | err = start_smtp_tls(session); | 653 | err = start_smtp_tls(); |
652 | if (err != MAILSMTP_NO_ERROR) { | 654 | if (err != MAILSMTP_NO_ERROR) { |
653 | try_tls = false; | 655 | try_tls = false; |
654 | } else { | 656 | } else { |
655 | err = mailesmtp_ehlo(session); | 657 | err = mailesmtp_ehlo(m_smtp); |
656 | } | 658 | } |
657 | } | 659 | } |
658 | 660 | ||
659 | if (!try_tls && force_tls) { | 661 | if (!try_tls && force_tls) { |
660 | result = 0; | 662 | result = 0; |
661 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 663 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
662 | } | 664 | } |
663 | 665 | ||
664 | if (result==1 && smtp->getLogin() ) { | 666 | if (result==1 && m_SmtpAccount->getLogin() ) { |
665 | qDebug("smtp with auth"); | 667 | qDebug("smtp with auth"); |
666 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 668 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
667 | // get'em | 669 | // get'em |
668 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 670 | LoginDialog login( m_SmtpAccount->getUser(), |
671 | m_SmtpAccount->getPassword(), NULL, 0, true ); | ||
669 | login.show(); | 672 | login.show(); |
670 | if ( QDialog::Accepted == login.exec() ) { | 673 | if ( QDialog::Accepted == login.exec() ) { |
671 | // ok | 674 | // ok |
672 | user = login.getUser().latin1(); | 675 | user = login.getUser().latin1(); |
673 | pass = login.getPassword().latin1(); | 676 | pass = login.getPassword().latin1(); |
674 | } else { | 677 | } else { |
675 | result = 0; | 678 | result = 0; |
676 | failuretext=tr("Login aborted - storing mail to localfolder"); | 679 | failuretext=tr("Login aborted - storing mail to localfolder"); |
677 | } | 680 | } |
678 | } else { | 681 | } else { |
679 | user = smtp->getUser().latin1(); | 682 | user = m_SmtpAccount->getUser().latin1(); |
680 | pass = smtp->getPassword().latin1(); | 683 | pass = m_SmtpAccount->getPassword().latin1(); |
681 | } | 684 | } |
682 | qDebug( "session->auth: %i", session->auth); | 685 | qDebug( "session->auth: %i", m_smtp->auth); |
683 | if (result) { | 686 | if (result) { |
684 | err = mailsmtp_auth( session, (char*)user, (char*)pass ); | 687 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); |
685 | if ( err == MAILSMTP_NO_ERROR ) { | 688 | if ( err == MAILSMTP_NO_ERROR ) { |
686 | qDebug("auth ok"); | 689 | qDebug("auth ok"); |
687 | } else { | 690 | } else { |
688 | failuretext = tr("Authentification failed"); | 691 | failuretext = tr("Authentification failed"); |
689 | result = 0; | 692 | result = 0; |
690 | } | 693 | } |
691 | } | 694 | } |
692 | } | 695 | } |
696 | } | ||
693 | 697 | ||
694 | if (result) { | 698 | void SMTPwrapper::disc_server() |
695 | err = mailsmtp_send( session, from, rcpts, data, size ); | 699 | { |
700 | if (m_smtp) { | ||
701 | mailsmtp_quit( m_smtp ); | ||
702 | mailsmtp_free( m_smtp ); | ||
703 | m_smtp = 0; | ||
704 | } | ||
705 | } | ||
706 | |||
707 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | ||
708 | { | ||
709 | int err,result; | ||
710 | QString failuretext = ""; | ||
711 | |||
712 | connect_server(); | ||
713 | |||
714 | result = 1; | ||
715 | if (m_smtp) { | ||
716 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | ||
696 | if ( err != MAILSMTP_NO_ERROR ) { | 717 | if ( err != MAILSMTP_NO_ERROR ) { |
697 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 718 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
698 | result = 0; | 719 | result = 0; |
699 | } | 720 | } |
721 | } else { | ||
722 | result = 0; | ||
700 | } | 723 | } |
701 | 724 | ||
702 | if (!result) { | 725 | if (!result) { |
703 | storeFailedMail(data,size,failuretext); | 726 | storeFailedMail(data,size,failuretext); |
704 | } else { | 727 | } else { |
705 | qDebug( "Mail sent." ); | 728 | qDebug( "Mail sent." ); |
706 | storeMail(data,size,"Sent"); | 729 | storeMail(data,size,"Sent"); |
707 | } | 730 | } |
708 | if (session) { | ||
709 | mailsmtp_quit( session ); | ||
710 | mailsmtp_free( session ); | ||
711 | } | ||
712 | return result; | 731 | return result; |
713 | } | 732 | } |
714 | 733 | ||
715 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { | 734 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
735 | { | ||
716 | mailmime * mimeMail; | 736 | mailmime * mimeMail; |
717 | 737 | ||
718 | SMTPaccount *smtp = aSmtp; | ||
719 | |||
720 | if (!later && !smtp) { | ||
721 | qDebug("Didn't get any send method - giving up"); | ||
722 | return; | ||
723 | } | ||
724 | mimeMail = createMimeMail(mail ); | 738 | mimeMail = createMimeMail(mail ); |
725 | if ( mimeMail == NULL ) { | 739 | if ( mimeMail == NULL ) { |
726 | qDebug( "sendMail: error creating mime mail" ); | 740 | qDebug( "sendMail: error creating mime mail" ); |
727 | } else { | 741 | } else { |
728 | sendProgress = new progressMailSend(); | 742 | sendProgress = new progressMailSend(); |
729 | sendProgress->show(); | 743 | sendProgress->show(); |
730 | sendProgress->setMaxMails(1); | 744 | sendProgress->setMaxMails(1); |
731 | smtpSend( mimeMail,later,smtp); | 745 | smtpSend( mimeMail,later); |
732 | qDebug("Clean up done"); | 746 | qDebug("Clean up done"); |
733 | sendProgress->hide(); | 747 | sendProgress->hide(); |
734 | delete sendProgress; | 748 | delete sendProgress; |
735 | sendProgress = 0; | 749 | sendProgress = 0; |
736 | mailmime_free( mimeMail ); | 750 | mailmime_free( mimeMail ); |
737 | } | 751 | } |
738 | } | 752 | } |
739 | 753 | ||
740 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) { | 754 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { |
741 | size_t curTok = 0; | 755 | size_t curTok = 0; |
742 | mailimf_fields *fields = 0; | 756 | mailimf_fields *fields = 0; |
743 | mailimf_field*ffrom = 0; | 757 | mailimf_field*ffrom = 0; |
744 | clist *rcpts = 0; | 758 | clist *rcpts = 0; |
745 | char*from = 0; | 759 | char*from = 0; |
746 | int res = 0; | 760 | int res = 0; |
747 | 761 | ||
748 | encodedString * data = wrap->fetchRawBody(*which); | 762 | encodedString * data = wrap->fetchRawBody(*which); |
749 | if (!data) | 763 | if (!data) |
750 | return 0; | 764 | return 0; |
751 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 765 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
752 | if (err != MAILIMF_NO_ERROR) { | 766 | if (err != MAILIMF_NO_ERROR) { |
753 | delete data; | 767 | delete data; |
754 | delete wrap; | 768 | delete wrap; |
755 | return 0; | 769 | return 0; |
756 | } | 770 | } |
757 | 771 | ||
758 | rcpts = createRcptList( fields ); | 772 | rcpts = createRcptList( fields ); |
759 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 773 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
760 | from = getFrom(ffrom); | 774 | from = getFrom(ffrom); |
761 | 775 | ||
762 | if (rcpts && from) { | 776 | if (rcpts && from) { |
763 | res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); | 777 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
764 | } | 778 | } |
765 | if (fields) { | 779 | if (fields) { |
766 | mailimf_fields_free(fields); | 780 | mailimf_fields_free(fields); |
767 | fields = 0; | 781 | fields = 0; |
768 | } | 782 | } |
769 | if (data) { | 783 | if (data) { |
770 | delete data; | 784 | delete data; |
771 | } | 785 | } |
772 | if (from) { | 786 | if (from) { |
773 | free(from); | 787 | free(from); |
774 | } | 788 | } |
775 | if (rcpts) { | 789 | if (rcpts) { |
776 | smtp_address_list_free( rcpts ); | 790 | smtp_address_list_free( rcpts ); |
777 | } | 791 | } |
778 | return res; | 792 | return res; |
779 | } | 793 | } |
780 | 794 | ||
781 | /* this is a special fun */ | 795 | /* this is a special fun */ |
782 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | 796 | bool SMTPwrapper::flushOutbox() { |
783 | bool returnValue = true; | 797 | bool returnValue = true; |
784 | 798 | ||
785 | qDebug("Sending the queue"); | 799 | qDebug("Sending the queue"); |
786 | if (!smtp) { | 800 | if (!m_SmtpAccount) { |
787 | qDebug("No smtp account given"); | 801 | qDebug("No smtp account given"); |
788 | return false; | 802 | return false; |
789 | } | 803 | } |
790 | 804 | ||
791 | bool reset_user_value = false; | 805 | bool reset_user_value = false; |
792 | QString localfolders = AbstractMail::defaultLocalfolder(); | 806 | QString localfolders = AbstractMail::defaultLocalfolder(); |
793 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 807 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
794 | if (!wrap) { | 808 | if (!wrap) { |
795 | qDebug("memory error"); | 809 | qDebug("memory error"); |
796 | return false; | 810 | return false; |
797 | } | 811 | } |
798 | QString oldPw, oldUser; | 812 | QString oldPw, oldUser; |
799 | QList<RecMail> mailsToSend; | 813 | QList<RecMail> mailsToSend; |
800 | QList<RecMail> mailsToRemove; | 814 | QList<RecMail> mailsToRemove; |
801 | QString mbox("Outgoing"); | 815 | QString mbox("Outgoing"); |
802 | wrap->listMessages(mbox,mailsToSend); | 816 | wrap->listMessages(mbox,mailsToSend); |
803 | if (mailsToSend.count()==0) { | 817 | if (mailsToSend.count()==0) { |
804 | delete wrap; | 818 | delete wrap; |
805 | qDebug("No mails to send"); | 819 | qDebug("No mails to send"); |
806 | return false; | 820 | return false; |
807 | } | 821 | } |
808 | 822 | ||
809 | oldPw = smtp->getPassword(); | 823 | oldPw = m_SmtpAccount->getPassword(); |
810 | oldUser = smtp->getUser(); | 824 | oldUser = m_SmtpAccount->getUser(); |
811 | if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) { | 825 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
812 | // get'em | 826 | // get'em |
813 | QString user,pass; | 827 | QString user,pass; |
814 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 828 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
815 | login.show(); | 829 | login.show(); |
816 | if ( QDialog::Accepted == login.exec() ) { | 830 | if ( QDialog::Accepted == login.exec() ) { |
817 | // ok | 831 | // ok |
818 | user = login.getUser().latin1(); | 832 | user = login.getUser().latin1(); |
819 | pass = login.getPassword().latin1(); | 833 | pass = login.getPassword().latin1(); |
820 | reset_user_value = true; | 834 | reset_user_value = true; |
821 | smtp->setUser(user); | 835 | m_SmtpAccount->setUser(user); |
822 | smtp->setPassword(pass); | 836 | m_SmtpAccount->setPassword(pass); |
823 | } else { | 837 | } else { |
824 | return true; | 838 | return true; |
825 | } | 839 | } |
826 | } | 840 | } |
827 | 841 | ||
828 | 842 | ||
829 | mailsToSend.setAutoDelete(false); | 843 | mailsToSend.setAutoDelete(false); |
830 | sendProgress = new progressMailSend(); | 844 | sendProgress = new progressMailSend(); |
831 | sendProgress->show(); | 845 | sendProgress->show(); |
832 | sendProgress->setMaxMails(mailsToSend.count()); | 846 | sendProgress->setMaxMails(mailsToSend.count()); |
833 | 847 | ||
834 | while (mailsToSend.count()>0) { | 848 | while (mailsToSend.count()>0) { |
835 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 849 | if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { |
836 | QMessageBox::critical(0,tr("Error sending mail"), | 850 | QMessageBox::critical(0,tr("Error sending mail"), |
837 | tr("Error sending queued mail - breaking")); | 851 | tr("Error sending queued mail - breaking")); |
838 | returnValue = false; | 852 | returnValue = false; |
839 | break; | 853 | break; |
840 | } | 854 | } |
841 | mailsToRemove.append(mailsToSend.at(0)); | 855 | mailsToRemove.append(mailsToSend.at(0)); |
842 | mailsToSend.removeFirst(); | 856 | mailsToSend.removeFirst(); |
843 | sendProgress->setCurrentMails(mailsToRemove.count()); | 857 | sendProgress->setCurrentMails(mailsToRemove.count()); |
844 | } | 858 | } |
845 | if (reset_user_value) { | 859 | if (reset_user_value) { |
846 | smtp->setUser(oldUser); | 860 | m_SmtpAccount->setUser(oldUser); |
847 | smtp->setPassword(oldPw); | 861 | m_SmtpAccount->setPassword(oldPw); |
848 | } | 862 | } |
849 | Config cfg( "mail" ); | 863 | Config cfg( "mail" ); |
850 | cfg.setGroup( "Status" ); | 864 | cfg.setGroup( "Status" ); |
851 | m_queuedMail = 0; | 865 | m_queuedMail = 0; |
852 | cfg.writeEntry( "outgoing", m_queuedMail ); | 866 | cfg.writeEntry( "outgoing", m_queuedMail ); |
853 | emit queuedMails( m_queuedMail ); | 867 | emit queuedMails( m_queuedMail ); |
854 | sendProgress->hide(); | 868 | sendProgress->hide(); |
855 | delete sendProgress; | 869 | delete sendProgress; |
856 | sendProgress = 0; | 870 | sendProgress = 0; |
857 | wrap->deleteMails(mbox,mailsToRemove); | 871 | wrap->deleteMails(mbox,mailsToRemove); |
858 | mailsToSend.setAutoDelete(true); | 872 | mailsToSend.setAutoDelete(true); |
859 | delete wrap; | 873 | delete wrap; |
860 | return returnValue; | 874 | return returnValue; |
861 | } | 875 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 75e4891..7f6aac1 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -1,76 +1,83 @@ | |||
1 | // -*- Mode: C++; -*- | ||
1 | #ifndef SMTPwrapper_H | 2 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 3 | #define SMTPwrapper_H |
3 | 4 | ||
4 | #include <qpe/applnk.h> | 5 | #include <qpe/applnk.h> |
5 | 6 | ||
6 | #include <qbitarray.h> | 7 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 8 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 9 | #include <libetpan/clist.h> |
9 | 10 | ||
10 | #include "settings.h" | 11 | #include "settings.h" |
11 | 12 | ||
12 | class Mail; | 13 | class Mail; |
13 | class AbstractMail; | 14 | class AbstractMail; |
14 | class RecMail; | 15 | class RecMail; |
15 | class Attachment; | 16 | class Attachment; |
16 | struct mailimf_fields; | 17 | struct mailimf_fields; |
17 | struct mailimf_field; | 18 | struct mailimf_field; |
18 | struct mailimf_mailbox; | 19 | struct mailimf_mailbox; |
19 | struct mailmime; | 20 | struct mailmime; |
20 | struct mailimf_address_list; | 21 | struct mailimf_address_list; |
21 | class progressMailSend; | 22 | class progressMailSend; |
22 | struct mailsmtp; | 23 | struct mailsmtp; |
24 | class SMTPaccount; | ||
23 | 25 | ||
24 | class SMTPwrapper : public QObject | 26 | class SMTPwrapper : public QObject |
25 | { | 27 | { |
26 | Q_OBJECT | 28 | Q_OBJECT |
27 | 29 | ||
28 | public: | 30 | public: |
29 | SMTPwrapper( Settings *s ); | 31 | SMTPwrapper(SMTPaccount * aSmtp); |
30 | virtual ~SMTPwrapper(){} | 32 | virtual ~SMTPwrapper(); |
31 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); | 33 | void sendMail(const Mail& mail,bool later=false ); |
32 | bool flushOutbox(SMTPaccount*smtp); | 34 | bool flushOutbox(); |
33 | 35 | ||
34 | static progressMailSend*sendProgress; | 36 | static progressMailSend*sendProgress; |
35 | 37 | ||
36 | signals: | 38 | signals: |
37 | void queuedMails( int ); | 39 | void queuedMails( int ); |
38 | 40 | ||
39 | protected: | 41 | protected: |
42 | mailsmtp *m_smtp; | ||
43 | SMTPaccount * m_SmtpAccount; | ||
44 | |||
45 | void connect_server(); | ||
46 | void disc_server(); | ||
47 | int start_smtp_tls(); | ||
48 | |||
40 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 49 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
41 | mailimf_fields *createImfFields(const Mail &mail ); | 50 | mailimf_fields *createImfFields(const Mail &mail ); |
42 | mailmime *createMimeMail(const Mail&mail ); | 51 | mailmime *createMimeMail(const Mail&mail ); |
43 | 52 | ||
44 | mailimf_address_list *parseAddresses(const QString&addr ); | 53 | mailimf_address_list *parseAddresses(const QString&addr ); |
45 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 54 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
46 | mailmime *buildTxtPart(const QString&str ); | 55 | mailmime *buildTxtPart(const QString&str ); |
47 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | 56 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
48 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); | 57 | void smtpSend( mailmime *mail,bool later); |
49 | clist *createRcptList( mailimf_fields *fields ); | 58 | clist *createRcptList( mailimf_fields *fields ); |
50 | 59 | ||
51 | static void storeMail(const char*mail, size_t length, const QString&box); | 60 | static void storeMail(const char*mail, size_t length, const QString&box); |
52 | static QString mailsmtpError( int err ); | 61 | static QString mailsmtpError( int err ); |
53 | static void progress( size_t current, size_t maximum ); | 62 | static void progress( size_t current, size_t maximum ); |
54 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 63 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
55 | static char *getFrom( mailmime *mail ); | 64 | static char *getFrom( mailmime *mail ); |
56 | static char *getFrom( mailimf_field *ffrom); | 65 | static char *getFrom( mailimf_field *ffrom); |
57 | static mailimf_field *getField( mailimf_fields *fields, int type ); | 66 | static mailimf_field *getField( mailimf_fields *fields, int type ); |
58 | static int start_smtp_tls(mailsmtp *session); | ||
59 | 67 | ||
60 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); | 68 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); |
61 | 69 | ||
62 | void storeMail(mailmime*mail, const QString&box); | 70 | void storeMail(mailmime*mail, const QString&box); |
63 | Settings *settings; | ||
64 | 71 | ||
65 | int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); | 72 | int sendQueuedMail(AbstractMail*wrap,RecMail*which); |
66 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); | 73 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); |
67 | 74 | ||
68 | int m_queuedMail; | 75 | int m_queuedMail; |
69 | static const char* USER_AGENT; | 76 | static const char* USER_AGENT; |
70 | 77 | ||
71 | protected slots: | 78 | protected slots: |
72 | void emitQCop( int queued ); | 79 | void emitQCop( int queued ); |
73 | 80 | ||
74 | }; | 81 | }; |
75 | 82 | ||
76 | #endif | 83 | #endif |
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp index ea0019d..0795436 100644 --- a/noncore/net/mail/opiemail.cpp +++ b/noncore/net/mail/opiemail.cpp | |||
@@ -1,228 +1,229 @@ | |||
1 | #include <qmessagebox.h> | 1 | #include <qmessagebox.h> |
2 | #include "settingsdialog.h" | 2 | #include "settingsdialog.h" |
3 | #include "opiemail.h" | 3 | #include "opiemail.h" |
4 | #include "editaccounts.h" | 4 | #include "editaccounts.h" |
5 | #include "composemail.h" | 5 | #include "composemail.h" |
6 | #include <libmailwrapper/smtpwrapper.h> | 6 | #include <libmailwrapper/smtpwrapper.h> |
7 | #include <qpe/qcopenvelope_qws.h> | 7 | #include <qpe/qcopenvelope_qws.h> |
8 | #include <qpe/resource.h> | 8 | #include <qpe/resource.h> |
9 | #include <qaction.h> | 9 | #include <qaction.h> |
10 | #include <qapplication.h> | 10 | #include <qapplication.h> |
11 | #include <libmailwrapper/mailtypes.h> | 11 | #include <libmailwrapper/mailtypes.h> |
12 | #include <libmailwrapper/abstractmail.h> | 12 | #include <libmailwrapper/abstractmail.h> |
13 | #include "mailistviewitem.h" | 13 | #include "mailistviewitem.h" |
14 | #include "viewmail.h" | 14 | #include "viewmail.h" |
15 | #include "selectstore.h" | 15 | #include "selectstore.h" |
16 | #include "selectsmtp.h" | 16 | #include "selectsmtp.h" |
17 | 17 | ||
18 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | 18 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) |
19 | : MainWindow( parent, name, WStyle_ContextHelp ) | 19 | : MainWindow( parent, name, WStyle_ContextHelp ) |
20 | { | 20 | { |
21 | settings = new Settings(); | 21 | settings = new Settings(); |
22 | 22 | ||
23 | folderView->populate( settings->getAccounts() ); | 23 | folderView->populate( settings->getAccounts() ); |
24 | } | 24 | } |
25 | 25 | ||
26 | OpieMail::~OpieMail() | 26 | OpieMail::~OpieMail() |
27 | { | 27 | { |
28 | if (settings) delete settings; | 28 | if (settings) delete settings; |
29 | } | 29 | } |
30 | 30 | ||
31 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 31 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) |
32 | { | 32 | { |
33 | // copied from old mail2 | 33 | // copied from old mail2 |
34 | if (msg == "writeMail(QString,QString)") { | 34 | if (msg == "writeMail(QString,QString)") { |
35 | QDataStream stream(data,IO_ReadOnly); | 35 | QDataStream stream(data,IO_ReadOnly); |
36 | QString name, email; | 36 | QString name, email; |
37 | stream >> name >> email; | 37 | stream >> name >> email; |
38 | // removing the whitespaces at beginning and end is needed! | 38 | // removing the whitespaces at beginning and end is needed! |
39 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); | 39 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); |
40 | } else if (msg == "newMail()") { | 40 | } else if (msg == "newMail()") { |
41 | slotComposeMail(); | 41 | slotComposeMail(); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | void OpieMail::slotwriteMail(const QString&name,const QString&email) | 45 | void OpieMail::slotwriteMail(const QString&name,const QString&email) |
46 | { | 46 | { |
47 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); | 47 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); |
48 | if (!email.isEmpty()) { | 48 | if (!email.isEmpty()) { |
49 | if (!name.isEmpty()) { | 49 | if (!name.isEmpty()) { |
50 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); | 50 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); |
51 | } else { | 51 | } else { |
52 | compose.setTo(email); | 52 | compose.setTo(email); |
53 | } | 53 | } |
54 | } | 54 | } |
55 | compose.showMaximized(); | 55 | compose.showMaximized(); |
56 | compose.slotAdjustColumns(); | 56 | compose.slotAdjustColumns(); |
57 | compose.exec(); | 57 | compose.exec(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void OpieMail::slotComposeMail() | 60 | void OpieMail::slotComposeMail() |
61 | { | 61 | { |
62 | qDebug( "Compose Mail" ); | 62 | qDebug( "Compose Mail" ); |
63 | slotwriteMail(0l,0l); | 63 | slotwriteMail(0l,0l); |
64 | } | 64 | } |
65 | 65 | ||
66 | void OpieMail::slotSendQueued() | 66 | void OpieMail::slotSendQueued() |
67 | { | 67 | { |
68 | qDebug( "Send Queued" ); | 68 | qDebug( "Send Queued" ); |
69 | SMTPaccount *smtp = 0; | 69 | SMTPaccount *smtp = 0; |
70 | 70 | ||
71 | QList<Account> list = settings->getAccounts(); | 71 | QList<Account> list = settings->getAccounts(); |
72 | QList<SMTPaccount> smtpList; | 72 | QList<SMTPaccount> smtpList; |
73 | smtpList.setAutoDelete(false); | 73 | smtpList.setAutoDelete(false); |
74 | Account *it; | 74 | Account *it; |
75 | for ( it = list.first(); it; it = list.next() ) { | 75 | for ( it = list.first(); it; it = list.next() ) { |
76 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 76 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
77 | smtp = static_cast<SMTPaccount *>(it); | 77 | smtp = static_cast<SMTPaccount *>(it); |
78 | smtpList.append(smtp); | 78 | smtpList.append(smtp); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | if (smtpList.count()==0) { | 81 | if (smtpList.count()==0) { |
82 | QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); | 82 | QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); |
83 | return; | 83 | return; |
84 | } | 84 | } |
85 | if (smtpList.count()==1) { | 85 | if (smtpList.count()==1) { |
86 | smtp = smtpList.at(0); | 86 | smtp = smtpList.at(0); |
87 | } else { | 87 | } else { |
88 | smtp = 0; | 88 | smtp = 0; |
89 | selectsmtp selsmtp; | 89 | selectsmtp selsmtp; |
90 | selsmtp.setSelectionlist(&smtpList); | 90 | selsmtp.setSelectionlist(&smtpList); |
91 | selsmtp.showMaximized(); | 91 | selsmtp.showMaximized(); |
92 | if (selsmtp.exec()==QDialog::Accepted) { | 92 | if (selsmtp.exec()==QDialog::Accepted) { |
93 | smtp = selsmtp.selected_smtp(); | 93 | smtp = selsmtp.selected_smtp(); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | if (smtp) { | 96 | if (smtp) { |
97 | SMTPwrapper * wrap = new SMTPwrapper(settings); | 97 | SMTPwrapper * wrap = new SMTPwrapper(smtp); |
98 | if ( wrap->flushOutbox(smtp) ) { | 98 | if ( wrap->flushOutbox() ) { |
99 | QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); | 99 | QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); |
100 | } | 100 | } |
101 | delete wrap; | ||
101 | } | 102 | } |
102 | } | 103 | } |
103 | 104 | ||
104 | void OpieMail::slotSearchMails() | 105 | void OpieMail::slotSearchMails() |
105 | { | 106 | { |
106 | qDebug( "Search Mails" ); | 107 | qDebug( "Search Mails" ); |
107 | } | 108 | } |
108 | 109 | ||
109 | void OpieMail::slotEditSettings() | 110 | void OpieMail::slotEditSettings() |
110 | { | 111 | { |
111 | SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); | 112 | SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); |
112 | settingsDialog.showMaximized(); | 113 | settingsDialog.showMaximized(); |
113 | settingsDialog.exec(); | 114 | settingsDialog.exec(); |
114 | } | 115 | } |
115 | 116 | ||
116 | void OpieMail::slotEditAccounts() | 117 | void OpieMail::slotEditAccounts() |
117 | { | 118 | { |
118 | qDebug( "Edit Accounts" ); | 119 | qDebug( "Edit Accounts" ); |
119 | EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); | 120 | EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); |
120 | eaDialog.showMaximized(); | 121 | eaDialog.showMaximized(); |
121 | eaDialog.slotAdjustColumns(); | 122 | eaDialog.slotAdjustColumns(); |
122 | eaDialog.exec(); | 123 | eaDialog.exec(); |
123 | if ( settings ) delete settings; | 124 | if ( settings ) delete settings; |
124 | settings = new Settings(); | 125 | settings = new Settings(); |
125 | 126 | ||
126 | folderView->populate( settings->getAccounts() ); | 127 | folderView->populate( settings->getAccounts() ); |
127 | } | 128 | } |
128 | 129 | ||
129 | void OpieMail::displayMail() | 130 | void OpieMail::displayMail() |
130 | { | 131 | { |
131 | QListViewItem*item = mailView->currentItem(); | 132 | QListViewItem*item = mailView->currentItem(); |
132 | if (!item) return; | 133 | if (!item) return; |
133 | RecMail mail = ((MailListViewItem*)item)->data(); | 134 | RecMail mail = ((MailListViewItem*)item)->data(); |
134 | RecBody body = folderView->fetchBody(mail); | 135 | RecBody body = folderView->fetchBody(mail); |
135 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); | 136 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); |
136 | readMail.setBody( body ); | 137 | readMail.setBody( body ); |
137 | readMail.setMail( mail ); | 138 | readMail.setMail( mail ); |
138 | readMail.showMaximized(); | 139 | readMail.showMaximized(); |
139 | readMail.exec(); | 140 | readMail.exec(); |
140 | 141 | ||
141 | if ( readMail.deleted ) { | 142 | if ( readMail.deleted ) { |
142 | folderView->refreshCurrent(); | 143 | folderView->refreshCurrent(); |
143 | } else { | 144 | } else { |
144 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); | 145 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); |
145 | } | 146 | } |
146 | } | 147 | } |
147 | 148 | ||
148 | void OpieMail::slotDeleteMail() | 149 | void OpieMail::slotDeleteMail() |
149 | { | 150 | { |
150 | if (!mailView->currentItem()) return; | 151 | if (!mailView->currentItem()) return; |
151 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 152 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
152 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 153 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
153 | mail.Wrapper()->deleteMail( mail ); | 154 | mail.Wrapper()->deleteMail( mail ); |
154 | folderView->refreshCurrent(); | 155 | folderView->refreshCurrent(); |
155 | } | 156 | } |
156 | } | 157 | } |
157 | 158 | ||
158 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) | 159 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) |
159 | { | 160 | { |
160 | /* just the RIGHT button - or hold on pda */ | 161 | /* just the RIGHT button - or hold on pda */ |
161 | if (button!=2) {return;} | 162 | if (button!=2) {return;} |
162 | qDebug("Event right/hold"); | 163 | qDebug("Event right/hold"); |
163 | if (!item) return; | 164 | if (!item) return; |
164 | QPopupMenu *m = new QPopupMenu(0); | 165 | QPopupMenu *m = new QPopupMenu(0); |
165 | if (m) { | 166 | if (m) { |
166 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); | 167 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); |
167 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); | 168 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); |
168 | m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); | 169 | m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); |
169 | m->setFocus(); | 170 | m->setFocus(); |
170 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 171 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
171 | delete m; | 172 | delete m; |
172 | } | 173 | } |
173 | } | 174 | } |
174 | 175 | ||
175 | void OpieMail::slotShowFolders( bool show ) | 176 | void OpieMail::slotShowFolders( bool show ) |
176 | { | 177 | { |
177 | qDebug( "Show Folders" ); | 178 | qDebug( "Show Folders" ); |
178 | if ( show && folderView->isHidden() ) { | 179 | if ( show && folderView->isHidden() ) { |
179 | qDebug( "-> showing" ); | 180 | qDebug( "-> showing" ); |
180 | folderView->show(); | 181 | folderView->show(); |
181 | } else if ( !show && !folderView->isHidden() ) { | 182 | } else if ( !show && !folderView->isHidden() ) { |
182 | qDebug( "-> hiding" ); | 183 | qDebug( "-> hiding" ); |
183 | folderView->hide(); | 184 | folderView->hide(); |
184 | } | 185 | } |
185 | } | 186 | } |
186 | 187 | ||
187 | void OpieMail::refreshMailView(QList<RecMail>*list) | 188 | void OpieMail::refreshMailView(QList<RecMail>*list) |
188 | { | 189 | { |
189 | MailListViewItem*item = 0; | 190 | MailListViewItem*item = 0; |
190 | mailView->clear(); | 191 | mailView->clear(); |
191 | for (unsigned int i = 0; i < list->count();++i) { | 192 | for (unsigned int i = 0; i < list->count();++i) { |
192 | item = new MailListViewItem(mailView,item); | 193 | item = new MailListViewItem(mailView,item); |
193 | item->storeData(*(list->at(i))); | 194 | item->storeData(*(list->at(i))); |
194 | item->showEntry(); | 195 | item->showEntry(); |
195 | } | 196 | } |
196 | } | 197 | } |
197 | 198 | ||
198 | void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) | 199 | void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) |
199 | { | 200 | { |
200 | /* just LEFT button - or tap with stylus on pda */ | 201 | /* just LEFT button - or tap with stylus on pda */ |
201 | if (button!=1) return; | 202 | if (button!=1) return; |
202 | if (!item) return; | 203 | if (!item) return; |
203 | displayMail(); | 204 | displayMail(); |
204 | } | 205 | } |
205 | 206 | ||
206 | void OpieMail::slotMoveCopyMail() | 207 | void OpieMail::slotMoveCopyMail() |
207 | { | 208 | { |
208 | if (!mailView->currentItem()) return; | 209 | if (!mailView->currentItem()) return; |
209 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 210 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
210 | AbstractMail*targetMail = 0; | 211 | AbstractMail*targetMail = 0; |
211 | QString targetFolder = ""; | 212 | QString targetFolder = ""; |
212 | Selectstore sels; | 213 | Selectstore sels; |
213 | folderView->setupFolderselect(&sels); | 214 | folderView->setupFolderselect(&sels); |
214 | if (!sels.exec()) return; | 215 | if (!sels.exec()) return; |
215 | targetMail = sels.currentMail(); | 216 | targetMail = sels.currentMail(); |
216 | targetFolder = sels.currentFolder(); | 217 | targetFolder = sels.currentFolder(); |
217 | if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) || | 218 | if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) || |
218 | targetFolder.isEmpty()) { | 219 | targetFolder.isEmpty()) { |
219 | return; | 220 | return; |
220 | } | 221 | } |
221 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { | 222 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { |
222 | QMessageBox::critical(0,tr("Error creating new Folder"), | 223 | QMessageBox::critical(0,tr("Error creating new Folder"), |
223 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 224 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
224 | return; | 225 | return; |
225 | } | 226 | } |
226 | mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); | 227 | mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); |
227 | folderView->refreshCurrent(); | 228 | folderView->refreshCurrent(); |
228 | } | 229 | } |