summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogress.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogressui.ui4
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp15
-rw-r--r--noncore/net/mail/sendmailprogress.cpp4
-rw-r--r--noncore/net/mail/sendmailprogressui.ui4
-rw-r--r--noncore/net/mail/smtpwrapper.cpp15
6 files changed, 32 insertions, 14 deletions
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
index 13ddd37..ef22750 100644
--- a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
+++ b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
@@ -1,48 +1,48 @@
1#include "sendmailprogress.h" 1#include "sendmailprogress.h"
2#include <qprogressbar.h> 2#include <qprogressbar.h>
3#include <qlabel.h> 3#include <qlabel.h>
4#include <qstring.h> 4#include <qstring.h>
5 5
6progressMailSend::progressMailSend(QWidget*parent, const char * name) 6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) 7 :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{ 8{
9} 9}
10 10
11progressMailSend::~progressMailSend() 11progressMailSend::~progressMailSend()
12{ 12{
13} 13}
14 14
15void progressMailSend::setMaxMails(unsigned int aMaxMails) 15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{ 16{
17 m_max_mail = aMaxMails; 17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails); 18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails(); 19 setMails();
20} 20}
21 21
22void progressMailSend::setCurrentMails(unsigned int aCurrent) 22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{ 23{
24 m_current_mail = aCurrent; 24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent); 25 allMailProgressBar->setProgress(aCurrent);
26 setMails(); 26 setMails();
27} 27}
28 28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) 29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{ 30{
31 m_current_single = aCurrent; 31 m_current_single = aCurrent;
32 m_max_single = aMax; 32 m_max_single = aMax;
33 setSingle(); 33 setSingle();
34} 34}
35 35
36void progressMailSend::setSingle() 36void progressMailSend::setSingle()
37{ 37{
38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); 38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text); 39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single); 40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single); 41 singleMailProgressBar->setProgress(m_current_single);
42} 42}
43 43
44void progressMailSend::setMails() 44void progressMailSend::setMails()
45{ 45{
46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); 46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
47 allMailLabel->setText(text); 47 allMailLabel->setText(text);
48} 48}
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
index b90b088..287ab5e 100644
--- a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
+++ b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
@@ -1,110 +1,110 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>progressMailSendUI</class> 2<class>progressMailSendUI</class>
3<widget> 3<widget>
4 <class>QDialog</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>progressMailSendUI</cstring> 7 <cstring>progressMailSendUI</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>316</width> 14 <width>221</width>
15 <height>266</height> 15 <height>127</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Sending mail</string> 20 <string>Sending mail</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <vbox> 28 <vbox>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>4</number> 31 <number>4</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QLabel</class> 38 <class>QLabel</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>singleMailLabel</cstring> 41 <cstring>singleMailLabel</cstring>
42 </property> 42 </property>
43 <property stdset="1"> 43 <property stdset="1">
44 <name>text</name> 44 <name>text</name>
45 <string>Progress of mail</string> 45 <string>Progress of mail</string>
46 </property> 46 </property>
47 <property stdset="1"> 47 <property stdset="1">
48 <name>alignment</name> 48 <name>alignment</name>
49 <set>AlignCenter</set> 49 <set>AlignCenter</set>
50 </property> 50 </property>
51 <property> 51 <property>
52 <name>hAlign</name> 52 <name>hAlign</name>
53 </property> 53 </property>
54 </widget> 54 </widget>
55 <widget> 55 <widget>
56 <class>QProgressBar</class> 56 <class>QProgressBar</class>
57 <property stdset="1"> 57 <property stdset="1">
58 <name>name</name> 58 <name>name</name>
59 <cstring>singleMailProgressBar</cstring> 59 <cstring>singleMailProgressBar</cstring>
60 </property> 60 </property>
61 </widget> 61 </widget>
62 <widget> 62 <widget>
63 <class>QLabel</class> 63 <class>QLabel</class>
64 <property stdset="1"> 64 <property stdset="1">
65 <name>name</name> 65 <name>name</name>
66 <cstring>allMailLabel</cstring> 66 <cstring>allMailLabel</cstring>
67 </property> 67 </property>
68 <property stdset="1"> 68 <property stdset="1">
69 <name>text</name> 69 <name>text</name>
70 <string>Sending mail</string> 70 <string>Sending mail</string>
71 </property> 71 </property>
72 <property stdset="1"> 72 <property stdset="1">
73 <name>alignment</name> 73 <name>alignment</name>
74 <set>AlignCenter</set> 74 <set>AlignCenter</set>
75 </property> 75 </property>
76 <property> 76 <property>
77 <name>hAlign</name> 77 <name>hAlign</name>
78 </property> 78 </property>
79 </widget> 79 </widget>
80 <widget> 80 <widget>
81 <class>QProgressBar</class> 81 <class>QProgressBar</class>
82 <property stdset="1"> 82 <property stdset="1">
83 <name>name</name> 83 <name>name</name>
84 <cstring>allMailProgressBar</cstring> 84 <cstring>allMailProgressBar</cstring>
85 </property> 85 </property>
86 </widget> 86 </widget>
87 <spacer> 87 <spacer>
88 <property> 88 <property>
89 <name>name</name> 89 <name>name</name>
90 <cstring>Spacer6</cstring> 90 <cstring>Spacer6</cstring>
91 </property> 91 </property>
92 <property stdset="1"> 92 <property stdset="1">
93 <name>orientation</name> 93 <name>orientation</name>
94 <enum>Vertical</enum> 94 <enum>Vertical</enum>
95 </property> 95 </property>
96 <property stdset="1"> 96 <property stdset="1">
97 <name>sizeType</name> 97 <name>sizeType</name>
98 <enum>Expanding</enum> 98 <enum>Expanding</enum>
99 </property> 99 </property>
100 <property> 100 <property>
101 <name>sizeHint</name> 101 <name>sizeHint</name>
102 <size> 102 <size>
103 <width>20</width> 103 <width>20</width>
104 <height>20</height> 104 <height>20</height>
105 </size> 105 </size>
106 </property> 106 </property>
107 </spacer> 107 </spacer>
108 </vbox> 108 </vbox>
109</widget> 109</widget>
110</UI> 110</UI>
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 53c0af5..770e2b8 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,728 +1,737 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9 9
10#include <libetpan/libetpan.h> 10#include <libetpan/libetpan.h>
11 11
12#include "smtpwrapper.h" 12#include "smtpwrapper.h"
13#include "mailwrapper.h" 13#include "mailwrapper.h"
14#include "mboxwrapper.h" 14#include "mboxwrapper.h"
15#include "logindialog.h" 15#include "logindialog.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17#include "defines.h" 17#include "defines.h"
18#include "sendmailprogress.h" 18#include "sendmailprogress.h"
19 19
20progressMailSend*SMTPwrapper::sendProgress = 0; 20progressMailSend*SMTPwrapper::sendProgress = 0;
21 21
22SMTPwrapper::SMTPwrapper( Settings *s ) 22SMTPwrapper::SMTPwrapper( Settings *s )
23 : QObject() 23 : QObject()
24{ 24{
25 settings = s; 25 settings = s;
26} 26}
27 27
28QString SMTPwrapper::mailsmtpError( int errnum ) 28QString SMTPwrapper::mailsmtpError( int errnum )
29{ 29{
30 switch ( errnum ) { 30 switch ( errnum ) {
31 case MAILSMTP_NO_ERROR: 31 case MAILSMTP_NO_ERROR:
32 return tr( "No error" ); 32 return tr( "No error" );
33 case MAILSMTP_ERROR_UNEXPECTED_CODE: 33 case MAILSMTP_ERROR_UNEXPECTED_CODE:
34 return tr( "Unexpected error code" ); 34 return tr( "Unexpected error code" );
35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
36 return tr( "Service not available" ); 36 return tr( "Service not available" );
37 case MAILSMTP_ERROR_STREAM: 37 case MAILSMTP_ERROR_STREAM:
38 return tr( "Stream error" ); 38 return tr( "Stream error" );
39 case MAILSMTP_ERROR_HOSTNAME: 39 case MAILSMTP_ERROR_HOSTNAME:
40 return tr( "gethostname() failed" ); 40 return tr( "gethostname() failed" );
41 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 41 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
42 return tr( "Not implemented" ); 42 return tr( "Not implemented" );
43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
44 return tr( "Error, action not taken" ); 44 return tr( "Error, action not taken" );
45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
46 return tr( "Data exceeds storage allocation" ); 46 return tr( "Data exceeds storage allocation" );
47 case MAILSMTP_ERROR_IN_PROCESSING: 47 case MAILSMTP_ERROR_IN_PROCESSING:
48 return tr( "Error in processing" ); 48 return tr( "Error in processing" );
49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
50 // return tr( "Insufficient system storage" ); 50 // return tr( "Insufficient system storage" );
51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
52 return tr( "Mailbox unavailable" ); 52 return tr( "Mailbox unavailable" );
53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
54 return tr( "Mailbox name not allowed" ); 54 return tr( "Mailbox name not allowed" );
55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
56 return tr( "Bad command sequence" ); 56 return tr( "Bad command sequence" );
57 case MAILSMTP_ERROR_USER_NOT_LOCAL: 57 case MAILSMTP_ERROR_USER_NOT_LOCAL:
58 return tr( "User not local" ); 58 return tr( "User not local" );
59 case MAILSMTP_ERROR_TRANSACTION_FAILED: 59 case MAILSMTP_ERROR_TRANSACTION_FAILED:
60 return tr( "Transaction failed" ); 60 return tr( "Transaction failed" );
61 case MAILSMTP_ERROR_MEMORY: 61 case MAILSMTP_ERROR_MEMORY:
62 return tr( "Memory error" ); 62 return tr( "Memory error" );
63 case MAILSMTP_ERROR_CONNECTION_REFUSED: 63 case MAILSMTP_ERROR_CONNECTION_REFUSED:
64 return tr( "Connection refused" ); 64 return tr( "Connection refused" );
65 default: 65 default:
66 return tr( "Unknown error code" ); 66 return tr( "Unknown error code" );
67 } 67 }
68} 68}
69 69
70mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) 70mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
71{ 71{
72 return mailimf_mailbox_new( strdup( name.latin1() ), 72 return mailimf_mailbox_new( strdup( name.latin1() ),
73 strdup( mail.latin1() ) ); 73 strdup( mail.latin1() ) );
74} 74}
75 75
76mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) 76mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
77{ 77{
78 mailimf_address_list *addresses; 78 mailimf_address_list *addresses;
79 79
80 if ( addr.isEmpty() ) return NULL; 80 if ( addr.isEmpty() ) return NULL;
81 81
82 addresses = mailimf_address_list_new_empty(); 82 addresses = mailimf_address_list_new_empty();
83 83
84 QStringList list = QStringList::split( ',', addr ); 84 QStringList list = QStringList::split( ',', addr );
85 QStringList::Iterator it; 85 QStringList::Iterator it;
86 for ( it = list.begin(); it != list.end(); it++ ) { 86 for ( it = list.begin(); it != list.end(); it++ ) {
87 char *str = strdup( (*it).latin1() ); 87 char *str = strdup( (*it).latin1() );
88 int err = mailimf_address_list_add_parse( addresses, str ); 88 int err = mailimf_address_list_add_parse( addresses, str );
89 if ( err != MAILIMF_NO_ERROR ) { 89 if ( err != MAILIMF_NO_ERROR ) {
90 qDebug( "Error parsing" ); 90 qDebug( "Error parsing" );
91 qDebug( *it ); 91 qDebug( *it );
92 free( str ); 92 free( str );
93 } else { 93 } else {
94 qDebug( "Parse success! :)" ); 94 qDebug( "Parse success! :)" );
95 } 95 }
96 } 96 }
97 97
98 return addresses; 98 return addresses;
99} 99}
100 100
101mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 101mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
102{ 102{
103 mailimf_fields *fields; 103 mailimf_fields *fields;
104 mailimf_field *xmailer; 104 mailimf_field *xmailer;
105 mailimf_mailbox *sender, *fromBox; 105 mailimf_mailbox *sender, *fromBox;
106 mailimf_mailbox_list *from; 106 mailimf_mailbox_list *from;
107 mailimf_address_list *to, *cc, *bcc, *reply; 107 mailimf_address_list *to, *cc, *bcc, *reply;
108 char *subject = strdup( mail.getSubject().latin1() ); 108 char *subject = strdup( mail.getSubject().latin1() );
109 int err; 109 int err;
110 110
111 sender = newMailbox( mail.getName(), mail.getMail() ); 111 sender = newMailbox( mail.getName(), mail.getMail() );
112 if ( sender == NULL ) goto err_free; 112 if ( sender == NULL ) goto err_free;
113 113
114 fromBox = newMailbox( mail.getName(), mail.getMail() ); 114 fromBox = newMailbox( mail.getName(), mail.getMail() );
115 if ( fromBox == NULL ) goto err_free_sender; 115 if ( fromBox == NULL ) goto err_free_sender;
116 116
117 from = mailimf_mailbox_list_new_empty(); 117 from = mailimf_mailbox_list_new_empty();
118 if ( from == NULL ) goto err_free_fromBox; 118 if ( from == NULL ) goto err_free_fromBox;
119 119
120 err = mailimf_mailbox_list_add( from, fromBox ); 120 err = mailimf_mailbox_list_add( from, fromBox );
121 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 121 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
122 122
123 to = parseAddresses( mail.getTo() ); 123 to = parseAddresses( mail.getTo() );
124 if ( to == NULL ) goto err_free_from; 124 if ( to == NULL ) goto err_free_from;
125 125
126 cc = parseAddresses( mail.getCC() ); 126 cc = parseAddresses( mail.getCC() );
127 bcc = parseAddresses( mail.getBCC() ); 127 bcc = parseAddresses( mail.getBCC() );
128 reply = parseAddresses( mail.getReply() ); 128 reply = parseAddresses( mail.getReply() );
129 129
130 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 130 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
131 NULL, NULL, subject ); 131 NULL, NULL, subject );
132 if ( fields == NULL ) goto err_free_reply; 132 if ( fields == NULL ) goto err_free_reply;
133 133
134 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 134 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
135 strdup( USER_AGENT ) ); 135 strdup( USER_AGENT ) );
136 if ( xmailer == NULL ) goto err_free_fields; 136 if ( xmailer == NULL ) goto err_free_fields;
137 137
138 err = mailimf_fields_add( fields, xmailer ); 138 err = mailimf_fields_add( fields, xmailer );
139 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 139 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
140 140
141 return fields; // Success :) 141 return fields; // Success :)
142 142
143err_free_xmailer: 143err_free_xmailer:
144 mailimf_field_free( xmailer ); 144 mailimf_field_free( xmailer );
145err_free_fields: 145err_free_fields:
146 mailimf_fields_free( fields ); 146 mailimf_fields_free( fields );
147err_free_reply: 147err_free_reply:
148 mailimf_address_list_free( reply ); 148 mailimf_address_list_free( reply );
149 mailimf_address_list_free( bcc ); 149 mailimf_address_list_free( bcc );
150 mailimf_address_list_free( cc ); 150 mailimf_address_list_free( cc );
151 mailimf_address_list_free( to ); 151 mailimf_address_list_free( to );
152err_free_from: 152err_free_from:
153 mailimf_mailbox_list_free( from ); 153 mailimf_mailbox_list_free( from );
154err_free_fromBox: 154err_free_fromBox:
155 mailimf_mailbox_free( fromBox ); 155 mailimf_mailbox_free( fromBox );
156err_free_sender: 156err_free_sender:
157 mailimf_mailbox_free( sender ); 157 mailimf_mailbox_free( sender );
158err_free: 158err_free:
159 free( subject ); 159 free( subject );
160 qDebug( "createImfFields - error" ); 160 qDebug( "createImfFields - error" );
161 161
162 return NULL; // Error :( 162 return NULL; // Error :(
163} 163}
164 164
165mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 165mailmime *SMTPwrapper::buildTxtPart(const QString&str )
166{ 166{
167 mailmime *txtPart; 167 mailmime *txtPart;
168 mailmime_fields *fields; 168 mailmime_fields *fields;
169 mailmime_content *content; 169 mailmime_content *content;
170 mailmime_parameter *param; 170 mailmime_parameter *param;
171 char *txt = strdup( str.latin1() ); 171 char *txt = strdup( str.latin1() );
172 int err; 172 int err;
173 173
174 param = mailmime_parameter_new( strdup( "charset" ), 174 param = mailmime_parameter_new( strdup( "charset" ),
175 strdup( "iso-8859-1" ) ); 175 strdup( "iso-8859-1" ) );
176 if ( param == NULL ) goto err_free; 176 if ( param == NULL ) goto err_free;
177 177
178 content = mailmime_content_new_with_str( "text/plain" ); 178 content = mailmime_content_new_with_str( "text/plain" );
179 if ( content == NULL ) goto err_free_param; 179 if ( content == NULL ) goto err_free_param;
180 180
181 err = clist_append( content->ct_parameters, param ); 181 err = clist_append( content->ct_parameters, param );
182 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 182 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
183 183
184 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 184 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
185 if ( fields == NULL ) goto err_free_content; 185 if ( fields == NULL ) goto err_free_content;
186 186
187 txtPart = mailmime_new_empty( content, fields ); 187 txtPart = mailmime_new_empty( content, fields );
188 if ( txtPart == NULL ) goto err_free_fields; 188 if ( txtPart == NULL ) goto err_free_fields;
189 189
190 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 190 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
191 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 191 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
192 192
193 return txtPart; // Success :) 193 return txtPart; // Success :)
194 194
195err_free_txtPart: 195err_free_txtPart:
196 mailmime_free( txtPart ); 196 mailmime_free( txtPart );
197err_free_fields: 197err_free_fields:
198 mailmime_fields_free( fields ); 198 mailmime_fields_free( fields );
199err_free_content: 199err_free_content:
200 mailmime_content_free( content ); 200 mailmime_content_free( content );
201err_free_param: 201err_free_param:
202 mailmime_parameter_free( param ); 202 mailmime_parameter_free( param );
203err_free: 203err_free:
204 free( txt ); 204 free( txt );
205 qDebug( "buildTxtPart - error" ); 205 qDebug( "buildTxtPart - error" );
206 206
207 return NULL; // Error :( 207 return NULL; // Error :(
208} 208}
209 209
210mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 210mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
211{ 211{
212 mailmime * filePart = 0; 212 mailmime * filePart = 0;
213 mailmime_fields * fields = 0; 213 mailmime_fields * fields = 0;
214 mailmime_content * content = 0; 214 mailmime_content * content = 0;
215 mailmime_parameter * param = 0; 215 mailmime_parameter * param = 0;
216 char*name = 0; 216 char*name = 0;
217 char*file = 0; 217 char*file = 0;
218 int err; 218 int err;
219 219
220 int pos = filename.findRev( '/' ); 220 int pos = filename.findRev( '/' );
221 221
222 if (filename.length()>0) { 222 if (filename.length()>0) {
223 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 223 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
224 name = strdup( tmp.latin1() ); // just filename 224 name = strdup( tmp.latin1() ); // just filename
225 file = strdup( filename.latin1() ); // full name with path 225 file = strdup( filename.latin1() ); // full name with path
226 } 226 }
227 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 227 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
228 228
229 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 229 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
230 int mechanism = MAILMIME_MECHANISM_BASE64; 230 int mechanism = MAILMIME_MECHANISM_BASE64;
231 231
232 if ( mimetype.startsWith( "text/" ) ) { 232 if ( mimetype.startsWith( "text/" ) ) {
233 param = mailmime_parameter_new( strdup( "charset" ), 233 param = mailmime_parameter_new( strdup( "charset" ),
234 strdup( "iso-8859-1" ) ); 234 strdup( "iso-8859-1" ) );
235 disptype = MAILMIME_DISPOSITION_TYPE_INLINE; 235 disptype = MAILMIME_DISPOSITION_TYPE_INLINE;
236 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 236 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
237 } 237 }
238 238
239 fields = mailmime_fields_new_filename( 239 fields = mailmime_fields_new_filename(
240 disptype, name, 240 disptype, name,
241 mechanism ); 241 mechanism );
242 content = mailmime_content_new_with_str( mime ); 242 content = mailmime_content_new_with_str( mime );
243 if (content!=0 && fields != 0) { 243 if (content!=0 && fields != 0) {
244 if (param) { 244 if (param) {
245 clist_append(content->ct_parameters,param); 245 clist_append(content->ct_parameters,param);
246 param = 0; 246 param = 0;
247 } 247 }
248 if (filename.length()>0) { 248 if (filename.length()>0) {
249 QFileInfo f(filename); 249 QFileInfo f(filename);
250 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 250 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
251 clist_append(content->ct_parameters,param); 251 clist_append(content->ct_parameters,param);
252 param = 0; 252 param = 0;
253 } 253 }
254 filePart = mailmime_new_empty( content, fields ); 254 filePart = mailmime_new_empty( content, fields );
255 } 255 }
256 if (filePart) { 256 if (filePart) {
257 if (filename.length()>0) { 257 if (filename.length()>0) {
258 err = mailmime_set_body_file( filePart, file ); 258 err = mailmime_set_body_file( filePart, file );
259 } else { 259 } else {
260 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); 260 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length());
261 } 261 }
262 if (err != MAILIMF_NO_ERROR) { 262 if (err != MAILIMF_NO_ERROR) {
263 qDebug("Error setting body with file %s",file); 263 qDebug("Error setting body with file %s",file);
264 mailmime_free( filePart ); 264 mailmime_free( filePart );
265 filePart = 0; 265 filePart = 0;
266 } 266 }
267 } 267 }
268 268
269 if (!filePart) { 269 if (!filePart) {
270 if ( param != NULL ) { 270 if ( param != NULL ) {
271 mailmime_parameter_free( param ); 271 mailmime_parameter_free( param );
272 } 272 }
273 if (content) { 273 if (content) {
274 mailmime_content_free( content ); 274 mailmime_content_free( content );
275 } else { 275 } else {
276 if (mime) { 276 if (mime) {
277 free( mime ); 277 free( mime );
278 } 278 }
279 } 279 }
280 if (fields) { 280 if (fields) {
281 mailmime_fields_free( fields ); 281 mailmime_fields_free( fields );
282 } else { 282 } else {
283 if (name) { 283 if (name) {
284 free( name ); 284 free( name );
285 } 285 }
286 if (file) { 286 if (file) {
287 free( file ); 287 free( file );
288 } 288 }
289 } 289 }
290 } 290 }
291 return filePart; // Success :) 291 return filePart; // Success :)
292 292
293} 293}
294 294
295void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) 295void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
296{ 296{
297 const Attachment *it; 297 const Attachment *it;
298 unsigned int count = files.count(); 298 unsigned int count = files.count();
299 qDebug("List contains %i values",count); 299 qDebug("List contains %i values",count);
300 for ( unsigned int i = 0; i < count; ++i ) { 300 for ( unsigned int i = 0; i < count; ++i ) {
301 qDebug( "Adding file" ); 301 qDebug( "Adding file" );
302 mailmime *filePart; 302 mailmime *filePart;
303 int err; 303 int err;
304 it = ((QList<Attachment>)files).at(i); 304 it = ((QList<Attachment>)files).at(i);
305 305
306 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 306 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
307 if ( filePart == NULL ) { 307 if ( filePart == NULL ) {
308 qDebug( "addFileParts: error adding file:" ); 308 qDebug( "addFileParts: error adding file:" );
309 qDebug( it->getFileName() ); 309 qDebug( it->getFileName() );
310 continue; 310 continue;
311 } 311 }
312 err = mailmime_smart_add_part( message, filePart ); 312 err = mailmime_smart_add_part( message, filePart );
313 if ( err != MAILIMF_NO_ERROR ) { 313 if ( err != MAILIMF_NO_ERROR ) {
314 mailmime_free( filePart ); 314 mailmime_free( filePart );
315 qDebug("error smart add"); 315 qDebug("error smart add");
316 } 316 }
317 } 317 }
318} 318}
319 319
320mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) 320mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
321{ 321{
322 mailmime *message, *txtPart; 322 mailmime *message, *txtPart;
323 mailimf_fields *fields; 323 mailimf_fields *fields;
324 int err; 324 int err;
325 325
326 fields = createImfFields( mail ); 326 fields = createImfFields( mail );
327 if ( fields == NULL ) goto err_free; 327 if ( fields == NULL ) goto err_free;
328 328
329 message = mailmime_new_message_data( NULL ); 329 message = mailmime_new_message_data( NULL );
330 if ( message == NULL ) goto err_free_fields; 330 if ( message == NULL ) goto err_free_fields;
331 331
332 mailmime_set_imf_fields( message, fields ); 332 mailmime_set_imf_fields( message, fields );
333 333
334 if (mail.getAttachments().count()==0) { 334 if (mail.getAttachments().count()==0) {
335 txtPart = buildTxtPart( mail.getMessage() ); 335 txtPart = buildTxtPart( mail.getMessage() );
336 } else { 336 } else {
337 txtPart = buildFilePart("","text/plain",mail.getMessage()); 337 txtPart = buildFilePart("","text/plain",mail.getMessage());
338 } 338 }
339 if ( txtPart == NULL ) goto err_free_message; 339 if ( txtPart == NULL ) goto err_free_message;
340 340
341 err = mailmime_smart_add_part( message, txtPart ); 341 err = mailmime_smart_add_part( message, txtPart );
342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
343 343
344 addFileParts( message, mail.getAttachments() ); 344 addFileParts( message, mail.getAttachments() );
345 345
346 return message; // Success :) 346 return message; // Success :)
347 347
348err_free_txtPart: 348err_free_txtPart:
349 mailmime_free( txtPart ); 349 mailmime_free( txtPart );
350err_free_message: 350err_free_message:
351 mailmime_free( message ); 351 mailmime_free( message );
352err_free_fields: 352err_free_fields:
353 mailimf_fields_free( fields ); 353 mailimf_fields_free( fields );
354err_free: 354err_free:
355 qDebug( "createMimeMail: error" ); 355 qDebug( "createMimeMail: error" );
356 356
357 return NULL; // Error :( 357 return NULL; // Error :(
358} 358}
359 359
360mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) 360mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
361{ 361{
362 mailimf_field *field; 362 mailimf_field *field;
363 clistiter *it; 363 clistiter *it;
364 364
365 it = clist_begin( fields->fld_list ); 365 it = clist_begin( fields->fld_list );
366 while ( it ) { 366 while ( it ) {
367 field = (mailimf_field *) it->data; 367 field = (mailimf_field *) it->data;
368 if ( field->fld_type == type ) { 368 if ( field->fld_type == type ) {
369 return field; 369 return field;
370 } 370 }
371 it = it->next; 371 it = it->next;
372 } 372 }
373 373
374 return NULL; 374 return NULL;
375} 375}
376 376
377void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) 377void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
378{ 378{
379 clistiter *it, *it2; 379 clistiter *it, *it2;
380 380
381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
382 mailimf_address *addr; 382 mailimf_address *addr;
383 addr = (mailimf_address *) it->data; 383 addr = (mailimf_address *) it->data;
384 384
385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
390 mailimf_mailbox *mbox; 390 mailimf_mailbox *mbox;
391 mbox = (mailimf_mailbox *) it2->data; 391 mbox = (mailimf_mailbox *) it2->data;
392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
393 } 393 }
394 } 394 }
395 } 395 }
396} 396}
397 397
398clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) 398clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
399{ 399{
400 clist *rcptList; 400 clist *rcptList;
401 mailimf_field *field; 401 mailimf_field *field;
402 402
403 rcptList = esmtp_address_list_new(); 403 rcptList = esmtp_address_list_new();
404 404
405 field = getField( fields, MAILIMF_FIELD_TO ); 405 field = getField( fields, MAILIMF_FIELD_TO );
406 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 406 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
407 && field->fld_data.fld_to->to_addr_list ) { 407 && field->fld_data.fld_to->to_addr_list ) {
408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
409 } 409 }
410 410
411 field = getField( fields, MAILIMF_FIELD_CC ); 411 field = getField( fields, MAILIMF_FIELD_CC );
412 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 412 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
413 && field->fld_data.fld_cc->cc_addr_list ) { 413 && field->fld_data.fld_cc->cc_addr_list ) {
414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
415 } 415 }
416 416
417 field = getField( fields, MAILIMF_FIELD_BCC ); 417 field = getField( fields, MAILIMF_FIELD_BCC );
418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
419 && field->fld_data.fld_bcc->bcc_addr_list ) { 419 && field->fld_data.fld_bcc->bcc_addr_list ) {
420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
421 } 421 }
422 422
423 return rcptList; 423 return rcptList;
424} 424}
425 425
426char *SMTPwrapper::getFrom( mailimf_field *ffrom) 426char *SMTPwrapper::getFrom( mailimf_field *ffrom)
427{ 427{
428 char *from = NULL; 428 char *from = NULL;
429 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 429 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
430 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 430 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
431 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 431 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
432 clistiter *it; 432 clistiter *it;
433 for ( it = clist_begin( cl ); it; it = it->next ) { 433 for ( it = clist_begin( cl ); it; it = it->next ) {
434 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 434 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
435 from = strdup( mb->mb_addr_spec ); 435 from = strdup( mb->mb_addr_spec );
436 } 436 }
437 } 437 }
438 438
439 return from; 439 return from;
440} 440}
441 441
442char *SMTPwrapper::getFrom( mailmime *mail ) 442char *SMTPwrapper::getFrom( mailmime *mail )
443{ 443{
444 mailimf_field *ffrom = 0; 444 mailimf_field *ffrom = 0;
445 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 445 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
446 return getFrom(ffrom); 446 return getFrom(ffrom);
447} 447}
448 448
449SMTPaccount *SMTPwrapper::getAccount(const QString&name ) 449SMTPaccount *SMTPwrapper::getAccount(const QString&name )
450{ 450{
451 SMTPaccount *smtp; 451 SMTPaccount *smtp;
452 452
453 QList<Account> list = settings->getAccounts(); 453 QList<Account> list = settings->getAccounts();
454 Account *it; 454 Account *it;
455 for ( it = list.first(); it; it = list.next() ) { 455 for ( it = list.first(); it; it = list.next() ) {
456 if ( it->getType().compare( "SMTP" ) == 0 ) { 456 if ( it->getType().compare( "SMTP" ) == 0 ) {
457 smtp = static_cast<SMTPaccount *>(it); 457 smtp = static_cast<SMTPaccount *>(it);
458 if ( smtp->getName()== name ) { 458 if ( smtp->getName()== name ) {
459 qDebug( "SMTPaccount found for" ); 459 qDebug( "SMTPaccount found for" );
460 qDebug( name ); 460 qDebug( name );
461 return smtp; 461 return smtp;
462 } 462 }
463 } 463 }
464 } 464 }
465 465
466 return NULL; 466 return NULL;
467} 467}
468 468
469QString SMTPwrapper::getTmpFile() { 469QString SMTPwrapper::getTmpFile() {
470 int num = 0; 470 int num = 0;
471 QString unique; 471 QString unique;
472 472
473 QDir dir( "/tmp" ); 473 QDir dir( "/tmp" );
474 474
475 QStringList list = dir.entryList( "opiemail-tmp-*" ); 475 QStringList list = dir.entryList( "opiemail-tmp-*" );
476 476
477 do { 477 do {
478 unique.setNum( num++ ); 478 unique.setNum( num++ );
479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
480 480
481 return "/tmp/opiemail-tmp-" + unique; 481 return "/tmp/opiemail-tmp-" + unique;
482} 482}
483 483
484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) 484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
485{ 485{
486 FILE *f; 486 FILE *f;
487 int err, col = 0; 487 int err, col = 0;
488 488
489 f = fopen( file.latin1(), "w" ); 489 f = fopen( file.latin1(), "w" );
490 if ( f == NULL ) { 490 if ( f == NULL ) {
491 qDebug( "writeToFile: error opening file" ); 491 qDebug( "writeToFile: error opening file" );
492 return; 492 return;
493 } 493 }
494 494
495 err = mailmime_write( f, &col, mail ); 495 err = mailmime_write( f, &col, mail );
496 if ( err != MAILIMF_NO_ERROR ) { 496 if ( err != MAILIMF_NO_ERROR ) {
497 fclose( f ); 497 fclose( f );
498 qDebug( "writeToFile: error writing mailmime" ); 498 qDebug( "writeToFile: error writing mailmime" );
499 return; 499 return;
500 } 500 }
501 501
502 fclose( f ); 502 fclose( f );
503} 503}
504 504
505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
506{ 506{
507 507
508 QFile msg_cache(file); 508 QFile msg_cache(file);
509 QString msg = ""; 509 QString msg = "";
510 msg_cache.open(IO_ReadOnly); 510 msg_cache.open(IO_ReadOnly);
511 char*message = new char[4096]; 511 char*message = new char[4096];
512 memset(message,0,4096); 512 memset(message,0,4096);
513 while (msg_cache.readBlock(message,4095)>0) { 513 while (msg_cache.readBlock(message,4095)>0) {
514 msg+=message; 514 msg+=message;
515 memset(message,0,4096); 515 memset(message,0,4096);
516 } 516 }
517 delete message; 517 delete message;
518 *data = (char*)malloc(msg.length()+1*sizeof(char)); 518 *data = (char*)malloc(msg.length()+1*sizeof(char));
519 memset(*data,0,msg.length()+1); 519 memset(*data,0,msg.length()+1);
520 memcpy(*data,msg.ascii(),msg.length()); 520 memcpy(*data,msg.ascii(),msg.length());
521 *size=msg.length(); 521 *size=msg.length();
522} 522}
523 523
524void SMTPwrapper::progress( size_t current, size_t maximum ) 524void SMTPwrapper::progress( size_t current, size_t maximum )
525{ 525{
526 if (SMTPwrapper::sendProgress) { 526 if (SMTPwrapper::sendProgress) {
527 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 527 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
528 qDebug("%u of %u",current,maximum); 528 qApp->processEvents();
529 } 529 }
530} 530}
531 531
532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
533{ 533{
534 if (!mail) return; 534 if (!mail) return;
535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
536 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 536 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
537 wrap->storeMessage(mail,length,box); 537 wrap->storeMessage(mail,length,box);
538 delete wrap; 538 delete wrap;
539} 539}
540 540
541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
542{ 542{
543 clist *rcpts = 0; 543 clist *rcpts = 0;
544 char *from, *data; 544 char *from, *data;
545 size_t size; 545 size_t size;
546 546
547 if ( smtp == NULL ) { 547 if ( smtp == NULL ) {
548 return; 548 return;
549 } 549 }
550 from = data = 0; 550 from = data = 0;
551 551
552 QString file = getTmpFile(); 552 QString file = getTmpFile();
553 writeToFile( file, mail ); 553 writeToFile( file, mail );
554 readFromFile( file, &data, &size ); 554 readFromFile( file, &data, &size );
555 QFile f( file ); 555 QFile f( file );
556 f.remove(); 556 f.remove();
557 557
558 if (later) { 558 if (later) {
559 storeMail(data,size,"Outgoing"); 559 storeMail(data,size,"Outgoing");
560 if (data) free( data ); 560 if (data) free( data );
561 return; 561 return;
562 } 562 }
563 from = getFrom( mail ); 563 from = getFrom( mail );
564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
565 smtpSend(from,rcpts,data,size,smtp); 565 smtpSend(from,rcpts,data,size,smtp);
566} 566}
567 567
568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
569{ 569{
570 char *server, *user, *pass; 570 char *server, *user, *pass;
571 bool ssl; 571 bool ssl;
572 uint16_t port; 572 uint16_t port;
573 mailsmtp *session; 573 mailsmtp *session;
574 int err,result; 574 int err,result;
575 575
576 result = 1; 576 result = 1;
577 server = user = pass = 0; 577 server = user = pass = 0;
578 server = strdup( smtp->getServer().latin1() ); 578 server = strdup( smtp->getServer().latin1() );
579 ssl = smtp->getSSL(); 579 ssl = smtp->getSSL();
580 port = smtp->getPort().toUInt(); 580 port = smtp->getPort().toUInt();
581 581
582 session = mailsmtp_new( 20, &progress ); 582 session = mailsmtp_new( 20, &progress );
583 if ( session == NULL ) goto free_mem; 583 if ( session == NULL ) goto free_mem;
584 584
585 qDebug( "Servername %s at port %i", server, port ); 585 qDebug( "Servername %s at port %i", server, port );
586 if ( ssl ) { 586 if ( ssl ) {
587 qDebug( "SSL session" ); 587 qDebug( "SSL session" );
588 err = mailsmtp_ssl_connect( session, server, port ); 588 err = mailsmtp_ssl_connect( session, server, port );
589 } else { 589 } else {
590 qDebug( "No SSL session" ); 590 qDebug( "No SSL session" );
591 err = mailsmtp_socket_connect( session, server, port ); 591 err = mailsmtp_socket_connect( session, server, port );
592 } 592 }
593 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} 593 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
594 594
595 err = mailsmtp_init( session ); 595 err = mailsmtp_init( session );
596 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 596 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
597 597
598 qDebug( "INIT OK" ); 598 qDebug( "INIT OK" );
599 599
600 if ( smtp->getLogin() ) { 600 if ( smtp->getLogin() ) {
601 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 601 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
602 // get'em 602 // get'em
603 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 603 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
604 login.show(); 604 login.show();
605 if ( QDialog::Accepted == login.exec() ) { 605 if ( QDialog::Accepted == login.exec() ) {
606 // ok 606 // ok
607 user = strdup( login.getUser().latin1() ); 607 user = strdup( login.getUser().latin1() );
608 pass = strdup( login.getPassword().latin1() ); 608 pass = strdup( login.getPassword().latin1() );
609 } else { 609 } else {
610 result = 0; goto free_con_session; 610 result = 0; goto free_con_session;
611 } 611 }
612 } else { 612 } else {
613 user = strdup( smtp->getUser().latin1() ); 613 user = strdup( smtp->getUser().latin1() );
614 pass = strdup( smtp->getPassword().latin1() ); 614 pass = strdup( smtp->getPassword().latin1() );
615 } 615 }
616 qDebug( "session->auth: %i", session->auth); 616 qDebug( "session->auth: %i", session->auth);
617 err = mailsmtp_auth( session, user, pass ); 617 err = mailsmtp_auth( session, user, pass );
618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
619 qDebug( "Done auth!" ); 619 qDebug( "Done auth!" );
620 } 620 }
621 621
622 err = mailsmtp_send( session, from, rcpts, data, size ); 622 err = mailsmtp_send( session, from, rcpts, data, size );
623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
624 624
625 qDebug( "Mail sent." ); 625 qDebug( "Mail sent." );
626 storeMail(data,size,"Sent"); 626 storeMail(data,size,"Sent");
627 627
628free_con_session: 628free_con_session:
629 mailsmtp_quit( session ); 629 mailsmtp_quit( session );
630free_mem_session: 630free_mem_session:
631 mailsmtp_free( session ); 631 mailsmtp_free( session );
632free_mem: 632free_mem:
633 if (rcpts) smtp_address_list_free( rcpts ); 633 if (rcpts) smtp_address_list_free( rcpts );
634 if (data) free( data ); 634 if (data) free( data );
635 if (server) free( server ); 635 if (server) free( server );
636 if (from) free( from ); 636 if (from) free( from );
637 if ( smtp->getLogin() ) { 637 if ( smtp->getLogin() ) {
638 free( user ); 638 free( user );
639 free( pass ); 639 free( pass );
640 } 640 }
641 return result; 641 return result;
642} 642}
643 643
644void SMTPwrapper::sendMail(const Mail&mail,bool later ) 644void SMTPwrapper::sendMail(const Mail&mail,bool later )
645{ 645{
646 mailmime * mimeMail; 646 mailmime * mimeMail;
647 647
648 SMTPaccount *smtp = getAccount(mail.getName()); 648 SMTPaccount *smtp = getAccount(mail.getName());
649 649
650 mimeMail = createMimeMail(mail ); 650 mimeMail = createMimeMail(mail );
651 if ( mimeMail == NULL ) { 651 if ( mimeMail == NULL ) {
652 qDebug( "sendMail: error creating mime mail" ); 652 qDebug( "sendMail: error creating mime mail" );
653 } else { 653 } else {
654 sendProgress = new progressMailSend(); 654 sendProgress = new progressMailSend();
655 sendProgress->showMaximized(); 655// sendProgress->showMaximized();
656 sendProgress->show(); 656 sendProgress->show();
657 qApp->processEvents(10); 657 sendProgress->setMaxMails(1);
658 smtpSend( mimeMail,later,smtp); 658 smtpSend( mimeMail,later,smtp);
659 mailmime_free( mimeMail ); 659 mailmime_free( mimeMail );
660 qDebug("Clean up done"); 660 qDebug("Clean up done");
661 sendProgress->hide(); 661 sendProgress->hide();
662 delete sendProgress; 662 delete sendProgress;
663 sendProgress = 0; 663 sendProgress = 0;
664 } 664 }
665} 665}
666 666
667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
668{ 668{
669 char*data = 0; 669 char*data = 0;
670 size_t length = 0; 670 size_t length = 0;
671 size_t curTok = 0; 671 size_t curTok = 0;
672 mailimf_fields *fields = 0; 672 mailimf_fields *fields = 0;
673 mailimf_field*ffrom = 0; 673 mailimf_field*ffrom = 0;
674 clist *rcpts = 0; 674 clist *rcpts = 0;
675 char*from = 0; 675 char*from = 0;
676 676
677 wrap->fetchRawBody(*which,&data,&length); 677 wrap->fetchRawBody(*which,&data,&length);
678 if (!data) return 0; 678 if (!data) return 0;
679 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 679 int err = mailimf_fields_parse( data, length, &curTok, &fields );
680 if (err != MAILIMF_NO_ERROR) { 680 if (err != MAILIMF_NO_ERROR) {
681 free(data); 681 free(data);
682 delete wrap; 682 delete wrap;
683 return 0; 683 return 0;
684 } 684 }
685 685
686 rcpts = createRcptList( fields ); 686 rcpts = createRcptList( fields );
687 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 687 ffrom = getField(fields, MAILIMF_FIELD_FROM );
688 from = getFrom(ffrom); 688 from = getFrom(ffrom);
689 689
690 qDebug("Size: %i vs. %i",length,strlen(data)); 690 qDebug("Size: %i vs. %i",length,strlen(data));
691 if (rcpts && from) { 691 if (rcpts && from) {
692 return smtpSend(from,rcpts,data,strlen(data),smtp ); 692 return smtpSend(from,rcpts,data,strlen(data),smtp );
693 } 693 }
694 return 0; 694 return 0;
695} 695}
696 696
697/* this is a special fun */ 697/* this is a special fun */
698void SMTPwrapper::flushOutbox(SMTPaccount*smtp) 698void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
699{ 699{
700 if (!smtp) return; 700 if (!smtp) return;
701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
702 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 702 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
703 if (!wrap) { 703 if (!wrap) {
704 qDebug("memory error"); 704 qDebug("memory error");
705 return; 705 return;
706 } 706 }
707 QList<RecMail> mailsToSend; 707 QList<RecMail> mailsToSend;
708 QList<RecMail> mailsToRemove; 708 QList<RecMail> mailsToRemove;
709 QString mbox("Outgoing"); 709 QString mbox("Outgoing");
710 wrap->listMessages(mbox,mailsToSend); 710 wrap->listMessages(mbox,mailsToSend);
711 if (mailsToSend.count()==0) { 711 if (mailsToSend.count()==0) {
712 delete wrap; 712 delete wrap;
713 return; 713 return;
714 } 714 }
715 mailsToSend.setAutoDelete(false); 715 mailsToSend.setAutoDelete(false);
716 sendProgress = new progressMailSend();
717// sendProgress->showMaximized();
718 sendProgress->show();
719 sendProgress->setMaxMails(mailsToSend.count());
720
716 while (mailsToSend.count()>0) { 721 while (mailsToSend.count()>0) {
717 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 722 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
718 QMessageBox::critical(0,tr("Error sending mail"), 723 QMessageBox::critical(0,tr("Error sending mail"),
719 tr("Error sending queued mail - breaking")); 724 tr("Error sending queued mail - breaking"));
720 break; 725 break;
721 } 726 }
722 mailsToRemove.append(mailsToSend.at(0)); 727 mailsToRemove.append(mailsToSend.at(0));
723 mailsToSend.removeFirst(); 728 mailsToSend.removeFirst();
729 sendProgress->setCurrentMails(mailsToRemove.count());
724 } 730 }
731 sendProgress->hide();
732 delete sendProgress;
733 sendProgress = 0;
725 wrap->deleteMails(mbox,mailsToRemove); 734 wrap->deleteMails(mbox,mailsToRemove);
726 mailsToSend.setAutoDelete(true); 735 mailsToSend.setAutoDelete(true);
727 delete wrap; 736 delete wrap;
728} 737}
diff --git a/noncore/net/mail/sendmailprogress.cpp b/noncore/net/mail/sendmailprogress.cpp
index 13ddd37..ef22750 100644
--- a/noncore/net/mail/sendmailprogress.cpp
+++ b/noncore/net/mail/sendmailprogress.cpp
@@ -1,48 +1,48 @@
1#include "sendmailprogress.h" 1#include "sendmailprogress.h"
2#include <qprogressbar.h> 2#include <qprogressbar.h>
3#include <qlabel.h> 3#include <qlabel.h>
4#include <qstring.h> 4#include <qstring.h>
5 5
6progressMailSend::progressMailSend(QWidget*parent, const char * name) 6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) 7 :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{ 8{
9} 9}
10 10
11progressMailSend::~progressMailSend() 11progressMailSend::~progressMailSend()
12{ 12{
13} 13}
14 14
15void progressMailSend::setMaxMails(unsigned int aMaxMails) 15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{ 16{
17 m_max_mail = aMaxMails; 17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails); 18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails(); 19 setMails();
20} 20}
21 21
22void progressMailSend::setCurrentMails(unsigned int aCurrent) 22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{ 23{
24 m_current_mail = aCurrent; 24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent); 25 allMailProgressBar->setProgress(aCurrent);
26 setMails(); 26 setMails();
27} 27}
28 28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) 29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{ 30{
31 m_current_single = aCurrent; 31 m_current_single = aCurrent;
32 m_max_single = aMax; 32 m_max_single = aMax;
33 setSingle(); 33 setSingle();
34} 34}
35 35
36void progressMailSend::setSingle() 36void progressMailSend::setSingle()
37{ 37{
38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); 38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text); 39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single); 40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single); 41 singleMailProgressBar->setProgress(m_current_single);
42} 42}
43 43
44void progressMailSend::setMails() 44void progressMailSend::setMails()
45{ 45{
46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); 46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
47 allMailLabel->setText(text); 47 allMailLabel->setText(text);
48} 48}
diff --git a/noncore/net/mail/sendmailprogressui.ui b/noncore/net/mail/sendmailprogressui.ui
index b90b088..287ab5e 100644
--- a/noncore/net/mail/sendmailprogressui.ui
+++ b/noncore/net/mail/sendmailprogressui.ui
@@ -1,110 +1,110 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>progressMailSendUI</class> 2<class>progressMailSendUI</class>
3<widget> 3<widget>
4 <class>QDialog</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>progressMailSendUI</cstring> 7 <cstring>progressMailSendUI</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>316</width> 14 <width>221</width>
15 <height>266</height> 15 <height>127</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Sending mail</string> 20 <string>Sending mail</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <vbox> 28 <vbox>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>4</number> 31 <number>4</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QLabel</class> 38 <class>QLabel</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>singleMailLabel</cstring> 41 <cstring>singleMailLabel</cstring>
42 </property> 42 </property>
43 <property stdset="1"> 43 <property stdset="1">
44 <name>text</name> 44 <name>text</name>
45 <string>Progress of mail</string> 45 <string>Progress of mail</string>
46 </property> 46 </property>
47 <property stdset="1"> 47 <property stdset="1">
48 <name>alignment</name> 48 <name>alignment</name>
49 <set>AlignCenter</set> 49 <set>AlignCenter</set>
50 </property> 50 </property>
51 <property> 51 <property>
52 <name>hAlign</name> 52 <name>hAlign</name>
53 </property> 53 </property>
54 </widget> 54 </widget>
55 <widget> 55 <widget>
56 <class>QProgressBar</class> 56 <class>QProgressBar</class>
57 <property stdset="1"> 57 <property stdset="1">
58 <name>name</name> 58 <name>name</name>
59 <cstring>singleMailProgressBar</cstring> 59 <cstring>singleMailProgressBar</cstring>
60 </property> 60 </property>
61 </widget> 61 </widget>
62 <widget> 62 <widget>
63 <class>QLabel</class> 63 <class>QLabel</class>
64 <property stdset="1"> 64 <property stdset="1">
65 <name>name</name> 65 <name>name</name>
66 <cstring>allMailLabel</cstring> 66 <cstring>allMailLabel</cstring>
67 </property> 67 </property>
68 <property stdset="1"> 68 <property stdset="1">
69 <name>text</name> 69 <name>text</name>
70 <string>Sending mail</string> 70 <string>Sending mail</string>
71 </property> 71 </property>
72 <property stdset="1"> 72 <property stdset="1">
73 <name>alignment</name> 73 <name>alignment</name>
74 <set>AlignCenter</set> 74 <set>AlignCenter</set>
75 </property> 75 </property>
76 <property> 76 <property>
77 <name>hAlign</name> 77 <name>hAlign</name>
78 </property> 78 </property>
79 </widget> 79 </widget>
80 <widget> 80 <widget>
81 <class>QProgressBar</class> 81 <class>QProgressBar</class>
82 <property stdset="1"> 82 <property stdset="1">
83 <name>name</name> 83 <name>name</name>
84 <cstring>allMailProgressBar</cstring> 84 <cstring>allMailProgressBar</cstring>
85 </property> 85 </property>
86 </widget> 86 </widget>
87 <spacer> 87 <spacer>
88 <property> 88 <property>
89 <name>name</name> 89 <name>name</name>
90 <cstring>Spacer6</cstring> 90 <cstring>Spacer6</cstring>
91 </property> 91 </property>
92 <property stdset="1"> 92 <property stdset="1">
93 <name>orientation</name> 93 <name>orientation</name>
94 <enum>Vertical</enum> 94 <enum>Vertical</enum>
95 </property> 95 </property>
96 <property stdset="1"> 96 <property stdset="1">
97 <name>sizeType</name> 97 <name>sizeType</name>
98 <enum>Expanding</enum> 98 <enum>Expanding</enum>
99 </property> 99 </property>
100 <property> 100 <property>
101 <name>sizeHint</name> 101 <name>sizeHint</name>
102 <size> 102 <size>
103 <width>20</width> 103 <width>20</width>
104 <height>20</height> 104 <height>20</height>
105 </size> 105 </size>
106 </property> 106 </property>
107 </spacer> 107 </spacer>
108 </vbox> 108 </vbox>
109</widget> 109</widget>
110</UI> 110</UI>
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
index 53c0af5..770e2b8 100644
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/noncore/net/mail/smtpwrapper.cpp
@@ -1,728 +1,737 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9 9
10#include <libetpan/libetpan.h> 10#include <libetpan/libetpan.h>
11 11
12#include "smtpwrapper.h" 12#include "smtpwrapper.h"
13#include "mailwrapper.h" 13#include "mailwrapper.h"
14#include "mboxwrapper.h" 14#include "mboxwrapper.h"
15#include "logindialog.h" 15#include "logindialog.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17#include "defines.h" 17#include "defines.h"
18#include "sendmailprogress.h" 18#include "sendmailprogress.h"
19 19
20progressMailSend*SMTPwrapper::sendProgress = 0; 20progressMailSend*SMTPwrapper::sendProgress = 0;
21 21
22SMTPwrapper::SMTPwrapper( Settings *s ) 22SMTPwrapper::SMTPwrapper( Settings *s )
23 : QObject() 23 : QObject()
24{ 24{
25 settings = s; 25 settings = s;
26} 26}
27 27
28QString SMTPwrapper::mailsmtpError( int errnum ) 28QString SMTPwrapper::mailsmtpError( int errnum )
29{ 29{
30 switch ( errnum ) { 30 switch ( errnum ) {
31 case MAILSMTP_NO_ERROR: 31 case MAILSMTP_NO_ERROR:
32 return tr( "No error" ); 32 return tr( "No error" );
33 case MAILSMTP_ERROR_UNEXPECTED_CODE: 33 case MAILSMTP_ERROR_UNEXPECTED_CODE:
34 return tr( "Unexpected error code" ); 34 return tr( "Unexpected error code" );
35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
36 return tr( "Service not available" ); 36 return tr( "Service not available" );
37 case MAILSMTP_ERROR_STREAM: 37 case MAILSMTP_ERROR_STREAM:
38 return tr( "Stream error" ); 38 return tr( "Stream error" );
39 case MAILSMTP_ERROR_HOSTNAME: 39 case MAILSMTP_ERROR_HOSTNAME:
40 return tr( "gethostname() failed" ); 40 return tr( "gethostname() failed" );
41 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 41 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
42 return tr( "Not implemented" ); 42 return tr( "Not implemented" );
43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
44 return tr( "Error, action not taken" ); 44 return tr( "Error, action not taken" );
45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
46 return tr( "Data exceeds storage allocation" ); 46 return tr( "Data exceeds storage allocation" );
47 case MAILSMTP_ERROR_IN_PROCESSING: 47 case MAILSMTP_ERROR_IN_PROCESSING:
48 return tr( "Error in processing" ); 48 return tr( "Error in processing" );
49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
50 // return tr( "Insufficient system storage" ); 50 // return tr( "Insufficient system storage" );
51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
52 return tr( "Mailbox unavailable" ); 52 return tr( "Mailbox unavailable" );
53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
54 return tr( "Mailbox name not allowed" ); 54 return tr( "Mailbox name not allowed" );
55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
56 return tr( "Bad command sequence" ); 56 return tr( "Bad command sequence" );
57 case MAILSMTP_ERROR_USER_NOT_LOCAL: 57 case MAILSMTP_ERROR_USER_NOT_LOCAL:
58 return tr( "User not local" ); 58 return tr( "User not local" );
59 case MAILSMTP_ERROR_TRANSACTION_FAILED: 59 case MAILSMTP_ERROR_TRANSACTION_FAILED:
60 return tr( "Transaction failed" ); 60 return tr( "Transaction failed" );
61 case MAILSMTP_ERROR_MEMORY: 61 case MAILSMTP_ERROR_MEMORY:
62 return tr( "Memory error" ); 62 return tr( "Memory error" );
63 case MAILSMTP_ERROR_CONNECTION_REFUSED: 63 case MAILSMTP_ERROR_CONNECTION_REFUSED:
64 return tr( "Connection refused" ); 64 return tr( "Connection refused" );
65 default: 65 default:
66 return tr( "Unknown error code" ); 66 return tr( "Unknown error code" );
67 } 67 }
68} 68}
69 69
70mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) 70mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
71{ 71{
72 return mailimf_mailbox_new( strdup( name.latin1() ), 72 return mailimf_mailbox_new( strdup( name.latin1() ),
73 strdup( mail.latin1() ) ); 73 strdup( mail.latin1() ) );
74} 74}
75 75
76mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) 76mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
77{ 77{
78 mailimf_address_list *addresses; 78 mailimf_address_list *addresses;
79 79
80 if ( addr.isEmpty() ) return NULL; 80 if ( addr.isEmpty() ) return NULL;
81 81
82 addresses = mailimf_address_list_new_empty(); 82 addresses = mailimf_address_list_new_empty();
83 83
84 QStringList list = QStringList::split( ',', addr ); 84 QStringList list = QStringList::split( ',', addr );
85 QStringList::Iterator it; 85 QStringList::Iterator it;
86 for ( it = list.begin(); it != list.end(); it++ ) { 86 for ( it = list.begin(); it != list.end(); it++ ) {
87 char *str = strdup( (*it).latin1() ); 87 char *str = strdup( (*it).latin1() );
88 int err = mailimf_address_list_add_parse( addresses, str ); 88 int err = mailimf_address_list_add_parse( addresses, str );
89 if ( err != MAILIMF_NO_ERROR ) { 89 if ( err != MAILIMF_NO_ERROR ) {
90 qDebug( "Error parsing" ); 90 qDebug( "Error parsing" );
91 qDebug( *it ); 91 qDebug( *it );
92 free( str ); 92 free( str );
93 } else { 93 } else {
94 qDebug( "Parse success! :)" ); 94 qDebug( "Parse success! :)" );
95 } 95 }
96 } 96 }
97 97
98 return addresses; 98 return addresses;
99} 99}
100 100
101mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 101mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
102{ 102{
103 mailimf_fields *fields; 103 mailimf_fields *fields;
104 mailimf_field *xmailer; 104 mailimf_field *xmailer;
105 mailimf_mailbox *sender, *fromBox; 105 mailimf_mailbox *sender, *fromBox;
106 mailimf_mailbox_list *from; 106 mailimf_mailbox_list *from;
107 mailimf_address_list *to, *cc, *bcc, *reply; 107 mailimf_address_list *to, *cc, *bcc, *reply;
108 char *subject = strdup( mail.getSubject().latin1() ); 108 char *subject = strdup( mail.getSubject().latin1() );
109 int err; 109 int err;
110 110
111 sender = newMailbox( mail.getName(), mail.getMail() ); 111 sender = newMailbox( mail.getName(), mail.getMail() );
112 if ( sender == NULL ) goto err_free; 112 if ( sender == NULL ) goto err_free;
113 113
114 fromBox = newMailbox( mail.getName(), mail.getMail() ); 114 fromBox = newMailbox( mail.getName(), mail.getMail() );
115 if ( fromBox == NULL ) goto err_free_sender; 115 if ( fromBox == NULL ) goto err_free_sender;
116 116
117 from = mailimf_mailbox_list_new_empty(); 117 from = mailimf_mailbox_list_new_empty();
118 if ( from == NULL ) goto err_free_fromBox; 118 if ( from == NULL ) goto err_free_fromBox;
119 119
120 err = mailimf_mailbox_list_add( from, fromBox ); 120 err = mailimf_mailbox_list_add( from, fromBox );
121 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 121 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
122 122
123 to = parseAddresses( mail.getTo() ); 123 to = parseAddresses( mail.getTo() );
124 if ( to == NULL ) goto err_free_from; 124 if ( to == NULL ) goto err_free_from;
125 125
126 cc = parseAddresses( mail.getCC() ); 126 cc = parseAddresses( mail.getCC() );
127 bcc = parseAddresses( mail.getBCC() ); 127 bcc = parseAddresses( mail.getBCC() );
128 reply = parseAddresses( mail.getReply() ); 128 reply = parseAddresses( mail.getReply() );
129 129
130 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 130 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
131 NULL, NULL, subject ); 131 NULL, NULL, subject );
132 if ( fields == NULL ) goto err_free_reply; 132 if ( fields == NULL ) goto err_free_reply;
133 133
134 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 134 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
135 strdup( USER_AGENT ) ); 135 strdup( USER_AGENT ) );
136 if ( xmailer == NULL ) goto err_free_fields; 136 if ( xmailer == NULL ) goto err_free_fields;
137 137
138 err = mailimf_fields_add( fields, xmailer ); 138 err = mailimf_fields_add( fields, xmailer );
139 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 139 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
140 140
141 return fields; // Success :) 141 return fields; // Success :)
142 142
143err_free_xmailer: 143err_free_xmailer:
144 mailimf_field_free( xmailer ); 144 mailimf_field_free( xmailer );
145err_free_fields: 145err_free_fields:
146 mailimf_fields_free( fields ); 146 mailimf_fields_free( fields );
147err_free_reply: 147err_free_reply:
148 mailimf_address_list_free( reply ); 148 mailimf_address_list_free( reply );
149 mailimf_address_list_free( bcc ); 149 mailimf_address_list_free( bcc );
150 mailimf_address_list_free( cc ); 150 mailimf_address_list_free( cc );
151 mailimf_address_list_free( to ); 151 mailimf_address_list_free( to );
152err_free_from: 152err_free_from:
153 mailimf_mailbox_list_free( from ); 153 mailimf_mailbox_list_free( from );
154err_free_fromBox: 154err_free_fromBox:
155 mailimf_mailbox_free( fromBox ); 155 mailimf_mailbox_free( fromBox );
156err_free_sender: 156err_free_sender:
157 mailimf_mailbox_free( sender ); 157 mailimf_mailbox_free( sender );
158err_free: 158err_free:
159 free( subject ); 159 free( subject );
160 qDebug( "createImfFields - error" ); 160 qDebug( "createImfFields - error" );
161 161
162 return NULL; // Error :( 162 return NULL; // Error :(
163} 163}
164 164
165mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 165mailmime *SMTPwrapper::buildTxtPart(const QString&str )
166{ 166{
167 mailmime *txtPart; 167 mailmime *txtPart;
168 mailmime_fields *fields; 168 mailmime_fields *fields;
169 mailmime_content *content; 169 mailmime_content *content;
170 mailmime_parameter *param; 170 mailmime_parameter *param;
171 char *txt = strdup( str.latin1() ); 171 char *txt = strdup( str.latin1() );
172 int err; 172 int err;
173 173
174 param = mailmime_parameter_new( strdup( "charset" ), 174 param = mailmime_parameter_new( strdup( "charset" ),
175 strdup( "iso-8859-1" ) ); 175 strdup( "iso-8859-1" ) );
176 if ( param == NULL ) goto err_free; 176 if ( param == NULL ) goto err_free;
177 177
178 content = mailmime_content_new_with_str( "text/plain" ); 178 content = mailmime_content_new_with_str( "text/plain" );
179 if ( content == NULL ) goto err_free_param; 179 if ( content == NULL ) goto err_free_param;
180 180
181 err = clist_append( content->ct_parameters, param ); 181 err = clist_append( content->ct_parameters, param );
182 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 182 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
183 183
184 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 184 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
185 if ( fields == NULL ) goto err_free_content; 185 if ( fields == NULL ) goto err_free_content;
186 186
187 txtPart = mailmime_new_empty( content, fields ); 187 txtPart = mailmime_new_empty( content, fields );
188 if ( txtPart == NULL ) goto err_free_fields; 188 if ( txtPart == NULL ) goto err_free_fields;
189 189
190 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 190 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
191 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 191 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
192 192
193 return txtPart; // Success :) 193 return txtPart; // Success :)
194 194
195err_free_txtPart: 195err_free_txtPart:
196 mailmime_free( txtPart ); 196 mailmime_free( txtPart );
197err_free_fields: 197err_free_fields:
198 mailmime_fields_free( fields ); 198 mailmime_fields_free( fields );
199err_free_content: 199err_free_content:
200 mailmime_content_free( content ); 200 mailmime_content_free( content );
201err_free_param: 201err_free_param:
202 mailmime_parameter_free( param ); 202 mailmime_parameter_free( param );
203err_free: 203err_free:
204 free( txt ); 204 free( txt );
205 qDebug( "buildTxtPart - error" ); 205 qDebug( "buildTxtPart - error" );
206 206
207 return NULL; // Error :( 207 return NULL; // Error :(
208} 208}
209 209
210mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 210mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
211{ 211{
212 mailmime * filePart = 0; 212 mailmime * filePart = 0;
213 mailmime_fields * fields = 0; 213 mailmime_fields * fields = 0;
214 mailmime_content * content = 0; 214 mailmime_content * content = 0;
215 mailmime_parameter * param = 0; 215 mailmime_parameter * param = 0;
216 char*name = 0; 216 char*name = 0;
217 char*file = 0; 217 char*file = 0;
218 int err; 218 int err;
219 219
220 int pos = filename.findRev( '/' ); 220 int pos = filename.findRev( '/' );
221 221
222 if (filename.length()>0) { 222 if (filename.length()>0) {
223 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 223 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
224 name = strdup( tmp.latin1() ); // just filename 224 name = strdup( tmp.latin1() ); // just filename
225 file = strdup( filename.latin1() ); // full name with path 225 file = strdup( filename.latin1() ); // full name with path
226 } 226 }
227 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 227 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
228 228
229 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 229 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
230 int mechanism = MAILMIME_MECHANISM_BASE64; 230 int mechanism = MAILMIME_MECHANISM_BASE64;
231 231
232 if ( mimetype.startsWith( "text/" ) ) { 232 if ( mimetype.startsWith( "text/" ) ) {
233 param = mailmime_parameter_new( strdup( "charset" ), 233 param = mailmime_parameter_new( strdup( "charset" ),
234 strdup( "iso-8859-1" ) ); 234 strdup( "iso-8859-1" ) );
235 disptype = MAILMIME_DISPOSITION_TYPE_INLINE; 235 disptype = MAILMIME_DISPOSITION_TYPE_INLINE;
236 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 236 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
237 } 237 }
238 238
239 fields = mailmime_fields_new_filename( 239 fields = mailmime_fields_new_filename(
240 disptype, name, 240 disptype, name,
241 mechanism ); 241 mechanism );
242 content = mailmime_content_new_with_str( mime ); 242 content = mailmime_content_new_with_str( mime );
243 if (content!=0 && fields != 0) { 243 if (content!=0 && fields != 0) {
244 if (param) { 244 if (param) {
245 clist_append(content->ct_parameters,param); 245 clist_append(content->ct_parameters,param);
246 param = 0; 246 param = 0;
247 } 247 }
248 if (filename.length()>0) { 248 if (filename.length()>0) {
249 QFileInfo f(filename); 249 QFileInfo f(filename);
250 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 250 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
251 clist_append(content->ct_parameters,param); 251 clist_append(content->ct_parameters,param);
252 param = 0; 252 param = 0;
253 } 253 }
254 filePart = mailmime_new_empty( content, fields ); 254 filePart = mailmime_new_empty( content, fields );
255 } 255 }
256 if (filePart) { 256 if (filePart) {
257 if (filename.length()>0) { 257 if (filename.length()>0) {
258 err = mailmime_set_body_file( filePart, file ); 258 err = mailmime_set_body_file( filePart, file );
259 } else { 259 } else {
260 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); 260 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length());
261 } 261 }
262 if (err != MAILIMF_NO_ERROR) { 262 if (err != MAILIMF_NO_ERROR) {
263 qDebug("Error setting body with file %s",file); 263 qDebug("Error setting body with file %s",file);
264 mailmime_free( filePart ); 264 mailmime_free( filePart );
265 filePart = 0; 265 filePart = 0;
266 } 266 }
267 } 267 }
268 268
269 if (!filePart) { 269 if (!filePart) {
270 if ( param != NULL ) { 270 if ( param != NULL ) {
271 mailmime_parameter_free( param ); 271 mailmime_parameter_free( param );
272 } 272 }
273 if (content) { 273 if (content) {
274 mailmime_content_free( content ); 274 mailmime_content_free( content );
275 } else { 275 } else {
276 if (mime) { 276 if (mime) {
277 free( mime ); 277 free( mime );
278 } 278 }
279 } 279 }
280 if (fields) { 280 if (fields) {
281 mailmime_fields_free( fields ); 281 mailmime_fields_free( fields );
282 } else { 282 } else {
283 if (name) { 283 if (name) {
284 free( name ); 284 free( name );
285 } 285 }
286 if (file) { 286 if (file) {
287 free( file ); 287 free( file );
288 } 288 }
289 } 289 }
290 } 290 }
291 return filePart; // Success :) 291 return filePart; // Success :)
292 292
293} 293}
294 294
295void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) 295void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
296{ 296{
297 const Attachment *it; 297 const Attachment *it;
298 unsigned int count = files.count(); 298 unsigned int count = files.count();
299 qDebug("List contains %i values",count); 299 qDebug("List contains %i values",count);
300 for ( unsigned int i = 0; i < count; ++i ) { 300 for ( unsigned int i = 0; i < count; ++i ) {
301 qDebug( "Adding file" ); 301 qDebug( "Adding file" );
302 mailmime *filePart; 302 mailmime *filePart;
303 int err; 303 int err;
304 it = ((QList<Attachment>)files).at(i); 304 it = ((QList<Attachment>)files).at(i);
305 305
306 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 306 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
307 if ( filePart == NULL ) { 307 if ( filePart == NULL ) {
308 qDebug( "addFileParts: error adding file:" ); 308 qDebug( "addFileParts: error adding file:" );
309 qDebug( it->getFileName() ); 309 qDebug( it->getFileName() );
310 continue; 310 continue;
311 } 311 }
312 err = mailmime_smart_add_part( message, filePart ); 312 err = mailmime_smart_add_part( message, filePart );
313 if ( err != MAILIMF_NO_ERROR ) { 313 if ( err != MAILIMF_NO_ERROR ) {
314 mailmime_free( filePart ); 314 mailmime_free( filePart );
315 qDebug("error smart add"); 315 qDebug("error smart add");
316 } 316 }
317 } 317 }
318} 318}
319 319
320mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) 320mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
321{ 321{
322 mailmime *message, *txtPart; 322 mailmime *message, *txtPart;
323 mailimf_fields *fields; 323 mailimf_fields *fields;
324 int err; 324 int err;
325 325
326 fields = createImfFields( mail ); 326 fields = createImfFields( mail );
327 if ( fields == NULL ) goto err_free; 327 if ( fields == NULL ) goto err_free;
328 328
329 message = mailmime_new_message_data( NULL ); 329 message = mailmime_new_message_data( NULL );
330 if ( message == NULL ) goto err_free_fields; 330 if ( message == NULL ) goto err_free_fields;
331 331
332 mailmime_set_imf_fields( message, fields ); 332 mailmime_set_imf_fields( message, fields );
333 333
334 if (mail.getAttachments().count()==0) { 334 if (mail.getAttachments().count()==0) {
335 txtPart = buildTxtPart( mail.getMessage() ); 335 txtPart = buildTxtPart( mail.getMessage() );
336 } else { 336 } else {
337 txtPart = buildFilePart("","text/plain",mail.getMessage()); 337 txtPart = buildFilePart("","text/plain",mail.getMessage());
338 } 338 }
339 if ( txtPart == NULL ) goto err_free_message; 339 if ( txtPart == NULL ) goto err_free_message;
340 340
341 err = mailmime_smart_add_part( message, txtPart ); 341 err = mailmime_smart_add_part( message, txtPart );
342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
343 343
344 addFileParts( message, mail.getAttachments() ); 344 addFileParts( message, mail.getAttachments() );
345 345
346 return message; // Success :) 346 return message; // Success :)
347 347
348err_free_txtPart: 348err_free_txtPart:
349 mailmime_free( txtPart ); 349 mailmime_free( txtPart );
350err_free_message: 350err_free_message:
351 mailmime_free( message ); 351 mailmime_free( message );
352err_free_fields: 352err_free_fields:
353 mailimf_fields_free( fields ); 353 mailimf_fields_free( fields );
354err_free: 354err_free:
355 qDebug( "createMimeMail: error" ); 355 qDebug( "createMimeMail: error" );
356 356
357 return NULL; // Error :( 357 return NULL; // Error :(
358} 358}
359 359
360mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) 360mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
361{ 361{
362 mailimf_field *field; 362 mailimf_field *field;
363 clistiter *it; 363 clistiter *it;
364 364
365 it = clist_begin( fields->fld_list ); 365 it = clist_begin( fields->fld_list );
366 while ( it ) { 366 while ( it ) {
367 field = (mailimf_field *) it->data; 367 field = (mailimf_field *) it->data;
368 if ( field->fld_type == type ) { 368 if ( field->fld_type == type ) {
369 return field; 369 return field;
370 } 370 }
371 it = it->next; 371 it = it->next;
372 } 372 }
373 373
374 return NULL; 374 return NULL;
375} 375}
376 376
377void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) 377void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
378{ 378{
379 clistiter *it, *it2; 379 clistiter *it, *it2;
380 380
381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
382 mailimf_address *addr; 382 mailimf_address *addr;
383 addr = (mailimf_address *) it->data; 383 addr = (mailimf_address *) it->data;
384 384
385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
390 mailimf_mailbox *mbox; 390 mailimf_mailbox *mbox;
391 mbox = (mailimf_mailbox *) it2->data; 391 mbox = (mailimf_mailbox *) it2->data;
392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
393 } 393 }
394 } 394 }
395 } 395 }
396} 396}
397 397
398clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) 398clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
399{ 399{
400 clist *rcptList; 400 clist *rcptList;
401 mailimf_field *field; 401 mailimf_field *field;
402 402
403 rcptList = esmtp_address_list_new(); 403 rcptList = esmtp_address_list_new();
404 404
405 field = getField( fields, MAILIMF_FIELD_TO ); 405 field = getField( fields, MAILIMF_FIELD_TO );
406 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 406 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
407 && field->fld_data.fld_to->to_addr_list ) { 407 && field->fld_data.fld_to->to_addr_list ) {
408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
409 } 409 }
410 410
411 field = getField( fields, MAILIMF_FIELD_CC ); 411 field = getField( fields, MAILIMF_FIELD_CC );
412 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 412 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
413 && field->fld_data.fld_cc->cc_addr_list ) { 413 && field->fld_data.fld_cc->cc_addr_list ) {
414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
415 } 415 }
416 416
417 field = getField( fields, MAILIMF_FIELD_BCC ); 417 field = getField( fields, MAILIMF_FIELD_BCC );
418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
419 && field->fld_data.fld_bcc->bcc_addr_list ) { 419 && field->fld_data.fld_bcc->bcc_addr_list ) {
420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
421 } 421 }
422 422
423 return rcptList; 423 return rcptList;
424} 424}
425 425
426char *SMTPwrapper::getFrom( mailimf_field *ffrom) 426char *SMTPwrapper::getFrom( mailimf_field *ffrom)
427{ 427{
428 char *from = NULL; 428 char *from = NULL;
429 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 429 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
430 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 430 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
431 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 431 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
432 clistiter *it; 432 clistiter *it;
433 for ( it = clist_begin( cl ); it; it = it->next ) { 433 for ( it = clist_begin( cl ); it; it = it->next ) {
434 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 434 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
435 from = strdup( mb->mb_addr_spec ); 435 from = strdup( mb->mb_addr_spec );
436 } 436 }
437 } 437 }
438 438
439 return from; 439 return from;
440} 440}
441 441
442char *SMTPwrapper::getFrom( mailmime *mail ) 442char *SMTPwrapper::getFrom( mailmime *mail )
443{ 443{
444 mailimf_field *ffrom = 0; 444 mailimf_field *ffrom = 0;
445 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 445 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
446 return getFrom(ffrom); 446 return getFrom(ffrom);
447} 447}
448 448
449SMTPaccount *SMTPwrapper::getAccount(const QString&name ) 449SMTPaccount *SMTPwrapper::getAccount(const QString&name )
450{ 450{
451 SMTPaccount *smtp; 451 SMTPaccount *smtp;
452 452
453 QList<Account> list = settings->getAccounts(); 453 QList<Account> list = settings->getAccounts();
454 Account *it; 454 Account *it;
455 for ( it = list.first(); it; it = list.next() ) { 455 for ( it = list.first(); it; it = list.next() ) {
456 if ( it->getType().compare( "SMTP" ) == 0 ) { 456 if ( it->getType().compare( "SMTP" ) == 0 ) {
457 smtp = static_cast<SMTPaccount *>(it); 457 smtp = static_cast<SMTPaccount *>(it);
458 if ( smtp->getName()== name ) { 458 if ( smtp->getName()== name ) {
459 qDebug( "SMTPaccount found for" ); 459 qDebug( "SMTPaccount found for" );
460 qDebug( name ); 460 qDebug( name );
461 return smtp; 461 return smtp;
462 } 462 }
463 } 463 }
464 } 464 }
465 465
466 return NULL; 466 return NULL;
467} 467}
468 468
469QString SMTPwrapper::getTmpFile() { 469QString SMTPwrapper::getTmpFile() {
470 int num = 0; 470 int num = 0;
471 QString unique; 471 QString unique;
472 472
473 QDir dir( "/tmp" ); 473 QDir dir( "/tmp" );
474 474
475 QStringList list = dir.entryList( "opiemail-tmp-*" ); 475 QStringList list = dir.entryList( "opiemail-tmp-*" );
476 476
477 do { 477 do {
478 unique.setNum( num++ ); 478 unique.setNum( num++ );
479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
480 480
481 return "/tmp/opiemail-tmp-" + unique; 481 return "/tmp/opiemail-tmp-" + unique;
482} 482}
483 483
484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) 484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
485{ 485{
486 FILE *f; 486 FILE *f;
487 int err, col = 0; 487 int err, col = 0;
488 488
489 f = fopen( file.latin1(), "w" ); 489 f = fopen( file.latin1(), "w" );
490 if ( f == NULL ) { 490 if ( f == NULL ) {
491 qDebug( "writeToFile: error opening file" ); 491 qDebug( "writeToFile: error opening file" );
492 return; 492 return;
493 } 493 }
494 494
495 err = mailmime_write( f, &col, mail ); 495 err = mailmime_write( f, &col, mail );
496 if ( err != MAILIMF_NO_ERROR ) { 496 if ( err != MAILIMF_NO_ERROR ) {
497 fclose( f ); 497 fclose( f );
498 qDebug( "writeToFile: error writing mailmime" ); 498 qDebug( "writeToFile: error writing mailmime" );
499 return; 499 return;
500 } 500 }
501 501
502 fclose( f ); 502 fclose( f );
503} 503}
504 504
505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
506{ 506{
507 507
508 QFile msg_cache(file); 508 QFile msg_cache(file);
509 QString msg = ""; 509 QString msg = "";
510 msg_cache.open(IO_ReadOnly); 510 msg_cache.open(IO_ReadOnly);
511 char*message = new char[4096]; 511 char*message = new char[4096];
512 memset(message,0,4096); 512 memset(message,0,4096);
513 while (msg_cache.readBlock(message,4095)>0) { 513 while (msg_cache.readBlock(message,4095)>0) {
514 msg+=message; 514 msg+=message;
515 memset(message,0,4096); 515 memset(message,0,4096);
516 } 516 }
517 delete message; 517 delete message;
518 *data = (char*)malloc(msg.length()+1*sizeof(char)); 518 *data = (char*)malloc(msg.length()+1*sizeof(char));
519 memset(*data,0,msg.length()+1); 519 memset(*data,0,msg.length()+1);
520 memcpy(*data,msg.ascii(),msg.length()); 520 memcpy(*data,msg.ascii(),msg.length());
521 *size=msg.length(); 521 *size=msg.length();
522} 522}
523 523
524void SMTPwrapper::progress( size_t current, size_t maximum ) 524void SMTPwrapper::progress( size_t current, size_t maximum )
525{ 525{
526 if (SMTPwrapper::sendProgress) { 526 if (SMTPwrapper::sendProgress) {
527 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 527 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
528 qDebug("%u of %u",current,maximum); 528 qApp->processEvents();
529 } 529 }
530} 530}
531 531
532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
533{ 533{
534 if (!mail) return; 534 if (!mail) return;
535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
536 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 536 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
537 wrap->storeMessage(mail,length,box); 537 wrap->storeMessage(mail,length,box);
538 delete wrap; 538 delete wrap;
539} 539}
540 540
541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
542{ 542{
543 clist *rcpts = 0; 543 clist *rcpts = 0;
544 char *from, *data; 544 char *from, *data;
545 size_t size; 545 size_t size;
546 546
547 if ( smtp == NULL ) { 547 if ( smtp == NULL ) {
548 return; 548 return;
549 } 549 }
550 from = data = 0; 550 from = data = 0;
551 551
552 QString file = getTmpFile(); 552 QString file = getTmpFile();
553 writeToFile( file, mail ); 553 writeToFile( file, mail );
554 readFromFile( file, &data, &size ); 554 readFromFile( file, &data, &size );
555 QFile f( file ); 555 QFile f( file );
556 f.remove(); 556 f.remove();
557 557
558 if (later) { 558 if (later) {
559 storeMail(data,size,"Outgoing"); 559 storeMail(data,size,"Outgoing");
560 if (data) free( data ); 560 if (data) free( data );
561 return; 561 return;
562 } 562 }
563 from = getFrom( mail ); 563 from = getFrom( mail );
564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
565 smtpSend(from,rcpts,data,size,smtp); 565 smtpSend(from,rcpts,data,size,smtp);
566} 566}
567 567
568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
569{ 569{
570 char *server, *user, *pass; 570 char *server, *user, *pass;
571 bool ssl; 571 bool ssl;
572 uint16_t port; 572 uint16_t port;
573 mailsmtp *session; 573 mailsmtp *session;
574 int err,result; 574 int err,result;
575 575
576 result = 1; 576 result = 1;
577 server = user = pass = 0; 577 server = user = pass = 0;
578 server = strdup( smtp->getServer().latin1() ); 578 server = strdup( smtp->getServer().latin1() );
579 ssl = smtp->getSSL(); 579 ssl = smtp->getSSL();
580 port = smtp->getPort().toUInt(); 580 port = smtp->getPort().toUInt();
581 581
582 session = mailsmtp_new( 20, &progress ); 582 session = mailsmtp_new( 20, &progress );
583 if ( session == NULL ) goto free_mem; 583 if ( session == NULL ) goto free_mem;
584 584
585 qDebug( "Servername %s at port %i", server, port ); 585 qDebug( "Servername %s at port %i", server, port );
586 if ( ssl ) { 586 if ( ssl ) {
587 qDebug( "SSL session" ); 587 qDebug( "SSL session" );
588 err = mailsmtp_ssl_connect( session, server, port ); 588 err = mailsmtp_ssl_connect( session, server, port );
589 } else { 589 } else {
590 qDebug( "No SSL session" ); 590 qDebug( "No SSL session" );
591 err = mailsmtp_socket_connect( session, server, port ); 591 err = mailsmtp_socket_connect( session, server, port );
592 } 592 }
593 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} 593 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
594 594
595 err = mailsmtp_init( session ); 595 err = mailsmtp_init( session );
596 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 596 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
597 597
598 qDebug( "INIT OK" ); 598 qDebug( "INIT OK" );
599 599
600 if ( smtp->getLogin() ) { 600 if ( smtp->getLogin() ) {
601 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 601 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
602 // get'em 602 // get'em
603 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 603 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
604 login.show(); 604 login.show();
605 if ( QDialog::Accepted == login.exec() ) { 605 if ( QDialog::Accepted == login.exec() ) {
606 // ok 606 // ok
607 user = strdup( login.getUser().latin1() ); 607 user = strdup( login.getUser().latin1() );
608 pass = strdup( login.getPassword().latin1() ); 608 pass = strdup( login.getPassword().latin1() );
609 } else { 609 } else {
610 result = 0; goto free_con_session; 610 result = 0; goto free_con_session;
611 } 611 }
612 } else { 612 } else {
613 user = strdup( smtp->getUser().latin1() ); 613 user = strdup( smtp->getUser().latin1() );
614 pass = strdup( smtp->getPassword().latin1() ); 614 pass = strdup( smtp->getPassword().latin1() );
615 } 615 }
616 qDebug( "session->auth: %i", session->auth); 616 qDebug( "session->auth: %i", session->auth);
617 err = mailsmtp_auth( session, user, pass ); 617 err = mailsmtp_auth( session, user, pass );
618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
619 qDebug( "Done auth!" ); 619 qDebug( "Done auth!" );
620 } 620 }
621 621
622 err = mailsmtp_send( session, from, rcpts, data, size ); 622 err = mailsmtp_send( session, from, rcpts, data, size );
623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
624 624
625 qDebug( "Mail sent." ); 625 qDebug( "Mail sent." );
626 storeMail(data,size,"Sent"); 626 storeMail(data,size,"Sent");
627 627
628free_con_session: 628free_con_session:
629 mailsmtp_quit( session ); 629 mailsmtp_quit( session );
630free_mem_session: 630free_mem_session:
631 mailsmtp_free( session ); 631 mailsmtp_free( session );
632free_mem: 632free_mem:
633 if (rcpts) smtp_address_list_free( rcpts ); 633 if (rcpts) smtp_address_list_free( rcpts );
634 if (data) free( data ); 634 if (data) free( data );
635 if (server) free( server ); 635 if (server) free( server );
636 if (from) free( from ); 636 if (from) free( from );
637 if ( smtp->getLogin() ) { 637 if ( smtp->getLogin() ) {
638 free( user ); 638 free( user );
639 free( pass ); 639 free( pass );
640 } 640 }
641 return result; 641 return result;
642} 642}
643 643
644void SMTPwrapper::sendMail(const Mail&mail,bool later ) 644void SMTPwrapper::sendMail(const Mail&mail,bool later )
645{ 645{
646 mailmime * mimeMail; 646 mailmime * mimeMail;
647 647
648 SMTPaccount *smtp = getAccount(mail.getName()); 648 SMTPaccount *smtp = getAccount(mail.getName());
649 649
650 mimeMail = createMimeMail(mail ); 650 mimeMail = createMimeMail(mail );
651 if ( mimeMail == NULL ) { 651 if ( mimeMail == NULL ) {
652 qDebug( "sendMail: error creating mime mail" ); 652 qDebug( "sendMail: error creating mime mail" );
653 } else { 653 } else {
654 sendProgress = new progressMailSend(); 654 sendProgress = new progressMailSend();
655 sendProgress->showMaximized(); 655// sendProgress->showMaximized();
656 sendProgress->show(); 656 sendProgress->show();
657 qApp->processEvents(10); 657 sendProgress->setMaxMails(1);
658 smtpSend( mimeMail,later,smtp); 658 smtpSend( mimeMail,later,smtp);
659 mailmime_free( mimeMail ); 659 mailmime_free( mimeMail );
660 qDebug("Clean up done"); 660 qDebug("Clean up done");
661 sendProgress->hide(); 661 sendProgress->hide();
662 delete sendProgress; 662 delete sendProgress;
663 sendProgress = 0; 663 sendProgress = 0;
664 } 664 }
665} 665}
666 666
667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
668{ 668{
669 char*data = 0; 669 char*data = 0;
670 size_t length = 0; 670 size_t length = 0;
671 size_t curTok = 0; 671 size_t curTok = 0;
672 mailimf_fields *fields = 0; 672 mailimf_fields *fields = 0;
673 mailimf_field*ffrom = 0; 673 mailimf_field*ffrom = 0;
674 clist *rcpts = 0; 674 clist *rcpts = 0;
675 char*from = 0; 675 char*from = 0;
676 676
677 wrap->fetchRawBody(*which,&data,&length); 677 wrap->fetchRawBody(*which,&data,&length);
678 if (!data) return 0; 678 if (!data) return 0;
679 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 679 int err = mailimf_fields_parse( data, length, &curTok, &fields );
680 if (err != MAILIMF_NO_ERROR) { 680 if (err != MAILIMF_NO_ERROR) {
681 free(data); 681 free(data);
682 delete wrap; 682 delete wrap;
683 return 0; 683 return 0;
684 } 684 }
685 685
686 rcpts = createRcptList( fields ); 686 rcpts = createRcptList( fields );
687 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 687 ffrom = getField(fields, MAILIMF_FIELD_FROM );
688 from = getFrom(ffrom); 688 from = getFrom(ffrom);
689 689
690 qDebug("Size: %i vs. %i",length,strlen(data)); 690 qDebug("Size: %i vs. %i",length,strlen(data));
691 if (rcpts && from) { 691 if (rcpts && from) {
692 return smtpSend(from,rcpts,data,strlen(data),smtp ); 692 return smtpSend(from,rcpts,data,strlen(data),smtp );
693 } 693 }
694 return 0; 694 return 0;
695} 695}
696 696
697/* this is a special fun */ 697/* this is a special fun */
698void SMTPwrapper::flushOutbox(SMTPaccount*smtp) 698void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
699{ 699{
700 if (!smtp) return; 700 if (!smtp) return;
701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
702 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 702 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
703 if (!wrap) { 703 if (!wrap) {
704 qDebug("memory error"); 704 qDebug("memory error");
705 return; 705 return;
706 } 706 }
707 QList<RecMail> mailsToSend; 707 QList<RecMail> mailsToSend;
708 QList<RecMail> mailsToRemove; 708 QList<RecMail> mailsToRemove;
709 QString mbox("Outgoing"); 709 QString mbox("Outgoing");
710 wrap->listMessages(mbox,mailsToSend); 710 wrap->listMessages(mbox,mailsToSend);
711 if (mailsToSend.count()==0) { 711 if (mailsToSend.count()==0) {
712 delete wrap; 712 delete wrap;
713 return; 713 return;
714 } 714 }
715 mailsToSend.setAutoDelete(false); 715 mailsToSend.setAutoDelete(false);
716 sendProgress = new progressMailSend();
717// sendProgress->showMaximized();
718 sendProgress->show();
719 sendProgress->setMaxMails(mailsToSend.count());
720
716 while (mailsToSend.count()>0) { 721 while (mailsToSend.count()>0) {
717 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 722 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
718 QMessageBox::critical(0,tr("Error sending mail"), 723 QMessageBox::critical(0,tr("Error sending mail"),
719 tr("Error sending queued mail - breaking")); 724 tr("Error sending queued mail - breaking"));
720 break; 725 break;
721 } 726 }
722 mailsToRemove.append(mailsToSend.at(0)); 727 mailsToRemove.append(mailsToSend.at(0));
723 mailsToSend.removeFirst(); 728 mailsToSend.removeFirst();
729 sendProgress->setCurrentMails(mailsToRemove.count());
724 } 730 }
731 sendProgress->hide();
732 delete sendProgress;
733 sendProgress = 0;
725 wrap->deleteMails(mbox,mailsToRemove); 734 wrap->deleteMails(mbox,mailsToRemove);
726 mailsToSend.setAutoDelete(true); 735 mailsToSend.setAutoDelete(true);
727 delete wrap; 736 delete wrap;
728} 737}