author | alwin <alwin> | 2003-12-22 02:37:35 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-22 02:37:35 (UTC) |
commit | 9e7aafdb7c76d29fee742d53131a73dd60aded2b (patch) (unidiff) | |
tree | e98f9fe1233455f458738acbfd29bac78dd03342 | |
parent | 7c016e1a75970cb7c28d70398ad20c708cdb452b (diff) | |
download | opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.zip opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.gz opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.bz2 |
- storing mails send in outgoing (if queued) or sent (if sent) folder
TODO: flush queue, cleanup SMTP code, select smtp-account if more than
one when flush the outgoing queue
-rw-r--r-- | noncore/net/mail/composemail.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 61 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 61 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 6 |
9 files changed, 162 insertions, 31 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index f680f5c..f532815 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp | |||
@@ -1,214 +1,215 @@ | |||
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 | 6 | ||
7 | #include "composemail.h" | 7 | #include "composemail.h" |
8 | #include "smtpwrapper.h" | 8 | #include "smtpwrapper.h" |
9 | 9 | ||
10 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 10 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
11 | : ComposeMailUI( parent, name, modal, flags ) | 11 | : ComposeMailUI( parent, name, modal, flags ) |
12 | { | 12 | { |
13 | settings = s; | 13 | settings = s; |
14 | 14 | ||
15 | Config cfg( "mail" ); | 15 | Config cfg( "mail" ); |
16 | cfg.setGroup( "Compose" ); | 16 | cfg.setGroup( "Compose" ); |
17 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 17 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
18 | 18 | ||
19 | attList->addColumn( tr( "Name" ) ); | 19 | attList->addColumn( tr( "Name" ) ); |
20 | attList->addColumn( tr( "Size" ) ); | 20 | attList->addColumn( tr( "Size" ) ); |
21 | 21 | ||
22 | QList<Account> accounts = settings->getAccounts(); | 22 | QList<Account> accounts = settings->getAccounts(); |
23 | Account *it; | 23 | Account *it; |
24 | for ( it = accounts.first(); it; it = accounts.next() ) { | 24 | for ( it = accounts.first(); it; it = accounts.next() ) { |
25 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 25 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
26 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 26 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
27 | fromBox->insertItem( smtp->getMail() ); | 27 | fromBox->insertItem( smtp->getMail() ); |
28 | smtpAccounts.append( smtp ); | 28 | smtpAccounts.append( smtp ); |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | if ( smtpAccounts.count() > 0 ) { | 32 | if ( smtpAccounts.count() > 0 ) { |
33 | fillValues( fromBox->currentItem() ); | 33 | fillValues( fromBox->currentItem() ); |
34 | } else { | 34 | } else { |
35 | QMessageBox::information( this, tr( "Problem" ), | 35 | QMessageBox::information( this, tr( "Problem" ), |
36 | tr( "<p>Please create an SMTP account first.</p>" ), | 36 | tr( "<p>Please create an SMTP account first.</p>" ), |
37 | tr( "Ok" ) ); | 37 | tr( "Ok" ) ); |
38 | return; | 38 | return; |
39 | } | 39 | } |
40 | 40 | ||
41 | connect( fromBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); | 41 | connect( fromBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); |
42 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 42 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
43 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 43 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
44 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 44 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
45 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 45 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
46 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 46 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
47 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 47 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
48 | } | 48 | } |
49 | 49 | ||
50 | void ComposeMail::pickAddress( QLineEdit *line ) | 50 | void ComposeMail::pickAddress( QLineEdit *line ) |
51 | { | 51 | { |
52 | QString names = AddressPicker::getNames(); | 52 | QString names = AddressPicker::getNames(); |
53 | if ( line->text().isEmpty() ) { | 53 | if ( line->text().isEmpty() ) { |
54 | line->setText( names ); | 54 | line->setText( names ); |
55 | } else if ( !names.isEmpty() ) { | 55 | } else if ( !names.isEmpty() ) { |
56 | line->setText( line->text() + ", " + names ); | 56 | line->setText( line->text() + ", " + names ); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | void ComposeMail::setTo( const QString & to ) | 61 | void ComposeMail::setTo( const QString & to ) |
62 | { | 62 | { |
63 | /* QString toline; | 63 | /* QString toline; |
64 | QStringList toEntry = to; | 64 | QStringList toEntry = to; |
65 | for ( QStringList::Iterator it = toEntry.begin(); it != toEntry.end(); ++it ) { | 65 | for ( QStringList::Iterator it = toEntry.begin(); it != toEntry.end(); ++it ) { |
66 | toline += (*it); | 66 | toline += (*it); |
67 | } | 67 | } |
68 | toLine->setText( toline ); | 68 | toLine->setText( toline ); |
69 | */ | 69 | */ |
70 | toLine->setText( to ); | 70 | toLine->setText( to ); |
71 | } | 71 | } |
72 | 72 | ||
73 | void ComposeMail::setSubject( const QString & subject ) | 73 | void ComposeMail::setSubject( const QString & subject ) |
74 | { | 74 | { |
75 | subjectLine->setText( subject ); | 75 | subjectLine->setText( subject ); |
76 | } | 76 | } |
77 | 77 | ||
78 | void ComposeMail::setInReplyTo( const QString & messageId ) | 78 | void ComposeMail::setInReplyTo( const QString & messageId ) |
79 | { | 79 | { |
80 | 80 | ||
81 | } | 81 | } |
82 | 82 | ||
83 | void ComposeMail::setMessage( const QString & text ) | 83 | void ComposeMail::setMessage( const QString & text ) |
84 | { | 84 | { |
85 | message->setText( text ); | 85 | message->setText( text ); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | void ComposeMail::pickAddressTo() | 89 | void ComposeMail::pickAddressTo() |
90 | { | 90 | { |
91 | pickAddress( toLine ); | 91 | pickAddress( toLine ); |
92 | } | 92 | } |
93 | 93 | ||
94 | void ComposeMail::pickAddressCC() | 94 | void ComposeMail::pickAddressCC() |
95 | { | 95 | { |
96 | pickAddress( ccLine ); | 96 | pickAddress( ccLine ); |
97 | } | 97 | } |
98 | 98 | ||
99 | void ComposeMail::pickAddressBCC() | 99 | void ComposeMail::pickAddressBCC() |
100 | { | 100 | { |
101 | pickAddress( bccLine ); | 101 | pickAddress( bccLine ); |
102 | } | 102 | } |
103 | 103 | ||
104 | void ComposeMail::pickAddressReply() | 104 | void ComposeMail::pickAddressReply() |
105 | { | 105 | { |
106 | pickAddress( replyLine ); | 106 | pickAddress( replyLine ); |
107 | } | 107 | } |
108 | 108 | ||
109 | void ComposeMail::fillValues( int current ) | 109 | void ComposeMail::fillValues( int current ) |
110 | { | 110 | { |
111 | SMTPaccount *smtp = smtpAccounts.at( current ); | 111 | SMTPaccount *smtp = smtpAccounts.at( current ); |
112 | 112 | ||
113 | ccLine->clear(); | 113 | ccLine->clear(); |
114 | if ( smtp->getUseCC() ) { | 114 | if ( smtp->getUseCC() ) { |
115 | ccLine->setText( smtp->getCC() ); | 115 | ccLine->setText( smtp->getCC() ); |
116 | } | 116 | } |
117 | bccLine->clear(); | 117 | bccLine->clear(); |
118 | if ( smtp->getUseBCC() ) { | 118 | if ( smtp->getUseBCC() ) { |
119 | bccLine->setText( smtp->getBCC() ); | 119 | bccLine->setText( smtp->getBCC() ); |
120 | } | 120 | } |
121 | replyLine->clear(); | 121 | replyLine->clear(); |
122 | if ( smtp->getUseReply() ) { | 122 | if ( smtp->getUseReply() ) { |
123 | replyLine->setText( smtp->getReply() ); | 123 | replyLine->setText( smtp->getReply() ); |
124 | } | 124 | } |
125 | 125 | ||
126 | sigMultiLine->setText( smtp->getSignature() ); | 126 | sigMultiLine->setText( smtp->getSignature() ); |
127 | } | 127 | } |
128 | 128 | ||
129 | void ComposeMail::slotAdjustColumns() | 129 | void ComposeMail::slotAdjustColumns() |
130 | { | 130 | { |
131 | int currPage = tabWidget->currentPageIndex(); | 131 | int currPage = tabWidget->currentPageIndex(); |
132 | 132 | ||
133 | tabWidget->showPage( attachTab ); | 133 | tabWidget->showPage( attachTab ); |
134 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | 134 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); |
135 | attList->setColumnWidth( 1, 80 ); | 135 | attList->setColumnWidth( 1, 80 ); |
136 | 136 | ||
137 | tabWidget->setCurrentPage( currPage ); | 137 | tabWidget->setCurrentPage( currPage ); |
138 | } | 138 | } |
139 | 139 | ||
140 | void ComposeMail::addAttachment() | 140 | void ComposeMail::addAttachment() |
141 | { | 141 | { |
142 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); | 142 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); |
143 | if ( !lnk.name().isEmpty() ) { | 143 | if ( !lnk.name().isEmpty() ) { |
144 | Attachment *att = new Attachment( lnk ); | 144 | Attachment *att = new Attachment( lnk ); |
145 | (void) new AttachViewItem( attList, att ); | 145 | (void) new AttachViewItem( attList, att ); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | void ComposeMail::removeAttachment() | 149 | void ComposeMail::removeAttachment() |
150 | { | 150 | { |
151 | if ( !attList->currentItem() ) { | 151 | if ( !attList->currentItem() ) { |
152 | QMessageBox::information( this, tr( "Error" ), | 152 | QMessageBox::information( this, tr( "Error" ), |
153 | tr( "<p>Please select a File.</p>" ), | 153 | tr( "<p>Please select a File.</p>" ), |
154 | tr( "Ok" ) ); | 154 | tr( "Ok" ) ); |
155 | } else { | 155 | } else { |
156 | attList->takeItem( attList->currentItem() ); | 156 | attList->takeItem( attList->currentItem() ); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | void ComposeMail::accept() | 160 | void ComposeMail::accept() |
161 | { | 161 | { |
162 | if ( checkBoxLater->isChecked() ) { | 162 | if ( checkBoxLater->isChecked() ) { |
163 | qDebug( "Send later" ); | 163 | qDebug( "Send later" ); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | qDebug( "Sending Mail with " + | 167 | qDebug( "Sending Mail with " + |
168 | smtpAccounts.at( fromBox->currentItem() )->getAccountName() ); | 168 | smtpAccounts.at( fromBox->currentItem() )->getAccountName() ); |
169 | Mail *mail = new Mail(); | 169 | Mail *mail = new Mail(); |
170 | SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); | 170 | SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); |
171 | |||
171 | mail->setMail( smtp->getMail() ); | 172 | mail->setMail( smtp->getMail() ); |
172 | mail->setName( smtp->getName() ); | 173 | mail->setName( smtp->getName() ); |
173 | 174 | ||
174 | if ( !toLine->text().isEmpty() ) { | 175 | if ( !toLine->text().isEmpty() ) { |
175 | mail->setTo( toLine->text() ); | 176 | mail->setTo( toLine->text() ); |
176 | } else { | 177 | } else { |
177 | qDebug( "No Reciever spezified -> returning" ); | 178 | qDebug( "No Reciever spezified -> returning" ); |
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | 181 | ||
181 | mail->setCC( ccLine->text() ); | 182 | mail->setCC( ccLine->text() ); |
182 | mail->setBCC( bccLine->text() ); | 183 | mail->setBCC( bccLine->text() ); |
183 | mail->setReply( replyLine->text() ); | 184 | mail->setReply( replyLine->text() ); |
184 | mail->setSubject( subjectLine->text() ); | 185 | mail->setSubject( subjectLine->text() ); |
185 | QString txt = message->text(); | 186 | QString txt = message->text(); |
186 | if ( !sigMultiLine->text().isEmpty() ) { | 187 | if ( !sigMultiLine->text().isEmpty() ) { |
187 | txt.append( "\n--\n" ); | 188 | txt.append( "\n--\n" ); |
188 | txt.append( sigMultiLine->text() ); | 189 | txt.append( sigMultiLine->text() ); |
189 | } | 190 | } |
190 | mail->setMessage( txt ); | 191 | mail->setMessage( txt ); |
191 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 192 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
192 | while ( it != NULL ) { | 193 | while ( it != NULL ) { |
193 | mail->addAttachment( it->getAttachment() ); | 194 | mail->addAttachment( it->getAttachment() ); |
194 | it = (AttachViewItem *) it->itemBelow(); | 195 | it = (AttachViewItem *) it->itemBelow(); |
195 | } | 196 | } |
196 | 197 | ||
197 | SMTPwrapper wrapper( settings ); | 198 | SMTPwrapper wrapper( settings ); |
198 | wrapper.sendMail( *mail ); | 199 | wrapper.sendMail( *mail,checkBoxLater->isChecked() ); |
199 | 200 | ||
200 | QDialog::accept(); | 201 | QDialog::accept(); |
201 | } | 202 | } |
202 | 203 | ||
203 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 204 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
204 | : QListViewItem( parent ) | 205 | : QListViewItem( parent ) |
205 | { | 206 | { |
206 | attachment = att; | 207 | attachment = att; |
207 | qDebug( att->getMimeType() ); | 208 | qDebug( att->getMimeType() ); |
208 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | 209 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? |
209 | Resource::loadPixmap( "UnknownDocument-14" ) : | 210 | Resource::loadPixmap( "UnknownDocument-14" ) : |
210 | attachment->getDocLnk().pixmap() ); | 211 | attachment->getDocLnk().pixmap() ); |
211 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 212 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
212 | setText( 1, QString::number( att->getSize() ) ); | 213 | setText( 1, QString::number( att->getSize() ) ); |
213 | } | 214 | } |
214 | 215 | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 7581715..8117cef 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,199 +1,219 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include "libetpan/libetpan.h" | 4 | #include <libetpan/libetpan.h> |
5 | #include "libetpan/mailstorage.h" | 5 | #include <libetpan/mailstorage.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | 7 | ||
8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
9 | : Genericwrapper(),MBOXPath(mbox_dir) | 9 | : Genericwrapper(),MBOXPath(mbox_dir) |
10 | { | 10 | { |
11 | QDir dir(MBOXPath); | 11 | QDir dir(MBOXPath); |
12 | if (!dir.exists()) { | 12 | if (!dir.exists()) { |
13 | dir.mkdir(MBOXPath); | 13 | dir.mkdir(MBOXPath); |
14 | } | 14 | } |
15 | } | 15 | } |
16 | 16 | ||
17 | MBOXwrapper::~MBOXwrapper() | 17 | MBOXwrapper::~MBOXwrapper() |
18 | { | 18 | { |
19 | } | 19 | } |
20 | 20 | ||
21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
22 | { | 22 | { |
23 | mailstorage*storage = mailstorage_new(NULL); | 23 | mailstorage*storage = mailstorage_new(NULL); |
24 | QString p = MBOXPath+"/"; | 24 | QString p = MBOXPath+"/"; |
25 | p+=mailbox; | 25 | p+=mailbox; |
26 | 26 | ||
27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
28 | mailfolder*folder; | 28 | mailfolder*folder; |
29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
30 | r = mailfolder_connect(folder); | 30 | r = mailfolder_connect(folder); |
31 | if (r != MAIL_NO_ERROR) { | 31 | if (r != MAIL_NO_ERROR) { |
32 | qDebug("Error initializing mbox"); | 32 | qDebug("Error initializing mbox"); |
33 | mailfolder_free(folder); | 33 | mailfolder_free(folder); |
34 | mailstorage_free(storage); | 34 | mailstorage_free(storage); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | mailmessage_list * env_list = 0; | 37 | mailmessage_list * env_list = 0; |
38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); |
39 | if (r != MAIL_NO_ERROR) { | 39 | if (r != MAIL_NO_ERROR) { |
40 | qDebug("Error message list"); | 40 | qDebug("Error message list"); |
41 | mailfolder_free(folder); | 41 | mailfolder_free(folder); |
42 | mailstorage_free(storage); | 42 | mailstorage_free(storage); |
43 | return; | 43 | return; |
44 | } | 44 | } |
45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | 45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); |
46 | if (r != MAIL_NO_ERROR) { | 46 | if (r != MAIL_NO_ERROR) { |
47 | qDebug("Error filling message list"); | 47 | qDebug("Error filling message list"); |
48 | if (env_list) { | 48 | if (env_list) { |
49 | mailmessage_list_free(env_list); | 49 | mailmessage_list_free(env_list); |
50 | } | 50 | } |
51 | mailfolder_free(folder); | 51 | mailfolder_free(folder); |
52 | mailstorage_free(storage); | 52 | mailstorage_free(storage); |
53 | return; | 53 | return; |
54 | } | 54 | } |
55 | mailimf_references * refs; | 55 | mailimf_references * refs; |
56 | 56 | ||
57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | 57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { |
58 | mailmessage * msg; | 58 | mailmessage * msg; |
59 | QBitArray mFlags(7); | 59 | QBitArray mFlags(7); |
60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
61 | if (msg->msg_fields == NULL) { | 61 | if (msg->msg_fields == NULL) { |
62 | qDebug("could not fetch envelope of message %i", i); | 62 | qDebug("could not fetch envelope of message %i", i); |
63 | continue; | 63 | continue; |
64 | } | 64 | } |
65 | RecMail * mail = new RecMail(); | 65 | RecMail * mail = new RecMail(); |
66 | mail->setWrapper(this); | 66 | mail->setWrapper(this); |
67 | mail_flags * flag_result = 0; | 67 | mail_flags * flag_result = 0; |
68 | r = mailmessage_get_flags(msg,&flag_result); | 68 | r = mailmessage_get_flags(msg,&flag_result); |
69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
70 | qDebug("flag fetching not implemented"); | ||
71 | mFlags.setBit(FLAG_SEEN); | 70 | mFlags.setBit(FLAG_SEEN); |
72 | } | 71 | } |
73 | mailimf_single_fields single_fields; | 72 | mailimf_single_fields single_fields; |
74 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 73 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
75 | mail->setMsgsize(msg->msg_size); | 74 | mail->setMsgsize(msg->msg_size); |
76 | mail->setFlags(mFlags); | 75 | mail->setFlags(mFlags); |
77 | mail->setMbox(mailbox); | 76 | mail->setMbox(mailbox); |
78 | mail->setNumber(i+1); | 77 | mail->setNumber(i+1); |
79 | if (single_fields.fld_subject) | 78 | if (single_fields.fld_subject) |
80 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 79 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
81 | if (single_fields.fld_from) | 80 | if (single_fields.fld_from) |
82 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 81 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
83 | if (single_fields.fld_to) | 82 | if (single_fields.fld_to) |
84 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 83 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
85 | if (single_fields.fld_cc) | 84 | if (single_fields.fld_cc) |
86 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 85 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
87 | if (single_fields.fld_bcc) | 86 | if (single_fields.fld_bcc) |
88 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 87 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
89 | if (single_fields.fld_orig_date) | 88 | if (single_fields.fld_orig_date) |
90 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 89 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
91 | if (single_fields.fld_message_id->mid_value) | 90 | if (single_fields.fld_message_id->mid_value) |
92 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 91 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
93 | refs = single_fields.fld_references; | 92 | refs = single_fields.fld_references; |
94 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 93 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
95 | char * text = (char*)refs->mid_list->first->data; | 94 | char * text = (char*)refs->mid_list->first->data; |
96 | mail->setReplyto(QString(text)); | 95 | mail->setReplyto(QString(text)); |
97 | } | 96 | } |
98 | 97 | ||
99 | target.append(mail); | 98 | target.append(mail); |
100 | } | 99 | } |
101 | if (env_list) { | 100 | if (env_list) { |
102 | mailmessage_list_free(env_list); | 101 | mailmessage_list_free(env_list); |
103 | } | 102 | } |
104 | mailfolder_disconnect(folder); | 103 | mailfolder_disconnect(folder); |
105 | mailfolder_free(folder); | 104 | mailfolder_free(folder); |
106 | mailstorage_free(storage); | 105 | mailstorage_free(storage); |
107 | } | 106 | } |
108 | 107 | ||
109 | QList<Folder>* MBOXwrapper::listFolders() | 108 | QList<Folder>* MBOXwrapper::listFolders() |
110 | { | 109 | { |
111 | QList<Folder> * folders = new QList<Folder>(); | 110 | QList<Folder> * folders = new QList<Folder>(); |
112 | folders->setAutoDelete( false ); | 111 | folders->setAutoDelete( false ); |
113 | QDir dir(MBOXPath); | 112 | QDir dir(MBOXPath); |
114 | if (!dir.exists()) return folders; | 113 | if (!dir.exists()) return folders; |
115 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 114 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
116 | QStringList entries = dir.entryList(); | 115 | QStringList entries = dir.entryList(); |
117 | QStringList::ConstIterator it = entries.begin(); | 116 | QStringList::ConstIterator it = entries.begin(); |
118 | for (;it!=entries.end();++it) { | 117 | for (;it!=entries.end();++it) { |
119 | Folder*inb=new Folder(*it,"/"); | 118 | Folder*inb=new Folder(*it,"/"); |
120 | folders->append(inb); | 119 | folders->append(inb); |
121 | } | 120 | } |
122 | return folders; | 121 | return folders; |
123 | } | 122 | } |
124 | 123 | ||
125 | void MBOXwrapper::deleteMail(const RecMail&mail) | 124 | void MBOXwrapper::deleteMail(const RecMail&mail) |
126 | { | 125 | { |
127 | mailstorage*storage = mailstorage_new(NULL); | 126 | mailstorage*storage = mailstorage_new(NULL); |
128 | QString p = MBOXPath+"/"; | 127 | QString p = MBOXPath+"/"; |
129 | p+=mail.getMbox(); | 128 | p+=mail.getMbox(); |
130 | mailmessage * msg; | 129 | mailmessage * msg; |
131 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 130 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
132 | mailfolder*folder; | 131 | mailfolder*folder; |
133 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 132 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
134 | r = mailfolder_connect(folder); | 133 | r = mailfolder_connect(folder); |
135 | if (r != MAIL_NO_ERROR) { | 134 | if (r != MAIL_NO_ERROR) { |
136 | qDebug("Error initializing mbox"); | 135 | qDebug("Error initializing mbox"); |
137 | mailfolder_free(folder); | 136 | mailfolder_free(folder); |
138 | mailstorage_free(storage); | 137 | mailstorage_free(storage); |
139 | return; | 138 | return; |
140 | } | 139 | } |
141 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 140 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
142 | if (r != MAIL_NO_ERROR) { | 141 | if (r != MAIL_NO_ERROR) { |
143 | qDebug("error deleting mail"); | 142 | qDebug("error deleting mail"); |
144 | } | 143 | } |
145 | mailfolder_free(folder); | 144 | mailfolder_free(folder); |
146 | mailstorage_free(storage); | 145 | mailstorage_free(storage); |
147 | } | 146 | } |
148 | 147 | ||
149 | void MBOXwrapper::answeredMail(const RecMail&) | 148 | void MBOXwrapper::answeredMail(const RecMail&) |
150 | { | 149 | { |
151 | } | 150 | } |
152 | 151 | ||
153 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 152 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
154 | { | 153 | { |
155 | RecBody body; | 154 | RecBody body; |
156 | mailstorage*storage = mailstorage_new(NULL); | 155 | mailstorage*storage = mailstorage_new(NULL); |
157 | QString p = MBOXPath+"/"; | 156 | QString p = MBOXPath+"/"; |
158 | p+=mail.getMbox(); | 157 | p+=mail.getMbox(); |
159 | mailmessage * msg; | 158 | mailmessage * msg; |
160 | char*data=0; | 159 | char*data=0; |
161 | size_t size; | 160 | size_t size; |
162 | 161 | ||
163 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
164 | mailfolder*folder; | 163 | mailfolder*folder; |
165 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
166 | r = mailfolder_connect(folder); | 165 | r = mailfolder_connect(folder); |
167 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
168 | qDebug("Error initializing mbox"); | 167 | qDebug("Error initializing mbox"); |
169 | mailfolder_free(folder); | 168 | mailfolder_free(folder); |
170 | mailstorage_free(storage); | 169 | mailstorage_free(storage); |
171 | return body; | 170 | return body; |
172 | } | 171 | } |
173 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
174 | if (r != MAIL_NO_ERROR) { | 173 | if (r != MAIL_NO_ERROR) { |
175 | qDebug("Error fetching mail %i",mail.getNumber()); | 174 | qDebug("Error fetching mail %i",mail.getNumber()); |
176 | mailfolder_free(folder); | 175 | mailfolder_free(folder); |
177 | mailstorage_free(storage); | 176 | mailstorage_free(storage); |
178 | return body; | 177 | return body; |
179 | } | 178 | } |
180 | r = mailmessage_fetch(msg,&data,&size); | 179 | r = mailmessage_fetch(msg,&data,&size); |
181 | if (r != MAIL_NO_ERROR) { | 180 | if (r != MAIL_NO_ERROR) { |
182 | qDebug("Error fetching mail %i",mail.getNumber()); | 181 | qDebug("Error fetching mail %i",mail.getNumber()); |
183 | mailfolder_free(folder); | 182 | mailfolder_free(folder); |
184 | mailstorage_free(storage); | 183 | mailstorage_free(storage); |
185 | mailmessage_free(msg); | 184 | mailmessage_free(msg); |
186 | return body; | 185 | return body; |
187 | } | 186 | } |
188 | body = parseMail(msg); | 187 | body = parseMail(msg); |
189 | mailmessage_fetch_result_free(msg,data); | 188 | mailmessage_fetch_result_free(msg,data); |
190 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
191 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
192 | 191 | ||
193 | return body; | 192 | return body; |
194 | } | 193 | } |
195 | 194 | ||
196 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
197 | { | 196 | { |
198 | qDebug("MBOX %i von %i",current,maximum); | 197 | qDebug("MBOX %i von %i",current,maximum); |
199 | } | 198 | } |
199 | |||
200 | void MBOXwrapper::createFolder(const QString&) | ||
201 | { | ||
202 | } | ||
203 | |||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | ||
205 | { | ||
206 | QString p = MBOXPath+"/"; | ||
207 | p+=folder; | ||
208 | mailmbox_folder*f = 0; | ||
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
210 | if (r != MAIL_NO_ERROR) { | ||
211 | qDebug("Error init folder"); | ||
212 | return; | ||
213 | } | ||
214 | r = mailmbox_append_message(f,msg,length); | ||
215 | if (r != MAIL_NO_ERROR) { | ||
216 | qDebug("Error writing message folder"); | ||
217 | } | ||
218 | mailmbox_done(f); | ||
219 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 779dbc8..1bbaf79 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -1,30 +1,32 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | 9 | ||
10 | class MBOXwrapper : public Genericwrapper | 10 | class MBOXwrapper : public Genericwrapper |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | public: | 13 | public: |
14 | MBOXwrapper(const QString & dir); | 14 | MBOXwrapper(const QString & dir); |
15 | virtual ~MBOXwrapper(); | 15 | virtual ~MBOXwrapper(); |
16 | 16 | ||
17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
18 | virtual QList<Folder>* listFolders(); | 18 | virtual QList<Folder>* listFolders(); |
19 | 19 | ||
20 | virtual void deleteMail(const RecMail&mail); | 20 | virtual void deleteMail(const RecMail&mail); |
21 | virtual void answeredMail(const RecMail&mail); | 21 | virtual void answeredMail(const RecMail&mail); |
22 | virtual void createFolder(const QString&aFolder); | ||
23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | ||
22 | 24 | ||
23 | virtual RecBody fetchBody( const RecMail &mail ); | 25 | virtual RecBody fetchBody( const RecMail &mail ); |
24 | static void mbox_progress( size_t current, size_t maximum ); | 26 | static void mbox_progress( size_t current, size_t maximum ); |
25 | 27 | ||
26 | protected: | 28 | protected: |
27 | QString MBOXPath; | 29 | QString MBOXPath; |
28 | }; | 30 | }; |
29 | 31 | ||
30 | #endif | 32 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 162b1b9..a6a46ba 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,604 +1,645 @@ | |||
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 | 8 | ||
9 | #include <libetpan/mailmime.h> | 9 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
10 | #include <libetpan/mailimf.h> | 11 | #include <libetpan/mailimf.h> |
11 | #include <libetpan/mailsmtp.h> | 12 | #include <libetpan/mailsmtp.h> |
12 | #include <libetpan/mailstorage.h> | 13 | #include <libetpan/mailstorage.h> |
13 | #include <libetpan/maildriver.h> | 14 | #include <libetpan/maildriver.h> |
15 | #endif | ||
14 | 16 | ||
15 | #include "smtpwrapper.h" | 17 | #include "smtpwrapper.h" |
16 | #include "mailwrapper.h" | 18 | #include "mailwrapper.h" |
19 | #include "mboxwrapper.h" | ||
17 | #include "logindialog.h" | 20 | #include "logindialog.h" |
18 | #include "defines.h" | 21 | #include "defines.h" |
19 | 22 | ||
20 | SMTPwrapper::SMTPwrapper( Settings *s ) | 23 | SMTPwrapper::SMTPwrapper( Settings *s ) |
21 | : QObject() | 24 | : QObject() |
22 | { | 25 | { |
23 | settings = s; | 26 | settings = s; |
24 | } | 27 | } |
25 | 28 | ||
26 | QString SMTPwrapper::mailsmtpError( int errnum ) | 29 | QString SMTPwrapper::mailsmtpError( int errnum ) |
27 | { | 30 | { |
28 | switch ( errnum ) { | 31 | switch ( errnum ) { |
29 | case MAILSMTP_NO_ERROR: | 32 | case MAILSMTP_NO_ERROR: |
30 | return tr( "No error" ); | 33 | return tr( "No error" ); |
31 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 34 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
32 | return tr( "Unexpected error code" ); | 35 | return tr( "Unexpected error code" ); |
33 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 36 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
34 | return tr( "Service not available" ); | 37 | return tr( "Service not available" ); |
35 | case MAILSMTP_ERROR_STREAM: | 38 | case MAILSMTP_ERROR_STREAM: |
36 | return tr( "Stream error" ); | 39 | return tr( "Stream error" ); |
37 | case MAILSMTP_ERROR_HOSTNAME: | 40 | case MAILSMTP_ERROR_HOSTNAME: |
38 | return tr( "gethostname() failed" ); | 41 | return tr( "gethostname() failed" ); |
39 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 42 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
40 | return tr( "Not implemented" ); | 43 | return tr( "Not implemented" ); |
41 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 44 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
42 | return tr( "Error, action not taken" ); | 45 | return tr( "Error, action not taken" ); |
43 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 46 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
44 | return tr( "Data exceeds storage allocation" ); | 47 | return tr( "Data exceeds storage allocation" ); |
45 | case MAILSMTP_ERROR_IN_PROCESSING: | 48 | case MAILSMTP_ERROR_IN_PROCESSING: |
46 | return tr( "Error in processing" ); | 49 | return tr( "Error in processing" ); |
47 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 50 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
48 | // return tr( "Insufficient system storage" ); | 51 | // return tr( "Insufficient system storage" ); |
49 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 52 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
50 | return tr( "Mailbox unavailable" ); | 53 | return tr( "Mailbox unavailable" ); |
51 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 54 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
52 | return tr( "Mailbox name not allowed" ); | 55 | return tr( "Mailbox name not allowed" ); |
53 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 56 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
54 | return tr( "Bad command sequence" ); | 57 | return tr( "Bad command sequence" ); |
55 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 58 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
56 | return tr( "User not local" ); | 59 | return tr( "User not local" ); |
57 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 60 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
58 | return tr( "Transaction failed" ); | 61 | return tr( "Transaction failed" ); |
59 | case MAILSMTP_ERROR_MEMORY: | 62 | case MAILSMTP_ERROR_MEMORY: |
60 | return tr( "Memory error" ); | 63 | return tr( "Memory error" ); |
61 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 64 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
62 | return tr( "Connection refused" ); | 65 | return tr( "Connection refused" ); |
63 | default: | 66 | default: |
64 | return tr( "Unknown error code" ); | 67 | return tr( "Unknown error code" ); |
65 | } | 68 | } |
66 | } | 69 | } |
67 | 70 | ||
68 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 71 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
69 | { | 72 | { |
70 | return mailimf_mailbox_new( strdup( name.latin1() ), | 73 | return mailimf_mailbox_new( strdup( name.latin1() ), |
71 | strdup( mail.latin1() ) ); | 74 | strdup( mail.latin1() ) ); |
72 | } | 75 | } |
73 | 76 | ||
74 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 77 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
75 | { | 78 | { |
76 | mailimf_address_list *addresses; | 79 | mailimf_address_list *addresses; |
77 | 80 | ||
78 | if ( addr.isEmpty() ) return NULL; | 81 | if ( addr.isEmpty() ) return NULL; |
79 | 82 | ||
80 | addresses = mailimf_address_list_new_empty(); | 83 | addresses = mailimf_address_list_new_empty(); |
81 | 84 | ||
82 | QStringList list = QStringList::split( ',', addr ); | 85 | QStringList list = QStringList::split( ',', addr ); |
83 | QStringList::Iterator it; | 86 | QStringList::Iterator it; |
84 | for ( it = list.begin(); it != list.end(); it++ ) { | 87 | for ( it = list.begin(); it != list.end(); it++ ) { |
85 | char *str = strdup( (*it).latin1() ); | 88 | char *str = strdup( (*it).latin1() ); |
86 | int err = mailimf_address_list_add_parse( addresses, str ); | 89 | int err = mailimf_address_list_add_parse( addresses, str ); |
87 | if ( err != MAILIMF_NO_ERROR ) { | 90 | if ( err != MAILIMF_NO_ERROR ) { |
88 | qDebug( "Error parsing" ); | 91 | qDebug( "Error parsing" ); |
89 | qDebug( *it ); | 92 | qDebug( *it ); |
90 | free( str ); | 93 | free( str ); |
91 | } else { | 94 | } else { |
92 | qDebug( "Parse success! :)" ); | 95 | qDebug( "Parse success! :)" ); |
93 | } | 96 | } |
94 | } | 97 | } |
95 | 98 | ||
96 | return addresses; | 99 | return addresses; |
97 | } | 100 | } |
98 | 101 | ||
99 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 102 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
100 | { | 103 | { |
101 | mailimf_fields *fields; | 104 | mailimf_fields *fields; |
102 | mailimf_field *xmailer; | 105 | mailimf_field *xmailer; |
103 | mailimf_mailbox *sender, *fromBox; | 106 | mailimf_mailbox *sender, *fromBox; |
104 | mailimf_mailbox_list *from; | 107 | mailimf_mailbox_list *from; |
105 | mailimf_address_list *to, *cc, *bcc, *reply; | 108 | mailimf_address_list *to, *cc, *bcc, *reply; |
106 | char *subject = strdup( mail.getSubject().latin1() ); | 109 | char *subject = strdup( mail.getSubject().latin1() ); |
107 | int err; | 110 | int err; |
108 | 111 | ||
109 | sender = newMailbox( mail.getName(), mail.getMail() ); | 112 | sender = newMailbox( mail.getName(), mail.getMail() ); |
110 | if ( sender == NULL ) goto err_free; | 113 | if ( sender == NULL ) goto err_free; |
111 | 114 | ||
112 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 115 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
113 | if ( fromBox == NULL ) goto err_free_sender; | 116 | if ( fromBox == NULL ) goto err_free_sender; |
114 | 117 | ||
115 | from = mailimf_mailbox_list_new_empty(); | 118 | from = mailimf_mailbox_list_new_empty(); |
116 | if ( from == NULL ) goto err_free_fromBox; | 119 | if ( from == NULL ) goto err_free_fromBox; |
117 | 120 | ||
118 | err = mailimf_mailbox_list_add( from, fromBox ); | 121 | err = mailimf_mailbox_list_add( from, fromBox ); |
119 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 122 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
120 | 123 | ||
121 | to = parseAddresses( mail.getTo() ); | 124 | to = parseAddresses( mail.getTo() ); |
122 | if ( to == NULL ) goto err_free_from; | 125 | if ( to == NULL ) goto err_free_from; |
123 | 126 | ||
124 | cc = parseAddresses( mail.getCC() ); | 127 | cc = parseAddresses( mail.getCC() ); |
125 | bcc = parseAddresses( mail.getBCC() ); | 128 | bcc = parseAddresses( mail.getBCC() ); |
126 | reply = parseAddresses( mail.getReply() ); | 129 | reply = parseAddresses( mail.getReply() ); |
127 | 130 | ||
128 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 131 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
129 | NULL, NULL, subject ); | 132 | NULL, NULL, subject ); |
130 | if ( fields == NULL ) goto err_free_reply; | 133 | if ( fields == NULL ) goto err_free_reply; |
131 | 134 | ||
132 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 135 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
133 | strdup( USER_AGENT ) ); | 136 | strdup( USER_AGENT ) ); |
134 | if ( xmailer == NULL ) goto err_free_fields; | 137 | if ( xmailer == NULL ) goto err_free_fields; |
135 | 138 | ||
136 | err = mailimf_fields_add( fields, xmailer ); | 139 | err = mailimf_fields_add( fields, xmailer ); |
137 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 140 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
138 | 141 | ||
139 | return fields; // Success :) | 142 | return fields; // Success :) |
140 | 143 | ||
141 | err_free_xmailer: | 144 | err_free_xmailer: |
142 | mailimf_field_free( xmailer ); | 145 | mailimf_field_free( xmailer ); |
143 | err_free_fields: | 146 | err_free_fields: |
144 | mailimf_fields_free( fields ); | 147 | mailimf_fields_free( fields ); |
145 | err_free_reply: | 148 | err_free_reply: |
146 | mailimf_address_list_free( reply ); | 149 | mailimf_address_list_free( reply ); |
147 | mailimf_address_list_free( bcc ); | 150 | mailimf_address_list_free( bcc ); |
148 | mailimf_address_list_free( cc ); | 151 | mailimf_address_list_free( cc ); |
149 | mailimf_address_list_free( to ); | 152 | mailimf_address_list_free( to ); |
150 | err_free_from: | 153 | err_free_from: |
151 | mailimf_mailbox_list_free( from ); | 154 | mailimf_mailbox_list_free( from ); |
152 | err_free_fromBox: | 155 | err_free_fromBox: |
153 | mailimf_mailbox_free( fromBox ); | 156 | mailimf_mailbox_free( fromBox ); |
154 | err_free_sender: | 157 | err_free_sender: |
155 | mailimf_mailbox_free( sender ); | 158 | mailimf_mailbox_free( sender ); |
156 | err_free: | 159 | err_free: |
157 | free( subject ); | 160 | free( subject ); |
158 | qDebug( "createImfFields - error" ); | 161 | qDebug( "createImfFields - error" ); |
159 | 162 | ||
160 | return NULL; // Error :( | 163 | return NULL; // Error :( |
161 | } | 164 | } |
162 | 165 | ||
163 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 166 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
164 | { | 167 | { |
165 | mailmime *txtPart; | 168 | mailmime *txtPart; |
166 | mailmime_fields *fields; | 169 | mailmime_fields *fields; |
167 | mailmime_content *content; | 170 | mailmime_content *content; |
168 | mailmime_parameter *param; | 171 | mailmime_parameter *param; |
169 | char *txt = strdup( str.latin1() ); | 172 | char *txt = strdup( str.latin1() ); |
170 | int err; | 173 | int err; |
171 | 174 | ||
172 | param = mailmime_parameter_new( strdup( "charset" ), | 175 | param = mailmime_parameter_new( strdup( "charset" ), |
173 | strdup( "iso-8859-1" ) ); | 176 | strdup( "iso-8859-1" ) ); |
174 | if ( param == NULL ) goto err_free; | 177 | if ( param == NULL ) goto err_free; |
175 | 178 | ||
176 | content = mailmime_content_new_with_str( "text/plain" ); | 179 | content = mailmime_content_new_with_str( "text/plain" ); |
177 | if ( content == NULL ) goto err_free_param; | 180 | if ( content == NULL ) goto err_free_param; |
178 | 181 | ||
179 | err = clist_append( content->ct_parameters, param ); | 182 | err = clist_append( content->ct_parameters, param ); |
180 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 183 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
181 | 184 | ||
182 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 185 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
183 | if ( fields == NULL ) goto err_free_content; | 186 | if ( fields == NULL ) goto err_free_content; |
184 | 187 | ||
185 | txtPart = mailmime_new_empty( content, fields ); | 188 | txtPart = mailmime_new_empty( content, fields ); |
186 | if ( txtPart == NULL ) goto err_free_fields; | 189 | if ( txtPart == NULL ) goto err_free_fields; |
187 | 190 | ||
188 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 191 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
189 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 192 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
190 | 193 | ||
191 | return txtPart; // Success :) | 194 | return txtPart; // Success :) |
192 | 195 | ||
193 | err_free_txtPart: | 196 | err_free_txtPart: |
194 | mailmime_free( txtPart ); | 197 | mailmime_free( txtPart ); |
195 | err_free_fields: | 198 | err_free_fields: |
196 | mailmime_fields_free( fields ); | 199 | mailmime_fields_free( fields ); |
197 | err_free_content: | 200 | err_free_content: |
198 | mailmime_content_free( content ); | 201 | mailmime_content_free( content ); |
199 | err_free_param: | 202 | err_free_param: |
200 | mailmime_parameter_free( param ); | 203 | mailmime_parameter_free( param ); |
201 | err_free: | 204 | err_free: |
202 | free( txt ); | 205 | free( txt ); |
203 | qDebug( "buildTxtPart - error" ); | 206 | qDebug( "buildTxtPart - error" ); |
204 | 207 | ||
205 | return NULL; // Error :( | 208 | return NULL; // Error :( |
206 | } | 209 | } |
207 | 210 | ||
208 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) | 211 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) |
209 | { | 212 | { |
210 | mailmime * filePart; | 213 | mailmime * filePart; |
211 | mailmime_fields * fields; | 214 | mailmime_fields * fields; |
212 | mailmime_content * content; | 215 | mailmime_content * content; |
213 | mailmime_parameter * param = NULL; | 216 | mailmime_parameter * param = NULL; |
214 | int err; | 217 | int err; |
215 | 218 | ||
216 | int pos = filename.findRev( '/' ); | 219 | int pos = filename.findRev( '/' ); |
217 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
218 | char *name = strdup( tmp.latin1() ); // just filename | 221 | char *name = strdup( tmp.latin1() ); // just filename |
219 | char *file = strdup( filename.latin1() ); // full name with path | 222 | char *file = strdup( filename.latin1() ); // full name with path |
220 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 223 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
221 | 224 | ||
222 | fields = mailmime_fields_new_filename( | 225 | fields = mailmime_fields_new_filename( |
223 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 226 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
224 | MAILMIME_MECHANISM_BASE64 ); | 227 | MAILMIME_MECHANISM_BASE64 ); |
225 | if ( fields == NULL ) goto err_free; | 228 | if ( fields == NULL ) goto err_free; |
226 | 229 | ||
227 | content = mailmime_content_new_with_str( mime ); | 230 | content = mailmime_content_new_with_str( mime ); |
228 | if ( content == NULL ) goto err_free_fields; | 231 | if ( content == NULL ) goto err_free_fields; |
229 | 232 | ||
230 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 233 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
231 | param = mailmime_parameter_new( strdup( "charset" ), | 234 | param = mailmime_parameter_new( strdup( "charset" ), |
232 | strdup( "iso-8859-1" ) ); | 235 | strdup( "iso-8859-1" ) ); |
233 | if ( param == NULL ) goto err_free_content; | 236 | if ( param == NULL ) goto err_free_content; |
234 | 237 | ||
235 | err = clist_append( content->ct_parameters, param ); | 238 | err = clist_append( content->ct_parameters, param ); |
236 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 239 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
237 | } | 240 | } |
238 | 241 | ||
239 | filePart = mailmime_new_empty( content, fields ); | 242 | filePart = mailmime_new_empty( content, fields ); |
240 | if ( filePart == NULL ) goto err_free_param; | 243 | if ( filePart == NULL ) goto err_free_param; |
241 | 244 | ||
242 | err = mailmime_set_body_file( filePart, file ); | 245 | err = mailmime_set_body_file( filePart, file ); |
243 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 246 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
244 | 247 | ||
245 | return filePart; // Success :) | 248 | return filePart; // Success :) |
246 | 249 | ||
247 | err_free_filePart: | 250 | err_free_filePart: |
248 | mailmime_free( filePart ); | 251 | mailmime_free( filePart ); |
249 | err_free_param: | 252 | err_free_param: |
250 | if ( param != NULL ) mailmime_parameter_free( param ); | 253 | if ( param != NULL ) mailmime_parameter_free( param ); |
251 | err_free_content: | 254 | err_free_content: |
252 | mailmime_content_free( content ); | 255 | mailmime_content_free( content ); |
253 | err_free_fields: | 256 | err_free_fields: |
254 | mailmime_fields_free( fields ); | 257 | mailmime_fields_free( fields ); |
255 | err_free: | 258 | err_free: |
256 | free( name ); | 259 | free( name ); |
257 | free( mime ); | 260 | free( mime ); |
258 | free( file ); | 261 | free( file ); |
259 | qDebug( "buildFilePart - error" ); | 262 | qDebug( "buildFilePart - error" ); |
260 | 263 | ||
261 | return NULL; // Error :( | 264 | return NULL; // Error :( |
262 | } | 265 | } |
263 | 266 | ||
264 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 267 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
265 | { | 268 | { |
266 | const Attachment *it; | 269 | const Attachment *it; |
267 | /* work around for the brainfucked qlist which can not act with const values */ | 270 | /* work around for the brainfucked qlist which can not act with const values */ |
268 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { | 271 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { |
269 | qDebug( "Adding file" ); | 272 | qDebug( "Adding file" ); |
270 | mailmime *filePart; | 273 | mailmime *filePart; |
271 | int err; | 274 | int err; |
272 | 275 | ||
273 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 276 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
274 | if ( filePart == NULL ) goto err_free; | 277 | if ( filePart == NULL ) goto err_free; |
275 | 278 | ||
276 | err = mailmime_smart_add_part( message, filePart ); | 279 | err = mailmime_smart_add_part( message, filePart ); |
277 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 280 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
278 | 281 | ||
279 | continue; // Success :) | 282 | continue; // Success :) |
280 | 283 | ||
281 | err_free_filePart: | 284 | err_free_filePart: |
282 | mailmime_free( filePart ); | 285 | mailmime_free( filePart ); |
283 | err_free: | 286 | err_free: |
284 | qDebug( "addFileParts: error adding file:" ); | 287 | qDebug( "addFileParts: error adding file:" ); |
285 | qDebug( it->getFileName() ); | 288 | qDebug( it->getFileName() ); |
286 | } | 289 | } |
287 | } | 290 | } |
288 | 291 | ||
289 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 292 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
290 | { | 293 | { |
291 | mailmime *message, *txtPart; | 294 | mailmime *message, *txtPart; |
292 | mailimf_fields *fields; | 295 | mailimf_fields *fields; |
293 | int err; | 296 | int err; |
294 | 297 | ||
295 | fields = createImfFields( mail ); | 298 | fields = createImfFields( mail ); |
296 | if ( fields == NULL ) goto err_free; | 299 | if ( fields == NULL ) goto err_free; |
297 | 300 | ||
298 | message = mailmime_new_message_data( NULL ); | 301 | message = mailmime_new_message_data( NULL ); |
299 | if ( message == NULL ) goto err_free_fields; | 302 | if ( message == NULL ) goto err_free_fields; |
300 | 303 | ||
301 | mailmime_set_imf_fields( message, fields ); | 304 | mailmime_set_imf_fields( message, fields ); |
302 | 305 | ||
303 | txtPart = buildTxtPart( mail.getMessage() ); | 306 | txtPart = buildTxtPart( mail.getMessage() ); |
304 | if ( txtPart == NULL ) goto err_free_message; | 307 | if ( txtPart == NULL ) goto err_free_message; |
305 | 308 | ||
306 | err = mailmime_smart_add_part( message, txtPart ); | 309 | err = mailmime_smart_add_part( message, txtPart ); |
307 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 310 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
308 | 311 | ||
309 | addFileParts( message, mail.getAttachments() ); | 312 | addFileParts( message, mail.getAttachments() ); |
310 | 313 | ||
311 | return message; // Success :) | 314 | return message; // Success :) |
312 | 315 | ||
313 | err_free_txtPart: | 316 | err_free_txtPart: |
314 | mailmime_free( txtPart ); | 317 | mailmime_free( txtPart ); |
315 | err_free_message: | 318 | err_free_message: |
316 | mailmime_free( message ); | 319 | mailmime_free( message ); |
317 | err_free_fields: | 320 | err_free_fields: |
318 | mailimf_fields_free( fields ); | 321 | mailimf_fields_free( fields ); |
319 | err_free: | 322 | err_free: |
320 | qDebug( "createMimeMail: error" ); | 323 | qDebug( "createMimeMail: error" ); |
321 | 324 | ||
322 | return NULL; // Error :( | 325 | return NULL; // Error :( |
323 | } | 326 | } |
324 | 327 | ||
325 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 328 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
326 | { | 329 | { |
327 | mailimf_field *field; | 330 | mailimf_field *field; |
328 | clistiter *it; | 331 | clistiter *it; |
329 | 332 | ||
330 | it = clist_begin( fields->fld_list ); | 333 | it = clist_begin( fields->fld_list ); |
331 | while ( it ) { | 334 | while ( it ) { |
332 | field = (mailimf_field *) it->data; | 335 | field = (mailimf_field *) it->data; |
333 | if ( field->fld_type == type ) { | 336 | if ( field->fld_type == type ) { |
334 | return field; | 337 | return field; |
335 | } | 338 | } |
336 | it = it->next; | 339 | it = it->next; |
337 | } | 340 | } |
338 | 341 | ||
339 | return NULL; | 342 | return NULL; |
340 | } | 343 | } |
341 | 344 | ||
342 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 345 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
343 | { | 346 | { |
344 | clistiter *it, *it2; | 347 | clistiter *it, *it2; |
345 | 348 | ||
346 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 349 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
347 | mailimf_address *addr; | 350 | mailimf_address *addr; |
348 | addr = (mailimf_address *) it->data; | 351 | addr = (mailimf_address *) it->data; |
349 | 352 | ||
350 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 353 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
351 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 354 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
352 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 355 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
353 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 356 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
354 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 357 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
355 | mailimf_mailbox *mbox; | 358 | mailimf_mailbox *mbox; |
356 | mbox = (mailimf_mailbox *) it2->data; | 359 | mbox = (mailimf_mailbox *) it2->data; |
357 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 360 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
358 | } | 361 | } |
359 | } | 362 | } |
360 | } | 363 | } |
361 | } | 364 | } |
362 | 365 | ||
363 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 366 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
364 | { | 367 | { |
365 | clist *rcptList; | 368 | clist *rcptList; |
366 | mailimf_field *field; | 369 | mailimf_field *field; |
367 | 370 | ||
368 | rcptList = esmtp_address_list_new(); | 371 | rcptList = esmtp_address_list_new(); |
369 | 372 | ||
370 | field = getField( fields, MAILIMF_FIELD_TO ); | 373 | field = getField( fields, MAILIMF_FIELD_TO ); |
371 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 374 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
372 | && field->fld_data.fld_to->to_addr_list ) { | 375 | && field->fld_data.fld_to->to_addr_list ) { |
373 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 376 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
374 | } | 377 | } |
375 | 378 | ||
376 | field = getField( fields, MAILIMF_FIELD_CC ); | 379 | field = getField( fields, MAILIMF_FIELD_CC ); |
377 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 380 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
378 | && field->fld_data.fld_cc->cc_addr_list ) { | 381 | && field->fld_data.fld_cc->cc_addr_list ) { |
379 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 382 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
380 | } | 383 | } |
381 | 384 | ||
382 | field = getField( fields, MAILIMF_FIELD_BCC ); | 385 | field = getField( fields, MAILIMF_FIELD_BCC ); |
383 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 386 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
384 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 387 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
385 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 388 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
386 | } | 389 | } |
387 | 390 | ||
388 | return rcptList; | 391 | return rcptList; |
389 | } | 392 | } |
390 | 393 | ||
391 | char *SMTPwrapper::getFrom( mailmime *mail ) | 394 | char *SMTPwrapper::getFrom( mailmime *mail ) |
392 | { | 395 | { |
393 | char *from = NULL; | 396 | char *from = NULL; |
394 | 397 | ||
395 | mailimf_field *ffrom; | 398 | mailimf_field *ffrom; |
396 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 399 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
397 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 400 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
398 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 401 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
399 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 402 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
400 | clistiter *it; | 403 | clistiter *it; |
401 | for ( it = clist_begin( cl ); it; it = it->next ) { | 404 | for ( it = clist_begin( cl ); it; it = it->next ) { |
402 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 405 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
403 | from = strdup( mb->mb_addr_spec ); | 406 | from = strdup( mb->mb_addr_spec ); |
404 | } | 407 | } |
405 | } | 408 | } |
406 | 409 | ||
407 | return from; | 410 | return from; |
408 | } | 411 | } |
409 | 412 | ||
410 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | 413 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) |
411 | { | 414 | { |
412 | SMTPaccount *smtp; | 415 | SMTPaccount *smtp; |
413 | 416 | ||
414 | QList<Account> list = settings->getAccounts(); | 417 | QList<Account> list = settings->getAccounts(); |
415 | Account *it; | 418 | Account *it; |
416 | for ( it = list.first(); it; it = list.next() ) { | 419 | for ( it = list.first(); it; it = list.next() ) { |
417 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 420 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
418 | smtp = static_cast<SMTPaccount *>(it); | 421 | smtp = static_cast<SMTPaccount *>(it); |
419 | if ( smtp->getMail().compare( from ) == 0 ) { | 422 | if ( smtp->getMail().compare( from ) == 0 ) { |
420 | qDebug( "SMTPaccount found for" ); | 423 | qDebug( "SMTPaccount found for" ); |
421 | qDebug( from ); | 424 | qDebug( from ); |
422 | return smtp; | 425 | return smtp; |
423 | } | 426 | } |
424 | } | 427 | } |
425 | } | 428 | } |
426 | 429 | ||
427 | return NULL; | 430 | return NULL; |
428 | } | 431 | } |
429 | 432 | ||
430 | QString SMTPwrapper::getTmpFile() { | 433 | QString SMTPwrapper::getTmpFile() { |
431 | int num = 0; | 434 | int num = 0; |
432 | QString unique; | 435 | QString unique; |
433 | 436 | ||
434 | QDir dir( "/tmp" ); | 437 | QDir dir( "/tmp" ); |
435 | QStringList::Iterator it; | 438 | QStringList::Iterator it; |
436 | 439 | ||
437 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 440 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
438 | do { | 441 | do { |
439 | unique.setNum( num++ ); | 442 | unique.setNum( num++ ); |
440 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 443 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
441 | 444 | ||
442 | return "/tmp/opiemail-tmp-" + unique; | 445 | return "/tmp/opiemail-tmp-" + unique; |
443 | } | 446 | } |
444 | 447 | ||
445 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 448 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
446 | { | 449 | { |
447 | FILE *f; | 450 | FILE *f; |
448 | int err, col = 0; | 451 | int err, col = 0; |
449 | 452 | ||
450 | f = fopen( file.latin1(), "w" ); | 453 | f = fopen( file.latin1(), "w" ); |
451 | if ( f == NULL ) { | 454 | if ( f == NULL ) { |
452 | qDebug( "writeToFile: error opening file" ); | 455 | qDebug( "writeToFile: error opening file" ); |
453 | return; | 456 | return; |
454 | } | 457 | } |
455 | 458 | ||
456 | err = mailmime_write( f, &col, mail ); | 459 | err = mailmime_write( f, &col, mail ); |
457 | if ( err != MAILIMF_NO_ERROR ) { | 460 | if ( err != MAILIMF_NO_ERROR ) { |
458 | fclose( f ); | 461 | fclose( f ); |
459 | qDebug( "writeToFile: error writing mailmime" ); | 462 | qDebug( "writeToFile: error writing mailmime" ); |
460 | return; | 463 | return; |
461 | } | 464 | } |
462 | 465 | ||
463 | fclose( f ); | 466 | fclose( f ); |
464 | } | 467 | } |
465 | 468 | ||
466 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 469 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
467 | { | 470 | { |
471 | |||
472 | QFile msg_cache(file); | ||
473 | QString msg = ""; | ||
474 | msg_cache.open(IO_ReadOnly); | ||
475 | char*message = new char[4096]; | ||
476 | memset(message,0,4096); | ||
477 | while (msg_cache.readBlock(message,4095)>0) { | ||
478 | msg+=message; | ||
479 | memset(message,0,4096); | ||
480 | } | ||
481 | delete message; | ||
482 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | ||
483 | memset(*data,0,msg.length()+1); | ||
484 | memcpy(*data,msg.ascii(),msg.length()); | ||
485 | *size=msg.length(); | ||
486 | |||
487 | #if 0 | ||
468 | char *buf; | 488 | char *buf; |
469 | struct stat st; | 489 | struct stat st; |
470 | int fd, count = 0, total = 0; | 490 | int fd, count = 0, total = 0; |
471 | 491 | ||
472 | fd = open( file.latin1(), O_RDONLY, 0 ); | 492 | fd = open( file.latin1(), O_RDONLY, 0 ); |
473 | if ( fd == -1 ) return; | 493 | if ( fd == -1 ) return; |
474 | 494 | ||
475 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 495 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
476 | if ( !st.st_size ) goto err_close; | 496 | if ( !st.st_size ) goto err_close; |
477 | 497 | ||
478 | buf = (char *) malloc( st.st_size ); | 498 | buf = (char *) malloc( st.st_size ); |
479 | if ( !buf ) goto err_close; | 499 | if ( !buf ) goto err_close; |
480 | 500 | ||
481 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
482 | count = read( fd, buf + total, st.st_size - total ); | 502 | count = read( fd, buf + total, st.st_size - total ); |
483 | total += count; | 503 | total += count; |
484 | } | 504 | } |
485 | if ( count < 0 ) goto err_free; | 505 | if ( count < 0 ) goto err_free; |
486 | 506 | ||
487 | *data = buf; | 507 | *data = buf; |
488 | *size = st.st_size; | 508 | *size = st.st_size; |
489 | 509 | ||
490 | close( fd ); | 510 | close( fd ); |
491 | 511 | ||
492 | return; // Success :) | 512 | return; // Success :) |
493 | 513 | ||
494 | err_free: | 514 | err_free: |
495 | free( buf ); | 515 | free( buf ); |
496 | err_close: | 516 | err_close: |
497 | close( fd ); | 517 | close( fd ); |
518 | #endif | ||
498 | } | 519 | } |
499 | 520 | ||
500 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 521 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
501 | { | 522 | { |
502 | qDebug( "Current: %i of %i", current, maximum ); | 523 | qDebug( "Current: %i of %i", current, maximum ); |
503 | } | 524 | } |
504 | 525 | ||
505 | void SMTPwrapper::smtpSend( mailmime *mail ) | 526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
527 | { | ||
528 | if (!mail) return; | ||
529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
531 | wrap->storeMessage(mail,length,box); | ||
532 | delete wrap; | ||
533 | } | ||
534 | |||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | ||
506 | { | 536 | { |
507 | mailsmtp *session; | 537 | mailsmtp *session; |
508 | clist *rcpts; | 538 | clist *rcpts; |
509 | char *from, *data, *server, *user = NULL, *pass = NULL; | 539 | char *from, *data, *server, *user = NULL, *pass = NULL; |
510 | size_t size; | 540 | size_t size; |
511 | int err; | 541 | int err; |
512 | bool ssl; | 542 | bool ssl; |
513 | uint16_t port; | 543 | uint16_t port; |
514 | 544 | ||
515 | 545 | ||
516 | from = getFrom( mail ); | 546 | from = getFrom( mail ); |
517 | SMTPaccount *smtp = getAccount( from ); | 547 | SMTPaccount *smtp = getAccount( from ); |
518 | if ( smtp == NULL ) { | 548 | if ( smtp == NULL ) { |
519 | free(from); | 549 | free(from); |
520 | return; | 550 | return; |
521 | } | 551 | } |
522 | server = strdup( smtp->getServer().latin1() ); | ||
523 | ssl = smtp->getSSL(); | ||
524 | port = smtp->getPort().toUInt(); | ||
525 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
526 | 553 | ||
527 | QString file = getTmpFile(); | 554 | QString file = getTmpFile(); |
528 | writeToFile( file, mail ); | 555 | writeToFile( file, mail ); |
556 | |||
529 | readFromFile( file, &data, &size ); | 557 | readFromFile( file, &data, &size ); |
530 | QFile f( file ); | 558 | QFile f( file ); |
531 | f.remove(); | 559 | f.remove(); |
560 | |||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
532 | 562 | ||
563 | if (later) { | ||
564 | smtp_address_list_free( rcpts ); | ||
565 | if (data) free( data ); | ||
566 | if (from) free(from); | ||
567 | return; | ||
568 | } | ||
569 | server = strdup( smtp->getServer().latin1() ); | ||
570 | ssl = smtp->getSSL(); | ||
571 | port = smtp->getPort().toUInt(); | ||
572 | |||
533 | session = mailsmtp_new( 20, &progress ); | 573 | session = mailsmtp_new( 20, &progress ); |
534 | if ( session == NULL ) goto free_mem; | 574 | if ( session == NULL ) goto free_mem; |
535 | 575 | ||
536 | qDebug( "Servername %s at port %i", server, port ); | 576 | qDebug( "Servername %s at port %i", server, port ); |
537 | if ( ssl ) { | 577 | if ( ssl ) { |
538 | qDebug( "SSL session" ); | 578 | qDebug( "SSL session" ); |
539 | err = mailsmtp_ssl_connect( session, server, port ); | 579 | err = mailsmtp_ssl_connect( session, server, port ); |
540 | } else { | 580 | } else { |
541 | qDebug( "No SSL session" ); | 581 | qDebug( "No SSL session" ); |
542 | err = mailsmtp_socket_connect( session, server, port ); | 582 | err = mailsmtp_socket_connect( session, server, port ); |
543 | } | 583 | } |
544 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 584 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
545 | 585 | ||
546 | err = mailsmtp_init( session ); | 586 | err = mailsmtp_init( session ); |
547 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 587 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
548 | 588 | ||
549 | qDebug( "INIT OK" ); | 589 | qDebug( "INIT OK" ); |
550 | 590 | ||
551 | if ( smtp->getLogin() ) { | 591 | if ( smtp->getLogin() ) { |
552 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 592 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
553 | // get'em | 593 | // get'em |
554 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 594 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
555 | login.show(); | 595 | login.show(); |
556 | if ( QDialog::Accepted == login.exec() ) { | 596 | if ( QDialog::Accepted == login.exec() ) { |
557 | // ok | 597 | // ok |
558 | user = strdup( login.getUser().latin1() ); | 598 | user = strdup( login.getUser().latin1() ); |
559 | pass = strdup( login.getPassword().latin1() ); | 599 | pass = strdup( login.getPassword().latin1() ); |
560 | } else { | 600 | } else { |
561 | goto free_con_session; | 601 | goto free_con_session; |
562 | } | 602 | } |
563 | } else { | 603 | } else { |
564 | user = strdup( smtp->getUser().latin1() ); | 604 | user = strdup( smtp->getUser().latin1() ); |
565 | pass = strdup( smtp->getPassword().latin1() ); | 605 | pass = strdup( smtp->getPassword().latin1() ); |
566 | } | 606 | } |
567 | qDebug( "session->auth: %i", session->auth); | 607 | qDebug( "session->auth: %i", session->auth); |
568 | err = mailsmtp_auth( session, user, pass ); | 608 | err = mailsmtp_auth( session, user, pass ); |
569 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 609 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
570 | qDebug( "Done auth!" ); | 610 | qDebug( "Done auth!" ); |
571 | } | 611 | } |
572 | 612 | ||
573 | err = mailsmtp_send( session, from, rcpts, data, size ); | 613 | err = mailsmtp_send( session, from, rcpts, data, size ); |
574 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 614 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
575 | 615 | ||
576 | qDebug( "Mail sent." ); | 616 | qDebug( "Mail sent." ); |
577 | 617 | ||
578 | free_con_session: | 618 | free_con_session: |
579 | mailsmtp_quit( session ); | 619 | mailsmtp_quit( session ); |
580 | free_mem_session: | 620 | free_mem_session: |
581 | mailsmtp_free( session ); | 621 | mailsmtp_free( session ); |
582 | free_mem: | 622 | free_mem: |
583 | smtp_address_list_free( rcpts ); | 623 | smtp_address_list_free( rcpts ); |
584 | free( data ); | 624 | if (data) free( data ); |
585 | free( server ); | 625 | if (from) free(from); |
626 | if (server) free( server ); | ||
586 | if ( smtp->getLogin() ) { | 627 | if ( smtp->getLogin() ) { |
587 | free( user ); | 628 | free( user ); |
588 | free( pass ); | 629 | free( pass ); |
589 | } | 630 | } |
590 | free( from ); | 631 | free( from ); |
591 | } | 632 | } |
592 | 633 | ||
593 | void SMTPwrapper::sendMail(const Mail&mail ) | 634 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
594 | { | 635 | { |
595 | mailmime *mimeMail; | 636 | mailmime * mimeMail; |
596 | 637 | ||
597 | mimeMail = createMimeMail(mail ); | 638 | mimeMail = createMimeMail(mail ); |
598 | if ( mimeMail == NULL ) { | 639 | if ( mimeMail == NULL ) { |
599 | qDebug( "sendMail: error creating mime mail" ); | 640 | qDebug( "sendMail: error creating mime mail" ); |
600 | } else { | 641 | } else { |
601 | smtpSend( mimeMail ); | 642 | smtpSend( mimeMail,later ); |
602 | mailmime_free( mimeMail ); | 643 | mailmime_free( mimeMail ); |
603 | } | 644 | } |
604 | } | 645 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 8fdb07d..41e9a8c 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -1,53 +1,55 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class Attachment; | 13 | class Attachment; |
14 | struct mailimf_fields; | 14 | struct mailimf_fields; |
15 | struct mailimf_field; | 15 | struct mailimf_field; |
16 | struct mailimf_mailbox; | 16 | struct mailimf_mailbox; |
17 | struct mailmime; | 17 | struct mailmime; |
18 | struct mailimf_address_list; | 18 | struct mailimf_address_list; |
19 | 19 | ||
20 | class SMTPwrapper : public QObject | 20 | class SMTPwrapper : public QObject |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | 23 | ||
24 | public: | 24 | public: |
25 | SMTPwrapper( Settings *s ); | 25 | SMTPwrapper( Settings *s ); |
26 | virtual ~SMTPwrapper(){} | 26 | virtual ~SMTPwrapper(){} |
27 | void sendMail(const Mail& mail ); | 27 | void sendMail(const Mail& mail,bool later=false ); |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
31 | mailimf_fields *createImfFields(const Mail &mail ); | 31 | mailimf_fields *createImfFields(const Mail &mail ); |
32 | mailmime *createMimeMail(const Mail&mail ); | 32 | mailmime *createMimeMail(const Mail&mail ); |
33 | 33 | ||
34 | mailimf_address_list *parseAddresses(const QString&addr ); | 34 | mailimf_address_list *parseAddresses(const QString&addr ); |
35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
36 | mailmime *buildTxtPart(const QString&str ); | 36 | mailmime *buildTxtPart(const QString&str ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); | 37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); |
38 | void smtpSend( mailmime *mail ); | 38 | void smtpSend( mailmime *mail,bool later ); |
39 | mailimf_field *getField( mailimf_fields *fields, int type ); | 39 | mailimf_field *getField( mailimf_fields *fields, int type ); |
40 | clist *createRcptList( mailimf_fields *fields ); | 40 | clist *createRcptList( mailimf_fields *fields ); |
41 | char *getFrom( mailmime *mail ); | 41 | char *getFrom( mailmime *mail ); |
42 | SMTPaccount *getAccount(const QString&from ); | 42 | SMTPaccount *getAccount(const QString&from ); |
43 | void writeToFile(const QString&file, mailmime *mail ); | 43 | void writeToFile(const QString&file, mailmime *mail ); |
44 | void readFromFile(const QString&file, char **data, size_t *size ); | 44 | void readFromFile(const QString&file, char **data, size_t *size ); |
45 | void storeMail(char*mail, size_t length, const QString&box); | ||
45 | 46 | ||
46 | static QString mailsmtpError( int err ); | 47 | static QString mailsmtpError( int err ); |
47 | static QString getTmpFile(); | 48 | static QString getTmpFile(); |
48 | static void progress( size_t current, size_t maximum ); | 49 | static void progress( size_t current, size_t maximum ); |
49 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
51 | void storeMail(mailmime*mail, const QString&box); | ||
50 | Settings *settings; | 52 | Settings *settings; |
51 | }; | 53 | }; |
52 | 54 | ||
53 | #endif | 55 | #endif |
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 7581715..8117cef 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -1,199 +1,219 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include "libetpan/libetpan.h" | 4 | #include <libetpan/libetpan.h> |
5 | #include "libetpan/mailstorage.h" | 5 | #include <libetpan/mailstorage.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | 7 | ||
8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
9 | : Genericwrapper(),MBOXPath(mbox_dir) | 9 | : Genericwrapper(),MBOXPath(mbox_dir) |
10 | { | 10 | { |
11 | QDir dir(MBOXPath); | 11 | QDir dir(MBOXPath); |
12 | if (!dir.exists()) { | 12 | if (!dir.exists()) { |
13 | dir.mkdir(MBOXPath); | 13 | dir.mkdir(MBOXPath); |
14 | } | 14 | } |
15 | } | 15 | } |
16 | 16 | ||
17 | MBOXwrapper::~MBOXwrapper() | 17 | MBOXwrapper::~MBOXwrapper() |
18 | { | 18 | { |
19 | } | 19 | } |
20 | 20 | ||
21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
22 | { | 22 | { |
23 | mailstorage*storage = mailstorage_new(NULL); | 23 | mailstorage*storage = mailstorage_new(NULL); |
24 | QString p = MBOXPath+"/"; | 24 | QString p = MBOXPath+"/"; |
25 | p+=mailbox; | 25 | p+=mailbox; |
26 | 26 | ||
27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
28 | mailfolder*folder; | 28 | mailfolder*folder; |
29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
30 | r = mailfolder_connect(folder); | 30 | r = mailfolder_connect(folder); |
31 | if (r != MAIL_NO_ERROR) { | 31 | if (r != MAIL_NO_ERROR) { |
32 | qDebug("Error initializing mbox"); | 32 | qDebug("Error initializing mbox"); |
33 | mailfolder_free(folder); | 33 | mailfolder_free(folder); |
34 | mailstorage_free(storage); | 34 | mailstorage_free(storage); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | mailmessage_list * env_list = 0; | 37 | mailmessage_list * env_list = 0; |
38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); |
39 | if (r != MAIL_NO_ERROR) { | 39 | if (r != MAIL_NO_ERROR) { |
40 | qDebug("Error message list"); | 40 | qDebug("Error message list"); |
41 | mailfolder_free(folder); | 41 | mailfolder_free(folder); |
42 | mailstorage_free(storage); | 42 | mailstorage_free(storage); |
43 | return; | 43 | return; |
44 | } | 44 | } |
45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | 45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); |
46 | if (r != MAIL_NO_ERROR) { | 46 | if (r != MAIL_NO_ERROR) { |
47 | qDebug("Error filling message list"); | 47 | qDebug("Error filling message list"); |
48 | if (env_list) { | 48 | if (env_list) { |
49 | mailmessage_list_free(env_list); | 49 | mailmessage_list_free(env_list); |
50 | } | 50 | } |
51 | mailfolder_free(folder); | 51 | mailfolder_free(folder); |
52 | mailstorage_free(storage); | 52 | mailstorage_free(storage); |
53 | return; | 53 | return; |
54 | } | 54 | } |
55 | mailimf_references * refs; | 55 | mailimf_references * refs; |
56 | 56 | ||
57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | 57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { |
58 | mailmessage * msg; | 58 | mailmessage * msg; |
59 | QBitArray mFlags(7); | 59 | QBitArray mFlags(7); |
60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
61 | if (msg->msg_fields == NULL) { | 61 | if (msg->msg_fields == NULL) { |
62 | qDebug("could not fetch envelope of message %i", i); | 62 | qDebug("could not fetch envelope of message %i", i); |
63 | continue; | 63 | continue; |
64 | } | 64 | } |
65 | RecMail * mail = new RecMail(); | 65 | RecMail * mail = new RecMail(); |
66 | mail->setWrapper(this); | 66 | mail->setWrapper(this); |
67 | mail_flags * flag_result = 0; | 67 | mail_flags * flag_result = 0; |
68 | r = mailmessage_get_flags(msg,&flag_result); | 68 | r = mailmessage_get_flags(msg,&flag_result); |
69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
70 | qDebug("flag fetching not implemented"); | ||
71 | mFlags.setBit(FLAG_SEEN); | 70 | mFlags.setBit(FLAG_SEEN); |
72 | } | 71 | } |
73 | mailimf_single_fields single_fields; | 72 | mailimf_single_fields single_fields; |
74 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 73 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
75 | mail->setMsgsize(msg->msg_size); | 74 | mail->setMsgsize(msg->msg_size); |
76 | mail->setFlags(mFlags); | 75 | mail->setFlags(mFlags); |
77 | mail->setMbox(mailbox); | 76 | mail->setMbox(mailbox); |
78 | mail->setNumber(i+1); | 77 | mail->setNumber(i+1); |
79 | if (single_fields.fld_subject) | 78 | if (single_fields.fld_subject) |
80 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 79 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
81 | if (single_fields.fld_from) | 80 | if (single_fields.fld_from) |
82 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 81 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
83 | if (single_fields.fld_to) | 82 | if (single_fields.fld_to) |
84 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 83 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
85 | if (single_fields.fld_cc) | 84 | if (single_fields.fld_cc) |
86 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 85 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
87 | if (single_fields.fld_bcc) | 86 | if (single_fields.fld_bcc) |
88 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 87 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
89 | if (single_fields.fld_orig_date) | 88 | if (single_fields.fld_orig_date) |
90 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 89 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
91 | if (single_fields.fld_message_id->mid_value) | 90 | if (single_fields.fld_message_id->mid_value) |
92 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 91 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
93 | refs = single_fields.fld_references; | 92 | refs = single_fields.fld_references; |
94 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 93 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
95 | char * text = (char*)refs->mid_list->first->data; | 94 | char * text = (char*)refs->mid_list->first->data; |
96 | mail->setReplyto(QString(text)); | 95 | mail->setReplyto(QString(text)); |
97 | } | 96 | } |
98 | 97 | ||
99 | target.append(mail); | 98 | target.append(mail); |
100 | } | 99 | } |
101 | if (env_list) { | 100 | if (env_list) { |
102 | mailmessage_list_free(env_list); | 101 | mailmessage_list_free(env_list); |
103 | } | 102 | } |
104 | mailfolder_disconnect(folder); | 103 | mailfolder_disconnect(folder); |
105 | mailfolder_free(folder); | 104 | mailfolder_free(folder); |
106 | mailstorage_free(storage); | 105 | mailstorage_free(storage); |
107 | } | 106 | } |
108 | 107 | ||
109 | QList<Folder>* MBOXwrapper::listFolders() | 108 | QList<Folder>* MBOXwrapper::listFolders() |
110 | { | 109 | { |
111 | QList<Folder> * folders = new QList<Folder>(); | 110 | QList<Folder> * folders = new QList<Folder>(); |
112 | folders->setAutoDelete( false ); | 111 | folders->setAutoDelete( false ); |
113 | QDir dir(MBOXPath); | 112 | QDir dir(MBOXPath); |
114 | if (!dir.exists()) return folders; | 113 | if (!dir.exists()) return folders; |
115 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 114 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
116 | QStringList entries = dir.entryList(); | 115 | QStringList entries = dir.entryList(); |
117 | QStringList::ConstIterator it = entries.begin(); | 116 | QStringList::ConstIterator it = entries.begin(); |
118 | for (;it!=entries.end();++it) { | 117 | for (;it!=entries.end();++it) { |
119 | Folder*inb=new Folder(*it,"/"); | 118 | Folder*inb=new Folder(*it,"/"); |
120 | folders->append(inb); | 119 | folders->append(inb); |
121 | } | 120 | } |
122 | return folders; | 121 | return folders; |
123 | } | 122 | } |
124 | 123 | ||
125 | void MBOXwrapper::deleteMail(const RecMail&mail) | 124 | void MBOXwrapper::deleteMail(const RecMail&mail) |
126 | { | 125 | { |
127 | mailstorage*storage = mailstorage_new(NULL); | 126 | mailstorage*storage = mailstorage_new(NULL); |
128 | QString p = MBOXPath+"/"; | 127 | QString p = MBOXPath+"/"; |
129 | p+=mail.getMbox(); | 128 | p+=mail.getMbox(); |
130 | mailmessage * msg; | 129 | mailmessage * msg; |
131 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 130 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
132 | mailfolder*folder; | 131 | mailfolder*folder; |
133 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 132 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
134 | r = mailfolder_connect(folder); | 133 | r = mailfolder_connect(folder); |
135 | if (r != MAIL_NO_ERROR) { | 134 | if (r != MAIL_NO_ERROR) { |
136 | qDebug("Error initializing mbox"); | 135 | qDebug("Error initializing mbox"); |
137 | mailfolder_free(folder); | 136 | mailfolder_free(folder); |
138 | mailstorage_free(storage); | 137 | mailstorage_free(storage); |
139 | return; | 138 | return; |
140 | } | 139 | } |
141 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 140 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
142 | if (r != MAIL_NO_ERROR) { | 141 | if (r != MAIL_NO_ERROR) { |
143 | qDebug("error deleting mail"); | 142 | qDebug("error deleting mail"); |
144 | } | 143 | } |
145 | mailfolder_free(folder); | 144 | mailfolder_free(folder); |
146 | mailstorage_free(storage); | 145 | mailstorage_free(storage); |
147 | } | 146 | } |
148 | 147 | ||
149 | void MBOXwrapper::answeredMail(const RecMail&) | 148 | void MBOXwrapper::answeredMail(const RecMail&) |
150 | { | 149 | { |
151 | } | 150 | } |
152 | 151 | ||
153 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 152 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
154 | { | 153 | { |
155 | RecBody body; | 154 | RecBody body; |
156 | mailstorage*storage = mailstorage_new(NULL); | 155 | mailstorage*storage = mailstorage_new(NULL); |
157 | QString p = MBOXPath+"/"; | 156 | QString p = MBOXPath+"/"; |
158 | p+=mail.getMbox(); | 157 | p+=mail.getMbox(); |
159 | mailmessage * msg; | 158 | mailmessage * msg; |
160 | char*data=0; | 159 | char*data=0; |
161 | size_t size; | 160 | size_t size; |
162 | 161 | ||
163 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
164 | mailfolder*folder; | 163 | mailfolder*folder; |
165 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
166 | r = mailfolder_connect(folder); | 165 | r = mailfolder_connect(folder); |
167 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
168 | qDebug("Error initializing mbox"); | 167 | qDebug("Error initializing mbox"); |
169 | mailfolder_free(folder); | 168 | mailfolder_free(folder); |
170 | mailstorage_free(storage); | 169 | mailstorage_free(storage); |
171 | return body; | 170 | return body; |
172 | } | 171 | } |
173 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
174 | if (r != MAIL_NO_ERROR) { | 173 | if (r != MAIL_NO_ERROR) { |
175 | qDebug("Error fetching mail %i",mail.getNumber()); | 174 | qDebug("Error fetching mail %i",mail.getNumber()); |
176 | mailfolder_free(folder); | 175 | mailfolder_free(folder); |
177 | mailstorage_free(storage); | 176 | mailstorage_free(storage); |
178 | return body; | 177 | return body; |
179 | } | 178 | } |
180 | r = mailmessage_fetch(msg,&data,&size); | 179 | r = mailmessage_fetch(msg,&data,&size); |
181 | if (r != MAIL_NO_ERROR) { | 180 | if (r != MAIL_NO_ERROR) { |
182 | qDebug("Error fetching mail %i",mail.getNumber()); | 181 | qDebug("Error fetching mail %i",mail.getNumber()); |
183 | mailfolder_free(folder); | 182 | mailfolder_free(folder); |
184 | mailstorage_free(storage); | 183 | mailstorage_free(storage); |
185 | mailmessage_free(msg); | 184 | mailmessage_free(msg); |
186 | return body; | 185 | return body; |
187 | } | 186 | } |
188 | body = parseMail(msg); | 187 | body = parseMail(msg); |
189 | mailmessage_fetch_result_free(msg,data); | 188 | mailmessage_fetch_result_free(msg,data); |
190 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
191 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
192 | 191 | ||
193 | return body; | 192 | return body; |
194 | } | 193 | } |
195 | 194 | ||
196 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
197 | { | 196 | { |
198 | qDebug("MBOX %i von %i",current,maximum); | 197 | qDebug("MBOX %i von %i",current,maximum); |
199 | } | 198 | } |
199 | |||
200 | void MBOXwrapper::createFolder(const QString&) | ||
201 | { | ||
202 | } | ||
203 | |||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | ||
205 | { | ||
206 | QString p = MBOXPath+"/"; | ||
207 | p+=folder; | ||
208 | mailmbox_folder*f = 0; | ||
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
210 | if (r != MAIL_NO_ERROR) { | ||
211 | qDebug("Error init folder"); | ||
212 | return; | ||
213 | } | ||
214 | r = mailmbox_append_message(f,msg,length); | ||
215 | if (r != MAIL_NO_ERROR) { | ||
216 | qDebug("Error writing message folder"); | ||
217 | } | ||
218 | mailmbox_done(f); | ||
219 | } | ||
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index 779dbc8..1bbaf79 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h | |||
@@ -1,30 +1,32 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | 9 | ||
10 | class MBOXwrapper : public Genericwrapper | 10 | class MBOXwrapper : public Genericwrapper |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | public: | 13 | public: |
14 | MBOXwrapper(const QString & dir); | 14 | MBOXwrapper(const QString & dir); |
15 | virtual ~MBOXwrapper(); | 15 | virtual ~MBOXwrapper(); |
16 | 16 | ||
17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
18 | virtual QList<Folder>* listFolders(); | 18 | virtual QList<Folder>* listFolders(); |
19 | 19 | ||
20 | virtual void deleteMail(const RecMail&mail); | 20 | virtual void deleteMail(const RecMail&mail); |
21 | virtual void answeredMail(const RecMail&mail); | 21 | virtual void answeredMail(const RecMail&mail); |
22 | virtual void createFolder(const QString&aFolder); | ||
23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | ||
22 | 24 | ||
23 | virtual RecBody fetchBody( const RecMail &mail ); | 25 | virtual RecBody fetchBody( const RecMail &mail ); |
24 | static void mbox_progress( size_t current, size_t maximum ); | 26 | static void mbox_progress( size_t current, size_t maximum ); |
25 | 27 | ||
26 | protected: | 28 | protected: |
27 | QString MBOXPath; | 29 | QString MBOXPath; |
28 | }; | 30 | }; |
29 | 31 | ||
30 | #endif | 32 | #endif |
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 162b1b9..a6a46ba 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp | |||
@@ -1,604 +1,645 @@ | |||
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 | 8 | ||
9 | #include <libetpan/mailmime.h> | 9 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
10 | #include <libetpan/mailimf.h> | 11 | #include <libetpan/mailimf.h> |
11 | #include <libetpan/mailsmtp.h> | 12 | #include <libetpan/mailsmtp.h> |
12 | #include <libetpan/mailstorage.h> | 13 | #include <libetpan/mailstorage.h> |
13 | #include <libetpan/maildriver.h> | 14 | #include <libetpan/maildriver.h> |
15 | #endif | ||
14 | 16 | ||
15 | #include "smtpwrapper.h" | 17 | #include "smtpwrapper.h" |
16 | #include "mailwrapper.h" | 18 | #include "mailwrapper.h" |
19 | #include "mboxwrapper.h" | ||
17 | #include "logindialog.h" | 20 | #include "logindialog.h" |
18 | #include "defines.h" | 21 | #include "defines.h" |
19 | 22 | ||
20 | SMTPwrapper::SMTPwrapper( Settings *s ) | 23 | SMTPwrapper::SMTPwrapper( Settings *s ) |
21 | : QObject() | 24 | : QObject() |
22 | { | 25 | { |
23 | settings = s; | 26 | settings = s; |
24 | } | 27 | } |
25 | 28 | ||
26 | QString SMTPwrapper::mailsmtpError( int errnum ) | 29 | QString SMTPwrapper::mailsmtpError( int errnum ) |
27 | { | 30 | { |
28 | switch ( errnum ) { | 31 | switch ( errnum ) { |
29 | case MAILSMTP_NO_ERROR: | 32 | case MAILSMTP_NO_ERROR: |
30 | return tr( "No error" ); | 33 | return tr( "No error" ); |
31 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 34 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
32 | return tr( "Unexpected error code" ); | 35 | return tr( "Unexpected error code" ); |
33 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 36 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
34 | return tr( "Service not available" ); | 37 | return tr( "Service not available" ); |
35 | case MAILSMTP_ERROR_STREAM: | 38 | case MAILSMTP_ERROR_STREAM: |
36 | return tr( "Stream error" ); | 39 | return tr( "Stream error" ); |
37 | case MAILSMTP_ERROR_HOSTNAME: | 40 | case MAILSMTP_ERROR_HOSTNAME: |
38 | return tr( "gethostname() failed" ); | 41 | return tr( "gethostname() failed" ); |
39 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 42 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
40 | return tr( "Not implemented" ); | 43 | return tr( "Not implemented" ); |
41 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 44 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
42 | return tr( "Error, action not taken" ); | 45 | return tr( "Error, action not taken" ); |
43 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 46 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
44 | return tr( "Data exceeds storage allocation" ); | 47 | return tr( "Data exceeds storage allocation" ); |
45 | case MAILSMTP_ERROR_IN_PROCESSING: | 48 | case MAILSMTP_ERROR_IN_PROCESSING: |
46 | return tr( "Error in processing" ); | 49 | return tr( "Error in processing" ); |
47 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 50 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
48 | // return tr( "Insufficient system storage" ); | 51 | // return tr( "Insufficient system storage" ); |
49 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 52 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
50 | return tr( "Mailbox unavailable" ); | 53 | return tr( "Mailbox unavailable" ); |
51 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 54 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
52 | return tr( "Mailbox name not allowed" ); | 55 | return tr( "Mailbox name not allowed" ); |
53 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 56 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
54 | return tr( "Bad command sequence" ); | 57 | return tr( "Bad command sequence" ); |
55 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 58 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
56 | return tr( "User not local" ); | 59 | return tr( "User not local" ); |
57 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 60 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
58 | return tr( "Transaction failed" ); | 61 | return tr( "Transaction failed" ); |
59 | case MAILSMTP_ERROR_MEMORY: | 62 | case MAILSMTP_ERROR_MEMORY: |
60 | return tr( "Memory error" ); | 63 | return tr( "Memory error" ); |
61 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 64 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
62 | return tr( "Connection refused" ); | 65 | return tr( "Connection refused" ); |
63 | default: | 66 | default: |
64 | return tr( "Unknown error code" ); | 67 | return tr( "Unknown error code" ); |
65 | } | 68 | } |
66 | } | 69 | } |
67 | 70 | ||
68 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 71 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
69 | { | 72 | { |
70 | return mailimf_mailbox_new( strdup( name.latin1() ), | 73 | return mailimf_mailbox_new( strdup( name.latin1() ), |
71 | strdup( mail.latin1() ) ); | 74 | strdup( mail.latin1() ) ); |
72 | } | 75 | } |
73 | 76 | ||
74 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 77 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
75 | { | 78 | { |
76 | mailimf_address_list *addresses; | 79 | mailimf_address_list *addresses; |
77 | 80 | ||
78 | if ( addr.isEmpty() ) return NULL; | 81 | if ( addr.isEmpty() ) return NULL; |
79 | 82 | ||
80 | addresses = mailimf_address_list_new_empty(); | 83 | addresses = mailimf_address_list_new_empty(); |
81 | 84 | ||
82 | QStringList list = QStringList::split( ',', addr ); | 85 | QStringList list = QStringList::split( ',', addr ); |
83 | QStringList::Iterator it; | 86 | QStringList::Iterator it; |
84 | for ( it = list.begin(); it != list.end(); it++ ) { | 87 | for ( it = list.begin(); it != list.end(); it++ ) { |
85 | char *str = strdup( (*it).latin1() ); | 88 | char *str = strdup( (*it).latin1() ); |
86 | int err = mailimf_address_list_add_parse( addresses, str ); | 89 | int err = mailimf_address_list_add_parse( addresses, str ); |
87 | if ( err != MAILIMF_NO_ERROR ) { | 90 | if ( err != MAILIMF_NO_ERROR ) { |
88 | qDebug( "Error parsing" ); | 91 | qDebug( "Error parsing" ); |
89 | qDebug( *it ); | 92 | qDebug( *it ); |
90 | free( str ); | 93 | free( str ); |
91 | } else { | 94 | } else { |
92 | qDebug( "Parse success! :)" ); | 95 | qDebug( "Parse success! :)" ); |
93 | } | 96 | } |
94 | } | 97 | } |
95 | 98 | ||
96 | return addresses; | 99 | return addresses; |
97 | } | 100 | } |
98 | 101 | ||
99 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 102 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
100 | { | 103 | { |
101 | mailimf_fields *fields; | 104 | mailimf_fields *fields; |
102 | mailimf_field *xmailer; | 105 | mailimf_field *xmailer; |
103 | mailimf_mailbox *sender, *fromBox; | 106 | mailimf_mailbox *sender, *fromBox; |
104 | mailimf_mailbox_list *from; | 107 | mailimf_mailbox_list *from; |
105 | mailimf_address_list *to, *cc, *bcc, *reply; | 108 | mailimf_address_list *to, *cc, *bcc, *reply; |
106 | char *subject = strdup( mail.getSubject().latin1() ); | 109 | char *subject = strdup( mail.getSubject().latin1() ); |
107 | int err; | 110 | int err; |
108 | 111 | ||
109 | sender = newMailbox( mail.getName(), mail.getMail() ); | 112 | sender = newMailbox( mail.getName(), mail.getMail() ); |
110 | if ( sender == NULL ) goto err_free; | 113 | if ( sender == NULL ) goto err_free; |
111 | 114 | ||
112 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 115 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
113 | if ( fromBox == NULL ) goto err_free_sender; | 116 | if ( fromBox == NULL ) goto err_free_sender; |
114 | 117 | ||
115 | from = mailimf_mailbox_list_new_empty(); | 118 | from = mailimf_mailbox_list_new_empty(); |
116 | if ( from == NULL ) goto err_free_fromBox; | 119 | if ( from == NULL ) goto err_free_fromBox; |
117 | 120 | ||
118 | err = mailimf_mailbox_list_add( from, fromBox ); | 121 | err = mailimf_mailbox_list_add( from, fromBox ); |
119 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 122 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
120 | 123 | ||
121 | to = parseAddresses( mail.getTo() ); | 124 | to = parseAddresses( mail.getTo() ); |
122 | if ( to == NULL ) goto err_free_from; | 125 | if ( to == NULL ) goto err_free_from; |
123 | 126 | ||
124 | cc = parseAddresses( mail.getCC() ); | 127 | cc = parseAddresses( mail.getCC() ); |
125 | bcc = parseAddresses( mail.getBCC() ); | 128 | bcc = parseAddresses( mail.getBCC() ); |
126 | reply = parseAddresses( mail.getReply() ); | 129 | reply = parseAddresses( mail.getReply() ); |
127 | 130 | ||
128 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 131 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
129 | NULL, NULL, subject ); | 132 | NULL, NULL, subject ); |
130 | if ( fields == NULL ) goto err_free_reply; | 133 | if ( fields == NULL ) goto err_free_reply; |
131 | 134 | ||
132 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 135 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
133 | strdup( USER_AGENT ) ); | 136 | strdup( USER_AGENT ) ); |
134 | if ( xmailer == NULL ) goto err_free_fields; | 137 | if ( xmailer == NULL ) goto err_free_fields; |
135 | 138 | ||
136 | err = mailimf_fields_add( fields, xmailer ); | 139 | err = mailimf_fields_add( fields, xmailer ); |
137 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 140 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
138 | 141 | ||
139 | return fields; // Success :) | 142 | return fields; // Success :) |
140 | 143 | ||
141 | err_free_xmailer: | 144 | err_free_xmailer: |
142 | mailimf_field_free( xmailer ); | 145 | mailimf_field_free( xmailer ); |
143 | err_free_fields: | 146 | err_free_fields: |
144 | mailimf_fields_free( fields ); | 147 | mailimf_fields_free( fields ); |
145 | err_free_reply: | 148 | err_free_reply: |
146 | mailimf_address_list_free( reply ); | 149 | mailimf_address_list_free( reply ); |
147 | mailimf_address_list_free( bcc ); | 150 | mailimf_address_list_free( bcc ); |
148 | mailimf_address_list_free( cc ); | 151 | mailimf_address_list_free( cc ); |
149 | mailimf_address_list_free( to ); | 152 | mailimf_address_list_free( to ); |
150 | err_free_from: | 153 | err_free_from: |
151 | mailimf_mailbox_list_free( from ); | 154 | mailimf_mailbox_list_free( from ); |
152 | err_free_fromBox: | 155 | err_free_fromBox: |
153 | mailimf_mailbox_free( fromBox ); | 156 | mailimf_mailbox_free( fromBox ); |
154 | err_free_sender: | 157 | err_free_sender: |
155 | mailimf_mailbox_free( sender ); | 158 | mailimf_mailbox_free( sender ); |
156 | err_free: | 159 | err_free: |
157 | free( subject ); | 160 | free( subject ); |
158 | qDebug( "createImfFields - error" ); | 161 | qDebug( "createImfFields - error" ); |
159 | 162 | ||
160 | return NULL; // Error :( | 163 | return NULL; // Error :( |
161 | } | 164 | } |
162 | 165 | ||
163 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 166 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
164 | { | 167 | { |
165 | mailmime *txtPart; | 168 | mailmime *txtPart; |
166 | mailmime_fields *fields; | 169 | mailmime_fields *fields; |
167 | mailmime_content *content; | 170 | mailmime_content *content; |
168 | mailmime_parameter *param; | 171 | mailmime_parameter *param; |
169 | char *txt = strdup( str.latin1() ); | 172 | char *txt = strdup( str.latin1() ); |
170 | int err; | 173 | int err; |
171 | 174 | ||
172 | param = mailmime_parameter_new( strdup( "charset" ), | 175 | param = mailmime_parameter_new( strdup( "charset" ), |
173 | strdup( "iso-8859-1" ) ); | 176 | strdup( "iso-8859-1" ) ); |
174 | if ( param == NULL ) goto err_free; | 177 | if ( param == NULL ) goto err_free; |
175 | 178 | ||
176 | content = mailmime_content_new_with_str( "text/plain" ); | 179 | content = mailmime_content_new_with_str( "text/plain" ); |
177 | if ( content == NULL ) goto err_free_param; | 180 | if ( content == NULL ) goto err_free_param; |
178 | 181 | ||
179 | err = clist_append( content->ct_parameters, param ); | 182 | err = clist_append( content->ct_parameters, param ); |
180 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 183 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
181 | 184 | ||
182 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 185 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
183 | if ( fields == NULL ) goto err_free_content; | 186 | if ( fields == NULL ) goto err_free_content; |
184 | 187 | ||
185 | txtPart = mailmime_new_empty( content, fields ); | 188 | txtPart = mailmime_new_empty( content, fields ); |
186 | if ( txtPart == NULL ) goto err_free_fields; | 189 | if ( txtPart == NULL ) goto err_free_fields; |
187 | 190 | ||
188 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 191 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
189 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 192 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
190 | 193 | ||
191 | return txtPart; // Success :) | 194 | return txtPart; // Success :) |
192 | 195 | ||
193 | err_free_txtPart: | 196 | err_free_txtPart: |
194 | mailmime_free( txtPart ); | 197 | mailmime_free( txtPart ); |
195 | err_free_fields: | 198 | err_free_fields: |
196 | mailmime_fields_free( fields ); | 199 | mailmime_fields_free( fields ); |
197 | err_free_content: | 200 | err_free_content: |
198 | mailmime_content_free( content ); | 201 | mailmime_content_free( content ); |
199 | err_free_param: | 202 | err_free_param: |
200 | mailmime_parameter_free( param ); | 203 | mailmime_parameter_free( param ); |
201 | err_free: | 204 | err_free: |
202 | free( txt ); | 205 | free( txt ); |
203 | qDebug( "buildTxtPart - error" ); | 206 | qDebug( "buildTxtPart - error" ); |
204 | 207 | ||
205 | return NULL; // Error :( | 208 | return NULL; // Error :( |
206 | } | 209 | } |
207 | 210 | ||
208 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) | 211 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) |
209 | { | 212 | { |
210 | mailmime * filePart; | 213 | mailmime * filePart; |
211 | mailmime_fields * fields; | 214 | mailmime_fields * fields; |
212 | mailmime_content * content; | 215 | mailmime_content * content; |
213 | mailmime_parameter * param = NULL; | 216 | mailmime_parameter * param = NULL; |
214 | int err; | 217 | int err; |
215 | 218 | ||
216 | int pos = filename.findRev( '/' ); | 219 | int pos = filename.findRev( '/' ); |
217 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
218 | char *name = strdup( tmp.latin1() ); // just filename | 221 | char *name = strdup( tmp.latin1() ); // just filename |
219 | char *file = strdup( filename.latin1() ); // full name with path | 222 | char *file = strdup( filename.latin1() ); // full name with path |
220 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 223 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
221 | 224 | ||
222 | fields = mailmime_fields_new_filename( | 225 | fields = mailmime_fields_new_filename( |
223 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 226 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
224 | MAILMIME_MECHANISM_BASE64 ); | 227 | MAILMIME_MECHANISM_BASE64 ); |
225 | if ( fields == NULL ) goto err_free; | 228 | if ( fields == NULL ) goto err_free; |
226 | 229 | ||
227 | content = mailmime_content_new_with_str( mime ); | 230 | content = mailmime_content_new_with_str( mime ); |
228 | if ( content == NULL ) goto err_free_fields; | 231 | if ( content == NULL ) goto err_free_fields; |
229 | 232 | ||
230 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 233 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
231 | param = mailmime_parameter_new( strdup( "charset" ), | 234 | param = mailmime_parameter_new( strdup( "charset" ), |
232 | strdup( "iso-8859-1" ) ); | 235 | strdup( "iso-8859-1" ) ); |
233 | if ( param == NULL ) goto err_free_content; | 236 | if ( param == NULL ) goto err_free_content; |
234 | 237 | ||
235 | err = clist_append( content->ct_parameters, param ); | 238 | err = clist_append( content->ct_parameters, param ); |
236 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 239 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
237 | } | 240 | } |
238 | 241 | ||
239 | filePart = mailmime_new_empty( content, fields ); | 242 | filePart = mailmime_new_empty( content, fields ); |
240 | if ( filePart == NULL ) goto err_free_param; | 243 | if ( filePart == NULL ) goto err_free_param; |
241 | 244 | ||
242 | err = mailmime_set_body_file( filePart, file ); | 245 | err = mailmime_set_body_file( filePart, file ); |
243 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 246 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
244 | 247 | ||
245 | return filePart; // Success :) | 248 | return filePart; // Success :) |
246 | 249 | ||
247 | err_free_filePart: | 250 | err_free_filePart: |
248 | mailmime_free( filePart ); | 251 | mailmime_free( filePart ); |
249 | err_free_param: | 252 | err_free_param: |
250 | if ( param != NULL ) mailmime_parameter_free( param ); | 253 | if ( param != NULL ) mailmime_parameter_free( param ); |
251 | err_free_content: | 254 | err_free_content: |
252 | mailmime_content_free( content ); | 255 | mailmime_content_free( content ); |
253 | err_free_fields: | 256 | err_free_fields: |
254 | mailmime_fields_free( fields ); | 257 | mailmime_fields_free( fields ); |
255 | err_free: | 258 | err_free: |
256 | free( name ); | 259 | free( name ); |
257 | free( mime ); | 260 | free( mime ); |
258 | free( file ); | 261 | free( file ); |
259 | qDebug( "buildFilePart - error" ); | 262 | qDebug( "buildFilePart - error" ); |
260 | 263 | ||
261 | return NULL; // Error :( | 264 | return NULL; // Error :( |
262 | } | 265 | } |
263 | 266 | ||
264 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 267 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
265 | { | 268 | { |
266 | const Attachment *it; | 269 | const Attachment *it; |
267 | /* work around for the brainfucked qlist which can not act with const values */ | 270 | /* work around for the brainfucked qlist which can not act with const values */ |
268 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { | 271 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { |
269 | qDebug( "Adding file" ); | 272 | qDebug( "Adding file" ); |
270 | mailmime *filePart; | 273 | mailmime *filePart; |
271 | int err; | 274 | int err; |
272 | 275 | ||
273 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 276 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
274 | if ( filePart == NULL ) goto err_free; | 277 | if ( filePart == NULL ) goto err_free; |
275 | 278 | ||
276 | err = mailmime_smart_add_part( message, filePart ); | 279 | err = mailmime_smart_add_part( message, filePart ); |
277 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 280 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
278 | 281 | ||
279 | continue; // Success :) | 282 | continue; // Success :) |
280 | 283 | ||
281 | err_free_filePart: | 284 | err_free_filePart: |
282 | mailmime_free( filePart ); | 285 | mailmime_free( filePart ); |
283 | err_free: | 286 | err_free: |
284 | qDebug( "addFileParts: error adding file:" ); | 287 | qDebug( "addFileParts: error adding file:" ); |
285 | qDebug( it->getFileName() ); | 288 | qDebug( it->getFileName() ); |
286 | } | 289 | } |
287 | } | 290 | } |
288 | 291 | ||
289 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 292 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
290 | { | 293 | { |
291 | mailmime *message, *txtPart; | 294 | mailmime *message, *txtPart; |
292 | mailimf_fields *fields; | 295 | mailimf_fields *fields; |
293 | int err; | 296 | int err; |
294 | 297 | ||
295 | fields = createImfFields( mail ); | 298 | fields = createImfFields( mail ); |
296 | if ( fields == NULL ) goto err_free; | 299 | if ( fields == NULL ) goto err_free; |
297 | 300 | ||
298 | message = mailmime_new_message_data( NULL ); | 301 | message = mailmime_new_message_data( NULL ); |
299 | if ( message == NULL ) goto err_free_fields; | 302 | if ( message == NULL ) goto err_free_fields; |
300 | 303 | ||
301 | mailmime_set_imf_fields( message, fields ); | 304 | mailmime_set_imf_fields( message, fields ); |
302 | 305 | ||
303 | txtPart = buildTxtPart( mail.getMessage() ); | 306 | txtPart = buildTxtPart( mail.getMessage() ); |
304 | if ( txtPart == NULL ) goto err_free_message; | 307 | if ( txtPart == NULL ) goto err_free_message; |
305 | 308 | ||
306 | err = mailmime_smart_add_part( message, txtPart ); | 309 | err = mailmime_smart_add_part( message, txtPart ); |
307 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 310 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
308 | 311 | ||
309 | addFileParts( message, mail.getAttachments() ); | 312 | addFileParts( message, mail.getAttachments() ); |
310 | 313 | ||
311 | return message; // Success :) | 314 | return message; // Success :) |
312 | 315 | ||
313 | err_free_txtPart: | 316 | err_free_txtPart: |
314 | mailmime_free( txtPart ); | 317 | mailmime_free( txtPart ); |
315 | err_free_message: | 318 | err_free_message: |
316 | mailmime_free( message ); | 319 | mailmime_free( message ); |
317 | err_free_fields: | 320 | err_free_fields: |
318 | mailimf_fields_free( fields ); | 321 | mailimf_fields_free( fields ); |
319 | err_free: | 322 | err_free: |
320 | qDebug( "createMimeMail: error" ); | 323 | qDebug( "createMimeMail: error" ); |
321 | 324 | ||
322 | return NULL; // Error :( | 325 | return NULL; // Error :( |
323 | } | 326 | } |
324 | 327 | ||
325 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 328 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
326 | { | 329 | { |
327 | mailimf_field *field; | 330 | mailimf_field *field; |
328 | clistiter *it; | 331 | clistiter *it; |
329 | 332 | ||
330 | it = clist_begin( fields->fld_list ); | 333 | it = clist_begin( fields->fld_list ); |
331 | while ( it ) { | 334 | while ( it ) { |
332 | field = (mailimf_field *) it->data; | 335 | field = (mailimf_field *) it->data; |
333 | if ( field->fld_type == type ) { | 336 | if ( field->fld_type == type ) { |
334 | return field; | 337 | return field; |
335 | } | 338 | } |
336 | it = it->next; | 339 | it = it->next; |
337 | } | 340 | } |
338 | 341 | ||
339 | return NULL; | 342 | return NULL; |
340 | } | 343 | } |
341 | 344 | ||
342 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 345 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
343 | { | 346 | { |
344 | clistiter *it, *it2; | 347 | clistiter *it, *it2; |
345 | 348 | ||
346 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 349 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
347 | mailimf_address *addr; | 350 | mailimf_address *addr; |
348 | addr = (mailimf_address *) it->data; | 351 | addr = (mailimf_address *) it->data; |
349 | 352 | ||
350 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 353 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
351 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 354 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
352 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 355 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
353 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 356 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
354 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 357 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
355 | mailimf_mailbox *mbox; | 358 | mailimf_mailbox *mbox; |
356 | mbox = (mailimf_mailbox *) it2->data; | 359 | mbox = (mailimf_mailbox *) it2->data; |
357 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 360 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
358 | } | 361 | } |
359 | } | 362 | } |
360 | } | 363 | } |
361 | } | 364 | } |
362 | 365 | ||
363 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 366 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
364 | { | 367 | { |
365 | clist *rcptList; | 368 | clist *rcptList; |
366 | mailimf_field *field; | 369 | mailimf_field *field; |
367 | 370 | ||
368 | rcptList = esmtp_address_list_new(); | 371 | rcptList = esmtp_address_list_new(); |
369 | 372 | ||
370 | field = getField( fields, MAILIMF_FIELD_TO ); | 373 | field = getField( fields, MAILIMF_FIELD_TO ); |
371 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 374 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
372 | && field->fld_data.fld_to->to_addr_list ) { | 375 | && field->fld_data.fld_to->to_addr_list ) { |
373 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 376 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
374 | } | 377 | } |
375 | 378 | ||
376 | field = getField( fields, MAILIMF_FIELD_CC ); | 379 | field = getField( fields, MAILIMF_FIELD_CC ); |
377 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 380 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
378 | && field->fld_data.fld_cc->cc_addr_list ) { | 381 | && field->fld_data.fld_cc->cc_addr_list ) { |
379 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 382 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
380 | } | 383 | } |
381 | 384 | ||
382 | field = getField( fields, MAILIMF_FIELD_BCC ); | 385 | field = getField( fields, MAILIMF_FIELD_BCC ); |
383 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 386 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
384 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 387 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
385 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 388 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
386 | } | 389 | } |
387 | 390 | ||
388 | return rcptList; | 391 | return rcptList; |
389 | } | 392 | } |
390 | 393 | ||
391 | char *SMTPwrapper::getFrom( mailmime *mail ) | 394 | char *SMTPwrapper::getFrom( mailmime *mail ) |
392 | { | 395 | { |
393 | char *from = NULL; | 396 | char *from = NULL; |
394 | 397 | ||
395 | mailimf_field *ffrom; | 398 | mailimf_field *ffrom; |
396 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 399 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
397 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 400 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
398 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 401 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
399 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 402 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
400 | clistiter *it; | 403 | clistiter *it; |
401 | for ( it = clist_begin( cl ); it; it = it->next ) { | 404 | for ( it = clist_begin( cl ); it; it = it->next ) { |
402 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 405 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
403 | from = strdup( mb->mb_addr_spec ); | 406 | from = strdup( mb->mb_addr_spec ); |
404 | } | 407 | } |
405 | } | 408 | } |
406 | 409 | ||
407 | return from; | 410 | return from; |
408 | } | 411 | } |
409 | 412 | ||
410 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | 413 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) |
411 | { | 414 | { |
412 | SMTPaccount *smtp; | 415 | SMTPaccount *smtp; |
413 | 416 | ||
414 | QList<Account> list = settings->getAccounts(); | 417 | QList<Account> list = settings->getAccounts(); |
415 | Account *it; | 418 | Account *it; |
416 | for ( it = list.first(); it; it = list.next() ) { | 419 | for ( it = list.first(); it; it = list.next() ) { |
417 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 420 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
418 | smtp = static_cast<SMTPaccount *>(it); | 421 | smtp = static_cast<SMTPaccount *>(it); |
419 | if ( smtp->getMail().compare( from ) == 0 ) { | 422 | if ( smtp->getMail().compare( from ) == 0 ) { |
420 | qDebug( "SMTPaccount found for" ); | 423 | qDebug( "SMTPaccount found for" ); |
421 | qDebug( from ); | 424 | qDebug( from ); |
422 | return smtp; | 425 | return smtp; |
423 | } | 426 | } |
424 | } | 427 | } |
425 | } | 428 | } |
426 | 429 | ||
427 | return NULL; | 430 | return NULL; |
428 | } | 431 | } |
429 | 432 | ||
430 | QString SMTPwrapper::getTmpFile() { | 433 | QString SMTPwrapper::getTmpFile() { |
431 | int num = 0; | 434 | int num = 0; |
432 | QString unique; | 435 | QString unique; |
433 | 436 | ||
434 | QDir dir( "/tmp" ); | 437 | QDir dir( "/tmp" ); |
435 | QStringList::Iterator it; | 438 | QStringList::Iterator it; |
436 | 439 | ||
437 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 440 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
438 | do { | 441 | do { |
439 | unique.setNum( num++ ); | 442 | unique.setNum( num++ ); |
440 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 443 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
441 | 444 | ||
442 | return "/tmp/opiemail-tmp-" + unique; | 445 | return "/tmp/opiemail-tmp-" + unique; |
443 | } | 446 | } |
444 | 447 | ||
445 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 448 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
446 | { | 449 | { |
447 | FILE *f; | 450 | FILE *f; |
448 | int err, col = 0; | 451 | int err, col = 0; |
449 | 452 | ||
450 | f = fopen( file.latin1(), "w" ); | 453 | f = fopen( file.latin1(), "w" ); |
451 | if ( f == NULL ) { | 454 | if ( f == NULL ) { |
452 | qDebug( "writeToFile: error opening file" ); | 455 | qDebug( "writeToFile: error opening file" ); |
453 | return; | 456 | return; |
454 | } | 457 | } |
455 | 458 | ||
456 | err = mailmime_write( f, &col, mail ); | 459 | err = mailmime_write( f, &col, mail ); |
457 | if ( err != MAILIMF_NO_ERROR ) { | 460 | if ( err != MAILIMF_NO_ERROR ) { |
458 | fclose( f ); | 461 | fclose( f ); |
459 | qDebug( "writeToFile: error writing mailmime" ); | 462 | qDebug( "writeToFile: error writing mailmime" ); |
460 | return; | 463 | return; |
461 | } | 464 | } |
462 | 465 | ||
463 | fclose( f ); | 466 | fclose( f ); |
464 | } | 467 | } |
465 | 468 | ||
466 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 469 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
467 | { | 470 | { |
471 | |||
472 | QFile msg_cache(file); | ||
473 | QString msg = ""; | ||
474 | msg_cache.open(IO_ReadOnly); | ||
475 | char*message = new char[4096]; | ||
476 | memset(message,0,4096); | ||
477 | while (msg_cache.readBlock(message,4095)>0) { | ||
478 | msg+=message; | ||
479 | memset(message,0,4096); | ||
480 | } | ||
481 | delete message; | ||
482 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | ||
483 | memset(*data,0,msg.length()+1); | ||
484 | memcpy(*data,msg.ascii(),msg.length()); | ||
485 | *size=msg.length(); | ||
486 | |||
487 | #if 0 | ||
468 | char *buf; | 488 | char *buf; |
469 | struct stat st; | 489 | struct stat st; |
470 | int fd, count = 0, total = 0; | 490 | int fd, count = 0, total = 0; |
471 | 491 | ||
472 | fd = open( file.latin1(), O_RDONLY, 0 ); | 492 | fd = open( file.latin1(), O_RDONLY, 0 ); |
473 | if ( fd == -1 ) return; | 493 | if ( fd == -1 ) return; |
474 | 494 | ||
475 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 495 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
476 | if ( !st.st_size ) goto err_close; | 496 | if ( !st.st_size ) goto err_close; |
477 | 497 | ||
478 | buf = (char *) malloc( st.st_size ); | 498 | buf = (char *) malloc( st.st_size ); |
479 | if ( !buf ) goto err_close; | 499 | if ( !buf ) goto err_close; |
480 | 500 | ||
481 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
482 | count = read( fd, buf + total, st.st_size - total ); | 502 | count = read( fd, buf + total, st.st_size - total ); |
483 | total += count; | 503 | total += count; |
484 | } | 504 | } |
485 | if ( count < 0 ) goto err_free; | 505 | if ( count < 0 ) goto err_free; |
486 | 506 | ||
487 | *data = buf; | 507 | *data = buf; |
488 | *size = st.st_size; | 508 | *size = st.st_size; |
489 | 509 | ||
490 | close( fd ); | 510 | close( fd ); |
491 | 511 | ||
492 | return; // Success :) | 512 | return; // Success :) |
493 | 513 | ||
494 | err_free: | 514 | err_free: |
495 | free( buf ); | 515 | free( buf ); |
496 | err_close: | 516 | err_close: |
497 | close( fd ); | 517 | close( fd ); |
518 | #endif | ||
498 | } | 519 | } |
499 | 520 | ||
500 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 521 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
501 | { | 522 | { |
502 | qDebug( "Current: %i of %i", current, maximum ); | 523 | qDebug( "Current: %i of %i", current, maximum ); |
503 | } | 524 | } |
504 | 525 | ||
505 | void SMTPwrapper::smtpSend( mailmime *mail ) | 526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
527 | { | ||
528 | if (!mail) return; | ||
529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
531 | wrap->storeMessage(mail,length,box); | ||
532 | delete wrap; | ||
533 | } | ||
534 | |||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | ||
506 | { | 536 | { |
507 | mailsmtp *session; | 537 | mailsmtp *session; |
508 | clist *rcpts; | 538 | clist *rcpts; |
509 | char *from, *data, *server, *user = NULL, *pass = NULL; | 539 | char *from, *data, *server, *user = NULL, *pass = NULL; |
510 | size_t size; | 540 | size_t size; |
511 | int err; | 541 | int err; |
512 | bool ssl; | 542 | bool ssl; |
513 | uint16_t port; | 543 | uint16_t port; |
514 | 544 | ||
515 | 545 | ||
516 | from = getFrom( mail ); | 546 | from = getFrom( mail ); |
517 | SMTPaccount *smtp = getAccount( from ); | 547 | SMTPaccount *smtp = getAccount( from ); |
518 | if ( smtp == NULL ) { | 548 | if ( smtp == NULL ) { |
519 | free(from); | 549 | free(from); |
520 | return; | 550 | return; |
521 | } | 551 | } |
522 | server = strdup( smtp->getServer().latin1() ); | ||
523 | ssl = smtp->getSSL(); | ||
524 | port = smtp->getPort().toUInt(); | ||
525 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
526 | 553 | ||
527 | QString file = getTmpFile(); | 554 | QString file = getTmpFile(); |
528 | writeToFile( file, mail ); | 555 | writeToFile( file, mail ); |
556 | |||
529 | readFromFile( file, &data, &size ); | 557 | readFromFile( file, &data, &size ); |
530 | QFile f( file ); | 558 | QFile f( file ); |
531 | f.remove(); | 559 | f.remove(); |
560 | |||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
532 | 562 | ||
563 | if (later) { | ||
564 | smtp_address_list_free( rcpts ); | ||
565 | if (data) free( data ); | ||
566 | if (from) free(from); | ||
567 | return; | ||
568 | } | ||
569 | server = strdup( smtp->getServer().latin1() ); | ||
570 | ssl = smtp->getSSL(); | ||
571 | port = smtp->getPort().toUInt(); | ||
572 | |||
533 | session = mailsmtp_new( 20, &progress ); | 573 | session = mailsmtp_new( 20, &progress ); |
534 | if ( session == NULL ) goto free_mem; | 574 | if ( session == NULL ) goto free_mem; |
535 | 575 | ||
536 | qDebug( "Servername %s at port %i", server, port ); | 576 | qDebug( "Servername %s at port %i", server, port ); |
537 | if ( ssl ) { | 577 | if ( ssl ) { |
538 | qDebug( "SSL session" ); | 578 | qDebug( "SSL session" ); |
539 | err = mailsmtp_ssl_connect( session, server, port ); | 579 | err = mailsmtp_ssl_connect( session, server, port ); |
540 | } else { | 580 | } else { |
541 | qDebug( "No SSL session" ); | 581 | qDebug( "No SSL session" ); |
542 | err = mailsmtp_socket_connect( session, server, port ); | 582 | err = mailsmtp_socket_connect( session, server, port ); |
543 | } | 583 | } |
544 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 584 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
545 | 585 | ||
546 | err = mailsmtp_init( session ); | 586 | err = mailsmtp_init( session ); |
547 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 587 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
548 | 588 | ||
549 | qDebug( "INIT OK" ); | 589 | qDebug( "INIT OK" ); |
550 | 590 | ||
551 | if ( smtp->getLogin() ) { | 591 | if ( smtp->getLogin() ) { |
552 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 592 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
553 | // get'em | 593 | // get'em |
554 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 594 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
555 | login.show(); | 595 | login.show(); |
556 | if ( QDialog::Accepted == login.exec() ) { | 596 | if ( QDialog::Accepted == login.exec() ) { |
557 | // ok | 597 | // ok |
558 | user = strdup( login.getUser().latin1() ); | 598 | user = strdup( login.getUser().latin1() ); |
559 | pass = strdup( login.getPassword().latin1() ); | 599 | pass = strdup( login.getPassword().latin1() ); |
560 | } else { | 600 | } else { |
561 | goto free_con_session; | 601 | goto free_con_session; |
562 | } | 602 | } |
563 | } else { | 603 | } else { |
564 | user = strdup( smtp->getUser().latin1() ); | 604 | user = strdup( smtp->getUser().latin1() ); |
565 | pass = strdup( smtp->getPassword().latin1() ); | 605 | pass = strdup( smtp->getPassword().latin1() ); |
566 | } | 606 | } |
567 | qDebug( "session->auth: %i", session->auth); | 607 | qDebug( "session->auth: %i", session->auth); |
568 | err = mailsmtp_auth( session, user, pass ); | 608 | err = mailsmtp_auth( session, user, pass ); |
569 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 609 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
570 | qDebug( "Done auth!" ); | 610 | qDebug( "Done auth!" ); |
571 | } | 611 | } |
572 | 612 | ||
573 | err = mailsmtp_send( session, from, rcpts, data, size ); | 613 | err = mailsmtp_send( session, from, rcpts, data, size ); |
574 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 614 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
575 | 615 | ||
576 | qDebug( "Mail sent." ); | 616 | qDebug( "Mail sent." ); |
577 | 617 | ||
578 | free_con_session: | 618 | free_con_session: |
579 | mailsmtp_quit( session ); | 619 | mailsmtp_quit( session ); |
580 | free_mem_session: | 620 | free_mem_session: |
581 | mailsmtp_free( session ); | 621 | mailsmtp_free( session ); |
582 | free_mem: | 622 | free_mem: |
583 | smtp_address_list_free( rcpts ); | 623 | smtp_address_list_free( rcpts ); |
584 | free( data ); | 624 | if (data) free( data ); |
585 | free( server ); | 625 | if (from) free(from); |
626 | if (server) free( server ); | ||
586 | if ( smtp->getLogin() ) { | 627 | if ( smtp->getLogin() ) { |
587 | free( user ); | 628 | free( user ); |
588 | free( pass ); | 629 | free( pass ); |
589 | } | 630 | } |
590 | free( from ); | 631 | free( from ); |
591 | } | 632 | } |
592 | 633 | ||
593 | void SMTPwrapper::sendMail(const Mail&mail ) | 634 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
594 | { | 635 | { |
595 | mailmime *mimeMail; | 636 | mailmime * mimeMail; |
596 | 637 | ||
597 | mimeMail = createMimeMail(mail ); | 638 | mimeMail = createMimeMail(mail ); |
598 | if ( mimeMail == NULL ) { | 639 | if ( mimeMail == NULL ) { |
599 | qDebug( "sendMail: error creating mime mail" ); | 640 | qDebug( "sendMail: error creating mime mail" ); |
600 | } else { | 641 | } else { |
601 | smtpSend( mimeMail ); | 642 | smtpSend( mimeMail,later ); |
602 | mailmime_free( mimeMail ); | 643 | mailmime_free( mimeMail ); |
603 | } | 644 | } |
604 | } | 645 | } |
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index 8fdb07d..41e9a8c 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h | |||
@@ -1,53 +1,55 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class Attachment; | 13 | class Attachment; |
14 | struct mailimf_fields; | 14 | struct mailimf_fields; |
15 | struct mailimf_field; | 15 | struct mailimf_field; |
16 | struct mailimf_mailbox; | 16 | struct mailimf_mailbox; |
17 | struct mailmime; | 17 | struct mailmime; |
18 | struct mailimf_address_list; | 18 | struct mailimf_address_list; |
19 | 19 | ||
20 | class SMTPwrapper : public QObject | 20 | class SMTPwrapper : public QObject |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | 23 | ||
24 | public: | 24 | public: |
25 | SMTPwrapper( Settings *s ); | 25 | SMTPwrapper( Settings *s ); |
26 | virtual ~SMTPwrapper(){} | 26 | virtual ~SMTPwrapper(){} |
27 | void sendMail(const Mail& mail ); | 27 | void sendMail(const Mail& mail,bool later=false ); |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
31 | mailimf_fields *createImfFields(const Mail &mail ); | 31 | mailimf_fields *createImfFields(const Mail &mail ); |
32 | mailmime *createMimeMail(const Mail&mail ); | 32 | mailmime *createMimeMail(const Mail&mail ); |
33 | 33 | ||
34 | mailimf_address_list *parseAddresses(const QString&addr ); | 34 | mailimf_address_list *parseAddresses(const QString&addr ); |
35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
36 | mailmime *buildTxtPart(const QString&str ); | 36 | mailmime *buildTxtPart(const QString&str ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); | 37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); |
38 | void smtpSend( mailmime *mail ); | 38 | void smtpSend( mailmime *mail,bool later ); |
39 | mailimf_field *getField( mailimf_fields *fields, int type ); | 39 | mailimf_field *getField( mailimf_fields *fields, int type ); |
40 | clist *createRcptList( mailimf_fields *fields ); | 40 | clist *createRcptList( mailimf_fields *fields ); |
41 | char *getFrom( mailmime *mail ); | 41 | char *getFrom( mailmime *mail ); |
42 | SMTPaccount *getAccount(const QString&from ); | 42 | SMTPaccount *getAccount(const QString&from ); |
43 | void writeToFile(const QString&file, mailmime *mail ); | 43 | void writeToFile(const QString&file, mailmime *mail ); |
44 | void readFromFile(const QString&file, char **data, size_t *size ); | 44 | void readFromFile(const QString&file, char **data, size_t *size ); |
45 | void storeMail(char*mail, size_t length, const QString&box); | ||
45 | 46 | ||
46 | static QString mailsmtpError( int err ); | 47 | static QString mailsmtpError( int err ); |
47 | static QString getTmpFile(); | 48 | static QString getTmpFile(); |
48 | static void progress( size_t current, size_t maximum ); | 49 | static void progress( size_t current, size_t maximum ); |
49 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
51 | void storeMail(mailmime*mail, const QString&box); | ||
50 | Settings *settings; | 52 | Settings *settings; |
51 | }; | 53 | }; |
52 | 54 | ||
53 | #endif | 55 | #endif |