author | harlekin <harlekin> | 2004-01-04 02:35:03 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-01-04 02:35:03 (UTC) |
commit | d93529cebc9ea9ab4adf674e93e204f5a53d8906 (patch) (unidiff) | |
tree | 727ebb146a3518a2303d515c8e3e5e093397b9dc | |
parent | 55df8c221c43d81f6132d033553a173276954f7c (diff) | |
download | opie-d93529cebc9ea9ab4adf674e93e204f5a53d8906.zip opie-d93529cebc9ea9ab4adf674e93e204f5a53d8906.tar.gz opie-d93529cebc9ea9ab4adf674e93e204f5a53d8906.tar.bz2 |
adapt build system to lib etc and get it build
-rw-r--r-- | noncore/net/mail/config.in | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/.cvsignore | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/config.in | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/libmailwrapper.pro | 44 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 15 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/settings.cpp | 36 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/mail.pro | 26 | ||||
-rw-r--r-- | noncore/net/mail/mainwindow.cpp | 7 |
9 files changed, 99 insertions, 45 deletions
diff --git a/noncore/net/mail/config.in b/noncore/net/mail/config.in index 43ecc6f..b5173ae 100644 --- a/noncore/net/mail/config.in +++ b/noncore/net/mail/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config MAIL3 | 1 | config MAIL3 |
2 | boolean "opie-mail3 (a mail client)" | 2 | boolean "opie-mail3 (a mail client)" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && LIBMAILWRAPPER |
diff --git a/noncore/net/mail/libmailwrapper/.cvsignore b/noncore/net/mail/libmailwrapper/.cvsignore new file mode 100644 index 0000000..581c299 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | logindialogui.cpp | ||
2 | logindialogui.h | ||
3 | sendmailprogressui.cpp | ||
4 | sendmailprogressui.h | ||
5 | .moc | ||
6 | Makefile | ||
diff --git a/noncore/net/mail/libmailwrapper/config.in b/noncore/net/mail/libmailwrapper/config.in new file mode 100644 index 0000000..790891e --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config LIBMAILWRAPPER | ||
2 | boolean "libmailwrapper ( wrapper arround libetpan needed by mail3" | ||
3 | default "y" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE | ||
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro new file mode 100644 index 0000000..4b4a4f1 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro | |||
@@ -0,0 +1,44 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt warn_on debug | ||
3 | |||
4 | HEADERS = mailwrapper.h \ | ||
5 | imapwrapper.h \ | ||
6 | mailtypes.h \ | ||
7 | pop3wrapper.h \ | ||
8 | abstractmail.h \ | ||
9 | smtpwrapper.h \ | ||
10 | genericwrapper.h \ | ||
11 | mboxwrapper.h \ | ||
12 | settings.h \ | ||
13 | logindialog.h \ | ||
14 | sendmailprogress.h | ||
15 | |||
16 | SOURCES = imapwrapper.cpp \ | ||
17 | mailwrapper.cpp \ | ||
18 | mailtypes.cpp \ | ||
19 | pop3wrapper.cpp \ | ||
20 | abstractmail.cpp \ | ||
21 | smtpwrapper.cpp \ | ||
22 | genericwrapper.cpp \ | ||
23 | mboxwrapper.cpp \ | ||
24 | settings.cpp \ | ||
25 | logindialog.cpp \ | ||
26 | sendmailprogress.cpp | ||
27 | |||
28 | INTERFACES = logindialogui.ui \ | ||
29 | sendmailprogressui.ui | ||
30 | |||
31 | |||
32 | INCLUDEPATH += $(OPIEDIR)/include | ||
33 | |||
34 | CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) | ||
35 | contains( CONFTEST, y ){ | ||
36 | LIBS += -lqpe -letpan -lssl -lcrypto -liconv | ||
37 | }else{ | ||
38 | LIBS += -lqpe -letpan -lssl -lcrypto | ||
39 | } | ||
40 | |||
41 | DESTDIR = $(OPIEDIR)/lib$(PROJMAK) | ||
42 | TARGET = mailwrapper | ||
43 | |||
44 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 9398823..75b9343 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,137 +1,148 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | //#include "logindialog.h" |
11 | #include "defines.h" | 11 | //#include "defines.h" |
12 | |||
13 | #define UNDEFINED 64 | ||
14 | #define MAXLINE 76 | ||
15 | #define UTF16MASK 0x03FFUL | ||
16 | #define UTF16SHIFT 10 | ||
17 | #define UTF16BASE 0x10000UL | ||
18 | #define UTF16HIGHSTART 0xD800UL | ||
19 | #define UTF16HIGHEND 0xDBFFUL | ||
20 | #define UTF16LOSTART 0xDC00UL | ||
21 | #define UTF16LOEND 0xDFFFUL | ||
22 | |||
12 | 23 | ||
13 | Attachment::Attachment( DocLnk lnk ) | 24 | Attachment::Attachment( DocLnk lnk ) |
14 | { | 25 | { |
15 | doc = lnk; | 26 | doc = lnk; |
16 | size = QFileInfo( doc.file() ).size(); | 27 | size = QFileInfo( doc.file() ).size(); |
17 | } | 28 | } |
18 | 29 | ||
19 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 30 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
20 | { | 31 | { |
21 | name = tmp_name; | 32 | name = tmp_name; |
22 | nameDisplay = name; | 33 | nameDisplay = name; |
23 | separator = sep; | 34 | separator = sep; |
24 | } | 35 | } |
25 | 36 | ||
26 | const QString& Folder::Separator()const | 37 | const QString& Folder::Separator()const |
27 | { | 38 | { |
28 | return separator; | 39 | return separator; |
29 | } | 40 | } |
30 | 41 | ||
31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) | 42 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) |
32 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) | 43 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) |
33 | { | 44 | { |
34 | // Decode IMAP foldername | 45 | // Decode IMAP foldername |
35 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 46 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 47 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
37 | 48 | ||
38 | if (prefix.length()>0) { | 49 | if (prefix.length()>0) { |
39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 50 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 51 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
41 | } | 52 | } |
42 | } | 53 | } |
43 | } | 54 | } |
44 | 55 | ||
45 | static unsigned char base64chars[] = | 56 | static unsigned char base64chars[] = |
46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 57 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
47 | 58 | ||
48 | /** | 59 | /** |
49 | * Decodes base64 encoded parts of the imapfolder name | 60 | * Decodes base64 encoded parts of the imapfolder name |
50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 61 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
51 | */ | 62 | */ |
52 | QString IMAPFolder::decodeFolderName( const QString &name ) | 63 | QString IMAPFolder::decodeFolderName( const QString &name ) |
53 | { | 64 | { |
54 | unsigned char c, i, bitcount; | 65 | unsigned char c, i, bitcount; |
55 | unsigned long ucs4, utf16, bitbuf; | 66 | unsigned long ucs4, utf16, bitbuf; |
56 | unsigned char base64[256], utf8[6]; | 67 | unsigned char base64[256], utf8[6]; |
57 | unsigned long srcPtr = 0; | 68 | unsigned long srcPtr = 0; |
58 | QCString dst = ""; | 69 | QCString dst = ""; |
59 | QCString src = name.ascii(); | 70 | QCString src = name.ascii(); |
60 | 71 | ||
61 | /* initialize modified base64 decoding table */ | 72 | /* initialize modified base64 decoding table */ |
62 | memset(base64, UNDEFINED, sizeof(base64)); | 73 | memset(base64, UNDEFINED, sizeof(base64)); |
63 | for (i = 0; i < sizeof(base64chars); ++i) { | 74 | for (i = 0; i < sizeof(base64chars); ++i) { |
64 | base64[(int)base64chars[i]] = i; | 75 | base64[(int)base64chars[i]] = i; |
65 | } | 76 | } |
66 | 77 | ||
67 | /* loop until end of string */ | 78 | /* loop until end of string */ |
68 | while (srcPtr < src.length ()) { | 79 | while (srcPtr < src.length ()) { |
69 | c = src[srcPtr++]; | 80 | c = src[srcPtr++]; |
70 | /* deal with literal characters and &- */ | 81 | /* deal with literal characters and &- */ |
71 | if (c != '&' || src[srcPtr] == '-') { | 82 | if (c != '&' || src[srcPtr] == '-') { |
72 | /* encode literally */ | 83 | /* encode literally */ |
73 | dst += c; | 84 | dst += c; |
74 | /* skip over the '-' if this is an &- sequence */ | 85 | /* skip over the '-' if this is an &- sequence */ |
75 | if (c == '&') | 86 | if (c == '&') |
76 | srcPtr++; | 87 | srcPtr++; |
77 | } else { | 88 | } else { |
78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | 89 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ |
79 | bitbuf = 0; | 90 | bitbuf = 0; |
80 | bitcount = 0; | 91 | bitcount = 0; |
81 | ucs4 = 0; | 92 | ucs4 = 0; |
82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | 93 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { |
83 | ++srcPtr; | 94 | ++srcPtr; |
84 | bitbuf = (bitbuf << 6) | c; | 95 | bitbuf = (bitbuf << 6) | c; |
85 | bitcount += 6; | 96 | bitcount += 6; |
86 | /* enough bits for a UTF-16 character? */ | 97 | /* enough bits for a UTF-16 character? */ |
87 | if (bitcount >= 16) { | 98 | if (bitcount >= 16) { |
88 | bitcount -= 16; | 99 | bitcount -= 16; |
89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | 100 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; |
90 | /* convert UTF16 to UCS4 */ | 101 | /* convert UTF16 to UCS4 */ |
91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | 102 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { |
92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | 103 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; |
93 | continue; | 104 | continue; |
94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 105 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 106 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
96 | } else { | 107 | } else { |
97 | ucs4 = utf16; | 108 | ucs4 = utf16; |
98 | } | 109 | } |
99 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 110 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
100 | if (ucs4 <= 0x7fUL) { | 111 | if (ucs4 <= 0x7fUL) { |
101 | utf8[0] = ucs4; | 112 | utf8[0] = ucs4; |
102 | i = 1; | 113 | i = 1; |
103 | } else if (ucs4 <= 0x7ffUL) { | 114 | } else if (ucs4 <= 0x7ffUL) { |
104 | utf8[0] = 0xc0 | (ucs4 >> 6); | 115 | utf8[0] = 0xc0 | (ucs4 >> 6); |
105 | utf8[1] = 0x80 | (ucs4 & 0x3f); | 116 | utf8[1] = 0x80 | (ucs4 & 0x3f); |
106 | i = 2; | 117 | i = 2; |
107 | } else if (ucs4 <= 0xffffUL) { | 118 | } else if (ucs4 <= 0xffffUL) { |
108 | utf8[0] = 0xe0 | (ucs4 >> 12); | 119 | utf8[0] = 0xe0 | (ucs4 >> 12); |
109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | 120 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); |
110 | utf8[2] = 0x80 | (ucs4 & 0x3f); | 121 | utf8[2] = 0x80 | (ucs4 & 0x3f); |
111 | i = 3; | 122 | i = 3; |
112 | } else { | 123 | } else { |
113 | utf8[0] = 0xf0 | (ucs4 >> 18); | 124 | utf8[0] = 0xf0 | (ucs4 >> 18); |
114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | 125 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); |
115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | 126 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); |
116 | utf8[3] = 0x80 | (ucs4 & 0x3f); | 127 | utf8[3] = 0x80 | (ucs4 & 0x3f); |
117 | i = 4; | 128 | i = 4; |
118 | } | 129 | } |
119 | /* copy it */ | 130 | /* copy it */ |
120 | for (c = 0; c < i; ++c) { | 131 | for (c = 0; c < i; ++c) { |
121 | dst += utf8[c]; | 132 | dst += utf8[c]; |
122 | } | 133 | } |
123 | } | 134 | } |
124 | } | 135 | } |
125 | /* skip over trailing '-' in modified UTF-7 encoding */ | 136 | /* skip over trailing '-' in modified UTF-7 encoding */ |
126 | if (src[srcPtr] == '-') | 137 | if (src[srcPtr] == '-') |
127 | ++srcPtr; | 138 | ++srcPtr; |
128 | } | 139 | } |
129 | } | 140 | } |
130 | 141 | ||
131 | return QString::fromUtf8( dst.data() ); | 142 | return QString::fromUtf8( dst.data() ); |
132 | } | 143 | } |
133 | 144 | ||
134 | Mail::Mail() | 145 | Mail::Mail() |
135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 146 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
136 | { | 147 | { |
137 | } | 148 | } |
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index 17aa1b0..c5187f5 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -1,403 +1,413 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | 5 | ||
6 | #include "settings.h" | 6 | #include "settings.h" |
7 | #include "defines.h" | 7 | //#include "defines.h" |
8 | |||
9 | #define IMAP_PORT "143" | ||
10 | #define IMAP_SSL_PORT "993" | ||
11 | #define SMTP_PORT "25" | ||
12 | #define SMTP_SSL_PORT "465" | ||
13 | #define POP3_PORT "110" | ||
14 | #define POP3_SSL_PORT "995" | ||
15 | #define NNTP_PORT "119" | ||
16 | #define NNTP_SSL_PORT "563" | ||
17 | |||
8 | 18 | ||
9 | Settings::Settings() | 19 | Settings::Settings() |
10 | : QObject() | 20 | : QObject() |
11 | { | 21 | { |
12 | updateAccounts(); | 22 | updateAccounts(); |
13 | } | 23 | } |
14 | 24 | ||
15 | void Settings::checkDirectory() | 25 | void Settings::checkDirectory() |
16 | { | 26 | { |
17 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 27 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
18 | system( "mkdir -p $HOME/Applications/opiemail" ); | 28 | system( "mkdir -p $HOME/Applications/opiemail" ); |
19 | qDebug( "$HOME/Applications/opiemail created" ); | 29 | qDebug( "$HOME/Applications/opiemail created" ); |
20 | } | 30 | } |
21 | } | 31 | } |
22 | 32 | ||
23 | QList<Account> Settings::getAccounts() | 33 | QList<Account> Settings::getAccounts() |
24 | { | 34 | { |
25 | return accounts; | 35 | return accounts; |
26 | } | 36 | } |
27 | 37 | ||
28 | void Settings::addAccount( Account *account ) | 38 | void Settings::addAccount( Account *account ) |
29 | { | 39 | { |
30 | accounts.append( account ); | 40 | accounts.append( account ); |
31 | } | 41 | } |
32 | 42 | ||
33 | void Settings::delAccount( Account *account ) | 43 | void Settings::delAccount( Account *account ) |
34 | { | 44 | { |
35 | accounts.remove( account ); | 45 | accounts.remove( account ); |
36 | account->remove(); | 46 | account->remove(); |
37 | } | 47 | } |
38 | 48 | ||
39 | void Settings::updateAccounts() | 49 | void Settings::updateAccounts() |
40 | { | 50 | { |
41 | accounts.clear(); | 51 | accounts.clear(); |
42 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 52 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
43 | QStringList::Iterator it; | 53 | QStringList::Iterator it; |
44 | 54 | ||
45 | QStringList imap = dir.entryList( "imap-*" ); | 55 | QStringList imap = dir.entryList( "imap-*" ); |
46 | for ( it = imap.begin(); it != imap.end(); it++ ) { | 56 | for ( it = imap.begin(); it != imap.end(); it++ ) { |
47 | qDebug( "Added IMAP account" ); | 57 | qDebug( "Added IMAP account" ); |
48 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | 58 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); |
49 | accounts.append( account ); | 59 | accounts.append( account ); |
50 | } | 60 | } |
51 | 61 | ||
52 | QStringList pop3 = dir.entryList( "pop3-*" ); | 62 | QStringList pop3 = dir.entryList( "pop3-*" ); |
53 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | 63 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { |
54 | qDebug( "Added POP account" ); | 64 | qDebug( "Added POP account" ); |
55 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | 65 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); |
56 | accounts.append( account ); | 66 | accounts.append( account ); |
57 | } | 67 | } |
58 | 68 | ||
59 | QStringList smtp = dir.entryList( "smtp-*" ); | 69 | QStringList smtp = dir.entryList( "smtp-*" ); |
60 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | 70 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { |
61 | qDebug( "Added SMTP account" ); | 71 | qDebug( "Added SMTP account" ); |
62 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | 72 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); |
63 | accounts.append( account ); | 73 | accounts.append( account ); |
64 | } | 74 | } |
65 | 75 | ||
66 | QStringList nntp = dir.entryList( "nntp-*" ); | 76 | QStringList nntp = dir.entryList( "nntp-*" ); |
67 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | 77 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { |
68 | qDebug( "Added NNTP account" ); | 78 | qDebug( "Added NNTP account" ); |
69 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | 79 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); |
70 | accounts.append( account ); | 80 | accounts.append( account ); |
71 | } | 81 | } |
72 | 82 | ||
73 | readAccounts(); | 83 | readAccounts(); |
74 | } | 84 | } |
75 | 85 | ||
76 | void Settings::saveAccounts() | 86 | void Settings::saveAccounts() |
77 | { | 87 | { |
78 | checkDirectory(); | 88 | checkDirectory(); |
79 | Account *it; | 89 | Account *it; |
80 | 90 | ||
81 | for ( it = accounts.first(); it; it = accounts.next() ) { | 91 | for ( it = accounts.first(); it; it = accounts.next() ) { |
82 | it->save(); | 92 | it->save(); |
83 | } | 93 | } |
84 | } | 94 | } |
85 | 95 | ||
86 | void Settings::readAccounts() | 96 | void Settings::readAccounts() |
87 | { | 97 | { |
88 | checkDirectory(); | 98 | checkDirectory(); |
89 | Account *it; | 99 | Account *it; |
90 | 100 | ||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | 101 | for ( it = accounts.first(); it; it = accounts.next() ) { |
92 | it->read(); | 102 | it->read(); |
93 | } | 103 | } |
94 | } | 104 | } |
95 | 105 | ||
96 | Account::Account() | 106 | Account::Account() |
97 | { | 107 | { |
98 | accountName = "changeMe"; | 108 | accountName = "changeMe"; |
99 | type = "changeMe"; | 109 | type = "changeMe"; |
100 | ssl = false; | 110 | ssl = false; |
101 | } | 111 | } |
102 | 112 | ||
103 | void Account::remove() | 113 | void Account::remove() |
104 | { | 114 | { |
105 | QFile file( getFileName() ); | 115 | QFile file( getFileName() ); |
106 | file.remove(); | 116 | file.remove(); |
107 | } | 117 | } |
108 | 118 | ||
109 | IMAPaccount::IMAPaccount() | 119 | IMAPaccount::IMAPaccount() |
110 | : Account() | 120 | : Account() |
111 | { | 121 | { |
112 | file = IMAPaccount::getUniqueFileName(); | 122 | file = IMAPaccount::getUniqueFileName(); |
113 | accountName = "New IMAP Account"; | 123 | accountName = "New IMAP Account"; |
114 | ssl = false; | 124 | ssl = false; |
115 | type = "IMAP"; | 125 | type = "IMAP"; |
116 | port = IMAP_PORT; | 126 | port = IMAP_PORT; |
117 | } | 127 | } |
118 | 128 | ||
119 | IMAPaccount::IMAPaccount( QString filename ) | 129 | IMAPaccount::IMAPaccount( QString filename ) |
120 | : Account() | 130 | : Account() |
121 | { | 131 | { |
122 | file = filename; | 132 | file = filename; |
123 | accountName = "New IMAP Account"; | 133 | accountName = "New IMAP Account"; |
124 | ssl = false; | 134 | ssl = false; |
125 | type = "IMAP"; | 135 | type = "IMAP"; |
126 | port = IMAP_PORT; | 136 | port = IMAP_PORT; |
127 | } | 137 | } |
128 | 138 | ||
129 | QString IMAPaccount::getUniqueFileName() | 139 | QString IMAPaccount::getUniqueFileName() |
130 | { | 140 | { |
131 | int num = 0; | 141 | int num = 0; |
132 | QString unique; | 142 | QString unique; |
133 | 143 | ||
134 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 144 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
135 | 145 | ||
136 | QStringList imap = dir.entryList( "imap-*" ); | 146 | QStringList imap = dir.entryList( "imap-*" ); |
137 | do { | 147 | do { |
138 | unique.setNum( num++ ); | 148 | unique.setNum( num++ ); |
139 | } while ( imap.contains( "imap-" + unique ) > 0 ); | 149 | } while ( imap.contains( "imap-" + unique ) > 0 ); |
140 | 150 | ||
141 | return unique; | 151 | return unique; |
142 | } | 152 | } |
143 | 153 | ||
144 | void IMAPaccount::read() | 154 | void IMAPaccount::read() |
145 | { | 155 | { |
146 | Config *conf = new Config( getFileName(), Config::File ); | 156 | Config *conf = new Config( getFileName(), Config::File ); |
147 | conf->setGroup( "IMAP Account" ); | 157 | conf->setGroup( "IMAP Account" ); |
148 | accountName = conf->readEntry( "Account","" ); | 158 | accountName = conf->readEntry( "Account","" ); |
149 | if (accountName.isNull()) accountName = ""; | 159 | if (accountName.isNull()) accountName = ""; |
150 | server = conf->readEntry( "Server","" ); | 160 | server = conf->readEntry( "Server","" ); |
151 | if (server.isNull()) server=""; | 161 | if (server.isNull()) server=""; |
152 | port = conf->readEntry( "Port","" ); | 162 | port = conf->readEntry( "Port","" ); |
153 | if (port.isNull()) port="143"; | 163 | if (port.isNull()) port="143"; |
154 | ssl = conf->readBoolEntry( "SSL",false ); | 164 | ssl = conf->readBoolEntry( "SSL",false ); |
155 | user = conf->readEntry( "User","" ); | 165 | user = conf->readEntry( "User","" ); |
156 | if (user.isNull()) user = ""; | 166 | if (user.isNull()) user = ""; |
157 | password = conf->readEntryCrypt( "Password","" ); | 167 | password = conf->readEntryCrypt( "Password","" ); |
158 | if (password.isNull()) password = ""; | 168 | if (password.isNull()) password = ""; |
159 | prefix = conf->readEntry("MailPrefix",""); | 169 | prefix = conf->readEntry("MailPrefix",""); |
160 | if (prefix.isNull()) prefix = ""; | 170 | if (prefix.isNull()) prefix = ""; |
161 | } | 171 | } |
162 | 172 | ||
163 | void IMAPaccount::save() | 173 | void IMAPaccount::save() |
164 | { | 174 | { |
165 | qDebug( "saving " + getFileName() ); | 175 | qDebug( "saving " + getFileName() ); |
166 | Settings::checkDirectory(); | 176 | Settings::checkDirectory(); |
167 | 177 | ||
168 | Config *conf = new Config( getFileName(), Config::File ); | 178 | Config *conf = new Config( getFileName(), Config::File ); |
169 | conf->setGroup( "IMAP Account" ); | 179 | conf->setGroup( "IMAP Account" ); |
170 | conf->writeEntry( "Account", accountName ); | 180 | conf->writeEntry( "Account", accountName ); |
171 | conf->writeEntry( "Server", server ); | 181 | conf->writeEntry( "Server", server ); |
172 | conf->writeEntry( "Port", port ); | 182 | conf->writeEntry( "Port", port ); |
173 | conf->writeEntry( "SSL", ssl ); | 183 | conf->writeEntry( "SSL", ssl ); |
174 | conf->writeEntry( "User", user ); | 184 | conf->writeEntry( "User", user ); |
175 | conf->writeEntryCrypt( "Password", password ); | 185 | conf->writeEntryCrypt( "Password", password ); |
176 | conf->writeEntry( "MailPrefix",prefix); | 186 | conf->writeEntry( "MailPrefix",prefix); |
177 | conf->write(); | 187 | conf->write(); |
178 | } | 188 | } |
179 | 189 | ||
180 | 190 | ||
181 | QString IMAPaccount::getFileName() | 191 | QString IMAPaccount::getFileName() |
182 | { | 192 | { |
183 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | 193 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; |
184 | } | 194 | } |
185 | 195 | ||
186 | POP3account::POP3account() | 196 | POP3account::POP3account() |
187 | : Account() | 197 | : Account() |
188 | { | 198 | { |
189 | file = POP3account::getUniqueFileName(); | 199 | file = POP3account::getUniqueFileName(); |
190 | accountName = "New POP3 Account"; | 200 | accountName = "New POP3 Account"; |
191 | ssl = false; | 201 | ssl = false; |
192 | type = "POP3"; | 202 | type = "POP3"; |
193 | port = POP3_PORT; | 203 | port = POP3_PORT; |
194 | } | 204 | } |
195 | 205 | ||
196 | POP3account::POP3account( QString filename ) | 206 | POP3account::POP3account( QString filename ) |
197 | : Account() | 207 | : Account() |
198 | { | 208 | { |
199 | file = filename; | 209 | file = filename; |
200 | accountName = "New POP3 Account"; | 210 | accountName = "New POP3 Account"; |
201 | ssl = false; | 211 | ssl = false; |
202 | type = "POP3"; | 212 | type = "POP3"; |
203 | port = POP3_PORT; | 213 | port = POP3_PORT; |
204 | } | 214 | } |
205 | 215 | ||
206 | QString POP3account::getUniqueFileName() | 216 | QString POP3account::getUniqueFileName() |
207 | { | 217 | { |
208 | int num = 0; | 218 | int num = 0; |
209 | QString unique; | 219 | QString unique; |
210 | 220 | ||
211 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 221 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
212 | 222 | ||
213 | QStringList imap = dir.entryList( "pop3-*" ); | 223 | QStringList imap = dir.entryList( "pop3-*" ); |
214 | do { | 224 | do { |
215 | unique.setNum( num++ ); | 225 | unique.setNum( num++ ); |
216 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | 226 | } while ( imap.contains( "pop3-" + unique ) > 0 ); |
217 | 227 | ||
218 | return unique; | 228 | return unique; |
219 | } | 229 | } |
220 | 230 | ||
221 | void POP3account::read() | 231 | void POP3account::read() |
222 | { | 232 | { |
223 | Config *conf = new Config( getFileName(), Config::File ); | 233 | Config *conf = new Config( getFileName(), Config::File ); |
224 | conf->setGroup( "POP3 Account" ); | 234 | conf->setGroup( "POP3 Account" ); |
225 | accountName = conf->readEntry( "Account" ); | 235 | accountName = conf->readEntry( "Account" ); |
226 | server = conf->readEntry( "Server" ); | 236 | server = conf->readEntry( "Server" ); |
227 | port = conf->readEntry( "Port" ); | 237 | port = conf->readEntry( "Port" ); |
228 | ssl = conf->readBoolEntry( "SSL" ); | 238 | ssl = conf->readBoolEntry( "SSL" ); |
229 | user = conf->readEntry( "User" ); | 239 | user = conf->readEntry( "User" ); |
230 | password = conf->readEntryCrypt( "Password" ); | 240 | password = conf->readEntryCrypt( "Password" ); |
231 | } | 241 | } |
232 | 242 | ||
233 | void POP3account::save() | 243 | void POP3account::save() |
234 | { | 244 | { |
235 | qDebug( "saving " + getFileName() ); | 245 | qDebug( "saving " + getFileName() ); |
236 | Settings::checkDirectory(); | 246 | Settings::checkDirectory(); |
237 | 247 | ||
238 | Config *conf = new Config( getFileName(), Config::File ); | 248 | Config *conf = new Config( getFileName(), Config::File ); |
239 | conf->setGroup( "POP3 Account" ); | 249 | conf->setGroup( "POP3 Account" ); |
240 | conf->writeEntry( "Account", accountName ); | 250 | conf->writeEntry( "Account", accountName ); |
241 | conf->writeEntry( "Server", server ); | 251 | conf->writeEntry( "Server", server ); |
242 | conf->writeEntry( "Port", port ); | 252 | conf->writeEntry( "Port", port ); |
243 | conf->writeEntry( "SSL", ssl ); | 253 | conf->writeEntry( "SSL", ssl ); |
244 | conf->writeEntry( "User", user ); | 254 | conf->writeEntry( "User", user ); |
245 | conf->writeEntryCrypt( "Password", password ); | 255 | conf->writeEntryCrypt( "Password", password ); |
246 | conf->write(); | 256 | conf->write(); |
247 | } | 257 | } |
248 | 258 | ||
249 | 259 | ||
250 | QString POP3account::getFileName() | 260 | QString POP3account::getFileName() |
251 | { | 261 | { |
252 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | 262 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; |
253 | } | 263 | } |
254 | 264 | ||
255 | SMTPaccount::SMTPaccount() | 265 | SMTPaccount::SMTPaccount() |
256 | : Account() | 266 | : Account() |
257 | { | 267 | { |
258 | file = SMTPaccount::getUniqueFileName(); | 268 | file = SMTPaccount::getUniqueFileName(); |
259 | accountName = "New SMTP Account"; | 269 | accountName = "New SMTP Account"; |
260 | ssl = false; | 270 | ssl = false; |
261 | login = false; | 271 | login = false; |
262 | useCC = false; | 272 | useCC = false; |
263 | useBCC = false; | 273 | useBCC = false; |
264 | useReply = false; | 274 | useReply = false; |
265 | type = "SMTP"; | 275 | type = "SMTP"; |
266 | port = SMTP_PORT; | 276 | port = SMTP_PORT; |
267 | } | 277 | } |
268 | 278 | ||
269 | SMTPaccount::SMTPaccount( QString filename ) | 279 | SMTPaccount::SMTPaccount( QString filename ) |
270 | : Account() | 280 | : Account() |
271 | { | 281 | { |
272 | file = filename; | 282 | file = filename; |
273 | accountName = "New SMTP Account"; | 283 | accountName = "New SMTP Account"; |
274 | ssl = false; | 284 | ssl = false; |
275 | login = false; | 285 | login = false; |
276 | type = "SMTP"; | 286 | type = "SMTP"; |
277 | port = SMTP_PORT; | 287 | port = SMTP_PORT; |
278 | } | 288 | } |
279 | 289 | ||
280 | QString SMTPaccount::getUniqueFileName() | 290 | QString SMTPaccount::getUniqueFileName() |
281 | { | 291 | { |
282 | int num = 0; | 292 | int num = 0; |
283 | QString unique; | 293 | QString unique; |
284 | 294 | ||
285 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 295 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
286 | 296 | ||
287 | QStringList imap = dir.entryList( "smtp-*" ); | 297 | QStringList imap = dir.entryList( "smtp-*" ); |
288 | do { | 298 | do { |
289 | unique.setNum( num++ ); | 299 | unique.setNum( num++ ); |
290 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | 300 | } while ( imap.contains( "smtp-" + unique ) > 0 ); |
291 | 301 | ||
292 | return unique; | 302 | return unique; |
293 | } | 303 | } |
294 | 304 | ||
295 | void SMTPaccount::read() | 305 | void SMTPaccount::read() |
296 | { | 306 | { |
297 | Config *conf = new Config( getFileName(), Config::File ); | 307 | Config *conf = new Config( getFileName(), Config::File ); |
298 | conf->setGroup( "SMTP Account" ); | 308 | conf->setGroup( "SMTP Account" ); |
299 | accountName = conf->readEntry( "Account" ); | 309 | accountName = conf->readEntry( "Account" ); |
300 | server = conf->readEntry( "Server" ); | 310 | server = conf->readEntry( "Server" ); |
301 | port = conf->readEntry( "Port" ); | 311 | port = conf->readEntry( "Port" ); |
302 | ssl = conf->readBoolEntry( "SSL" ); | 312 | ssl = conf->readBoolEntry( "SSL" ); |
303 | login = conf->readBoolEntry( "Login" ); | 313 | login = conf->readBoolEntry( "Login" ); |
304 | user = conf->readEntry( "User" ); | 314 | user = conf->readEntry( "User" ); |
305 | password = conf->readEntryCrypt( "Password" ); | 315 | password = conf->readEntryCrypt( "Password" ); |
306 | } | 316 | } |
307 | 317 | ||
308 | void SMTPaccount::save() | 318 | void SMTPaccount::save() |
309 | { | 319 | { |
310 | qDebug( "saving " + getFileName() ); | 320 | qDebug( "saving " + getFileName() ); |
311 | Settings::checkDirectory(); | 321 | Settings::checkDirectory(); |
312 | 322 | ||
313 | Config *conf = new Config( getFileName(), Config::File ); | 323 | Config *conf = new Config( getFileName(), Config::File ); |
314 | conf->setGroup( "SMTP Account" ); | 324 | conf->setGroup( "SMTP Account" ); |
315 | conf->writeEntry( "Account", accountName ); | 325 | conf->writeEntry( "Account", accountName ); |
316 | conf->writeEntry( "Server", server ); | 326 | conf->writeEntry( "Server", server ); |
317 | conf->writeEntry( "Port", port ); | 327 | conf->writeEntry( "Port", port ); |
318 | conf->writeEntry( "SSL", ssl ); | 328 | conf->writeEntry( "SSL", ssl ); |
319 | conf->writeEntry( "Login", login ); | 329 | conf->writeEntry( "Login", login ); |
320 | conf->writeEntry( "User", user ); | 330 | conf->writeEntry( "User", user ); |
321 | conf->writeEntryCrypt( "Password", password ); | 331 | conf->writeEntryCrypt( "Password", password ); |
322 | conf->write(); | 332 | conf->write(); |
323 | } | 333 | } |
324 | 334 | ||
325 | 335 | ||
326 | QString SMTPaccount::getFileName() | 336 | QString SMTPaccount::getFileName() |
327 | { | 337 | { |
328 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | 338 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; |
329 | } | 339 | } |
330 | 340 | ||
331 | NNTPaccount::NNTPaccount() | 341 | NNTPaccount::NNTPaccount() |
332 | : Account() | 342 | : Account() |
333 | { | 343 | { |
334 | file = NNTPaccount::getUniqueFileName(); | 344 | file = NNTPaccount::getUniqueFileName(); |
335 | accountName = "New NNTP Account"; | 345 | accountName = "New NNTP Account"; |
336 | ssl = false; | 346 | ssl = false; |
337 | login = false; | 347 | login = false; |
338 | type = "NNTP"; | 348 | type = "NNTP"; |
339 | port = NNTP_PORT; | 349 | port = NNTP_PORT; |
340 | } | 350 | } |
341 | 351 | ||
342 | NNTPaccount::NNTPaccount( QString filename ) | 352 | NNTPaccount::NNTPaccount( QString filename ) |
343 | : Account() | 353 | : Account() |
344 | { | 354 | { |
345 | file = filename; | 355 | file = filename; |
346 | accountName = "New NNTP Account"; | 356 | accountName = "New NNTP Account"; |
347 | ssl = false; | 357 | ssl = false; |
348 | login = false; | 358 | login = false; |
349 | type = "NNTP"; | 359 | type = "NNTP"; |
350 | port = NNTP_PORT; | 360 | port = NNTP_PORT; |
351 | } | 361 | } |
352 | 362 | ||
353 | QString NNTPaccount::getUniqueFileName() | 363 | QString NNTPaccount::getUniqueFileName() |
354 | { | 364 | { |
355 | int num = 0; | 365 | int num = 0; |
356 | QString unique; | 366 | QString unique; |
357 | 367 | ||
358 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 368 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
359 | 369 | ||
360 | QStringList imap = dir.entryList( "nntp-*" ); | 370 | QStringList imap = dir.entryList( "nntp-*" ); |
361 | do { | 371 | do { |
362 | unique.setNum( num++ ); | 372 | unique.setNum( num++ ); |
363 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | 373 | } while ( imap.contains( "nntp-" + unique ) > 0 ); |
364 | 374 | ||
365 | return unique; | 375 | return unique; |
366 | } | 376 | } |
367 | 377 | ||
368 | void NNTPaccount::read() | 378 | void NNTPaccount::read() |
369 | { | 379 | { |
370 | Config *conf = new Config( getFileName(), Config::File ); | 380 | Config *conf = new Config( getFileName(), Config::File ); |
371 | conf->setGroup( "NNTP Account" ); | 381 | conf->setGroup( "NNTP Account" ); |
372 | accountName = conf->readEntry( "Account" ); | 382 | accountName = conf->readEntry( "Account" ); |
373 | server = conf->readEntry( "Server" ); | 383 | server = conf->readEntry( "Server" ); |
374 | port = conf->readEntry( "Port" ); | 384 | port = conf->readEntry( "Port" ); |
375 | ssl = conf->readBoolEntry( "SSL" ); | 385 | ssl = conf->readBoolEntry( "SSL" ); |
376 | login = conf->readBoolEntry( "Login" ); | 386 | login = conf->readBoolEntry( "Login" ); |
377 | user = conf->readEntry( "User" ); | 387 | user = conf->readEntry( "User" ); |
378 | password = conf->readEntryCrypt( "Password" ); | 388 | password = conf->readEntryCrypt( "Password" ); |
379 | } | 389 | } |
380 | 390 | ||
381 | void NNTPaccount::save() | 391 | void NNTPaccount::save() |
382 | { | 392 | { |
383 | qDebug( "saving " + getFileName() ); | 393 | qDebug( "saving " + getFileName() ); |
384 | Settings::checkDirectory(); | 394 | Settings::checkDirectory(); |
385 | 395 | ||
386 | Config *conf = new Config( getFileName(), Config::File ); | 396 | Config *conf = new Config( getFileName(), Config::File ); |
387 | conf->setGroup( "NNTP Account" ); | 397 | conf->setGroup( "NNTP Account" ); |
388 | conf->writeEntry( "Account", accountName ); | 398 | conf->writeEntry( "Account", accountName ); |
389 | conf->writeEntry( "Server", server ); | 399 | conf->writeEntry( "Server", server ); |
390 | conf->writeEntry( "Port", port ); | 400 | conf->writeEntry( "Port", port ); |
391 | conf->writeEntry( "SSL", ssl ); | 401 | conf->writeEntry( "SSL", ssl ); |
392 | conf->writeEntry( "Login", login ); | 402 | conf->writeEntry( "Login", login ); |
393 | conf->writeEntry( "User", user ); | 403 | conf->writeEntry( "User", user ); |
394 | conf->writeEntryCrypt( "Password", password ); | 404 | conf->writeEntryCrypt( "Password", password ); |
395 | conf->write(); | 405 | conf->write(); |
396 | } | 406 | } |
397 | 407 | ||
398 | 408 | ||
399 | QString NNTPaccount::getFileName() | 409 | QString NNTPaccount::getFileName() |
400 | { | 410 | { |
401 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | 411 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; |
402 | } | 412 | } |
403 | 413 | ||
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 7e03af9..b9c4ff2 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,732 +1,734 @@ | |||
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 <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
12 | 12 | ||
13 | #include <libetpan/libetpan.h> | 13 | #include <libetpan/libetpan.h> |
14 | 14 | ||
15 | #include "smtpwrapper.h" | 15 | #include "smtpwrapper.h" |
16 | #include "mailwrapper.h" | 16 | #include "mailwrapper.h" |
17 | #include "mboxwrapper.h" | 17 | #include "mboxwrapper.h" |
18 | #include "logindialog.h" | 18 | #include "logindialog.h" |
19 | #include "mailtypes.h" | 19 | #include "mailtypes.h" |
20 | #include "defines.h" | 20 | //#include "defines.h" |
21 | #include "sendmailprogress.h" | 21 | #include "sendmailprogress.h" |
22 | 22 | ||
23 | #define USER_AGENT "OpieMail v0.1" | ||
24 | |||
23 | progressMailSend*SMTPwrapper::sendProgress = 0; | 25 | progressMailSend*SMTPwrapper::sendProgress = 0; |
24 | 26 | ||
25 | SMTPwrapper::SMTPwrapper( Settings *s ) | 27 | SMTPwrapper::SMTPwrapper( Settings *s ) |
26 | : QObject() | 28 | : QObject() |
27 | { | 29 | { |
28 | settings = s; | 30 | settings = s; |
29 | Config cfg( "mail" ); | 31 | Config cfg( "mail" ); |
30 | cfg.setGroup( "Status" ); | 32 | cfg.setGroup( "Status" ); |
31 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 33 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
32 | emit queuedMails( m_queuedMail ); | 34 | emit queuedMails( m_queuedMail ); |
33 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); | 35 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); |
34 | } | 36 | } |
35 | 37 | ||
36 | void SMTPwrapper::emitQCop( int queued ) { | 38 | void SMTPwrapper::emitQCop( int queued ) { |
37 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 39 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
38 | env << queued; | 40 | env << queued; |
39 | } | 41 | } |
40 | 42 | ||
41 | QString SMTPwrapper::mailsmtpError( int errnum ) | 43 | QString SMTPwrapper::mailsmtpError( int errnum ) |
42 | { | 44 | { |
43 | switch ( errnum ) { | 45 | switch ( errnum ) { |
44 | case MAILSMTP_NO_ERROR: | 46 | case MAILSMTP_NO_ERROR: |
45 | return tr( "No error" ); | 47 | return tr( "No error" ); |
46 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 48 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
47 | return tr( "Unexpected error code" ); | 49 | return tr( "Unexpected error code" ); |
48 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 50 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
49 | return tr( "Service not available" ); | 51 | return tr( "Service not available" ); |
50 | case MAILSMTP_ERROR_STREAM: | 52 | case MAILSMTP_ERROR_STREAM: |
51 | return tr( "Stream error" ); | 53 | return tr( "Stream error" ); |
52 | case MAILSMTP_ERROR_HOSTNAME: | 54 | case MAILSMTP_ERROR_HOSTNAME: |
53 | return tr( "gethostname() failed" ); | 55 | return tr( "gethostname() failed" ); |
54 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 56 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
55 | return tr( "Not implemented" ); | 57 | return tr( "Not implemented" ); |
56 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 58 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
57 | return tr( "Error, action not taken" ); | 59 | return tr( "Error, action not taken" ); |
58 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 60 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
59 | return tr( "Data exceeds storage allocation" ); | 61 | return tr( "Data exceeds storage allocation" ); |
60 | case MAILSMTP_ERROR_IN_PROCESSING: | 62 | case MAILSMTP_ERROR_IN_PROCESSING: |
61 | return tr( "Error in processing" ); | 63 | return tr( "Error in processing" ); |
62 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 64 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
63 | // return tr( "Insufficient system storage" ); | 65 | // return tr( "Insufficient system storage" ); |
64 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 66 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
65 | return tr( "Mailbox unavailable" ); | 67 | return tr( "Mailbox unavailable" ); |
66 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 68 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
67 | return tr( "Mailbox name not allowed" ); | 69 | return tr( "Mailbox name not allowed" ); |
68 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 70 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
69 | return tr( "Bad command sequence" ); | 71 | return tr( "Bad command sequence" ); |
70 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 72 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
71 | return tr( "User not local" ); | 73 | return tr( "User not local" ); |
72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 74 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
73 | return tr( "Transaction failed" ); | 75 | return tr( "Transaction failed" ); |
74 | case MAILSMTP_ERROR_MEMORY: | 76 | case MAILSMTP_ERROR_MEMORY: |
75 | return tr( "Memory error" ); | 77 | return tr( "Memory error" ); |
76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 78 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
77 | return tr( "Connection refused" ); | 79 | return tr( "Connection refused" ); |
78 | default: | 80 | default: |
79 | return tr( "Unknown error code" ); | 81 | return tr( "Unknown error code" ); |
80 | } | 82 | } |
81 | } | 83 | } |
82 | 84 | ||
83 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 85 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
84 | { | 86 | { |
85 | return mailimf_mailbox_new( strdup( name.latin1() ), | 87 | return mailimf_mailbox_new( strdup( name.latin1() ), |
86 | strdup( mail.latin1() ) ); | 88 | strdup( mail.latin1() ) ); |
87 | } | 89 | } |
88 | 90 | ||
89 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 91 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
90 | { | 92 | { |
91 | mailimf_address_list *addresses; | 93 | mailimf_address_list *addresses; |
92 | 94 | ||
93 | if ( addr.isEmpty() ) return NULL; | 95 | if ( addr.isEmpty() ) return NULL; |
94 | 96 | ||
95 | addresses = mailimf_address_list_new_empty(); | 97 | addresses = mailimf_address_list_new_empty(); |
96 | 98 | ||
97 | bool literal_open = false; | 99 | bool literal_open = false; |
98 | unsigned int startpos = 0; | 100 | unsigned int startpos = 0; |
99 | QStringList list; | 101 | QStringList list; |
100 | QString s; | 102 | QString s; |
101 | unsigned int i = 0; | 103 | unsigned int i = 0; |
102 | for (; i < addr.length();++i) { | 104 | for (; i < addr.length();++i) { |
103 | switch (addr[i]) { | 105 | switch (addr[i]) { |
104 | case '\"': | 106 | case '\"': |
105 | literal_open = !literal_open; | 107 | literal_open = !literal_open; |
106 | break; | 108 | break; |
107 | case ',': | 109 | case ',': |
108 | if (!literal_open) { | 110 | if (!literal_open) { |
109 | s = addr.mid(startpos,i-startpos); | 111 | s = addr.mid(startpos,i-startpos); |
110 | if (!s.isEmpty()) { | 112 | if (!s.isEmpty()) { |
111 | list.append(s); | 113 | list.append(s); |
112 | qDebug("Appended %s",s.latin1()); | 114 | qDebug("Appended %s",s.latin1()); |
113 | } | 115 | } |
114 | // !!!! this is a MUST BE! | 116 | // !!!! this is a MUST BE! |
115 | startpos = ++i; | 117 | startpos = ++i; |
116 | } | 118 | } |
117 | break; | 119 | break; |
118 | default: | 120 | default: |
119 | break; | 121 | break; |
120 | } | 122 | } |
121 | } | 123 | } |
122 | s = addr.mid(startpos,i-startpos); | 124 | s = addr.mid(startpos,i-startpos); |
123 | if (!s.isEmpty()) { | 125 | if (!s.isEmpty()) { |
124 | list.append(s); | 126 | list.append(s); |
125 | qDebug("Appended %s",s.latin1()); | 127 | qDebug("Appended %s",s.latin1()); |
126 | } | 128 | } |
127 | QStringList::Iterator it; | 129 | QStringList::Iterator it; |
128 | for ( it = list.begin(); it != list.end(); it++ ) { | 130 | for ( it = list.begin(); it != list.end(); it++ ) { |
129 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 131 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
130 | if ( err != MAILIMF_NO_ERROR ) { | 132 | if ( err != MAILIMF_NO_ERROR ) { |
131 | qDebug( "Error parsing" ); | 133 | qDebug( "Error parsing" ); |
132 | qDebug( *it ); | 134 | qDebug( *it ); |
133 | } else { | 135 | } else { |
134 | qDebug( "Parse success! %s",(*it).latin1()); | 136 | qDebug( "Parse success! %s",(*it).latin1()); |
135 | } | 137 | } |
136 | } | 138 | } |
137 | return addresses; | 139 | return addresses; |
138 | } | 140 | } |
139 | 141 | ||
140 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 142 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
141 | { | 143 | { |
142 | mailimf_fields *fields; | 144 | mailimf_fields *fields; |
143 | mailimf_field *xmailer; | 145 | mailimf_field *xmailer; |
144 | mailimf_mailbox *sender=0,*fromBox=0; | 146 | mailimf_mailbox *sender=0,*fromBox=0; |
145 | mailimf_mailbox_list *from=0; | 147 | mailimf_mailbox_list *from=0; |
146 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 148 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
147 | char *subject = strdup( mail.getSubject().latin1() ); | 149 | char *subject = strdup( mail.getSubject().latin1() ); |
148 | int err; | 150 | int err; |
149 | 151 | ||
150 | sender = newMailbox( mail.getName(), mail.getMail() ); | 152 | sender = newMailbox( mail.getName(), mail.getMail() ); |
151 | if ( sender == NULL ) goto err_free; | 153 | if ( sender == NULL ) goto err_free; |
152 | 154 | ||
153 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 155 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
154 | if ( fromBox == NULL ) goto err_free_sender; | 156 | if ( fromBox == NULL ) goto err_free_sender; |
155 | 157 | ||
156 | from = mailimf_mailbox_list_new_empty(); | 158 | from = mailimf_mailbox_list_new_empty(); |
157 | if ( from == NULL ) goto err_free_fromBox; | 159 | if ( from == NULL ) goto err_free_fromBox; |
158 | 160 | ||
159 | err = mailimf_mailbox_list_add( from, fromBox ); | 161 | err = mailimf_mailbox_list_add( from, fromBox ); |
160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 162 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
161 | 163 | ||
162 | to = parseAddresses( mail.getTo() ); | 164 | to = parseAddresses( mail.getTo() ); |
163 | if ( to == NULL ) goto err_free_from; | 165 | if ( to == NULL ) goto err_free_from; |
164 | 166 | ||
165 | cc = parseAddresses( mail.getCC() ); | 167 | cc = parseAddresses( mail.getCC() ); |
166 | bcc = parseAddresses( mail.getBCC() ); | 168 | bcc = parseAddresses( mail.getBCC() ); |
167 | reply = parseAddresses( mail.getReply() ); | 169 | reply = parseAddresses( mail.getReply() ); |
168 | 170 | ||
169 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 171 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
170 | NULL, NULL, subject ); | 172 | NULL, NULL, subject ); |
171 | if ( fields == NULL ) goto err_free_reply; | 173 | if ( fields == NULL ) goto err_free_reply; |
172 | 174 | ||
173 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 175 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
174 | strdup( USER_AGENT ) ); | 176 | strdup( USER_AGENT ) ); |
175 | if ( xmailer == NULL ) goto err_free_fields; | 177 | if ( xmailer == NULL ) goto err_free_fields; |
176 | 178 | ||
177 | err = mailimf_fields_add( fields, xmailer ); | 179 | err = mailimf_fields_add( fields, xmailer ); |
178 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 180 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
179 | 181 | ||
180 | return fields; // Success :) | 182 | return fields; // Success :) |
181 | 183 | ||
182 | err_free_xmailer: | 184 | err_free_xmailer: |
183 | if (xmailer) mailimf_field_free( xmailer ); | 185 | if (xmailer) mailimf_field_free( xmailer ); |
184 | err_free_fields: | 186 | err_free_fields: |
185 | if (fields) mailimf_fields_free( fields ); | 187 | if (fields) mailimf_fields_free( fields ); |
186 | err_free_reply: | 188 | err_free_reply: |
187 | if (reply) mailimf_address_list_free( reply ); | 189 | if (reply) mailimf_address_list_free( reply ); |
188 | if (bcc) mailimf_address_list_free( bcc ); | 190 | if (bcc) mailimf_address_list_free( bcc ); |
189 | if (cc) mailimf_address_list_free( cc ); | 191 | if (cc) mailimf_address_list_free( cc ); |
190 | if (to) mailimf_address_list_free( to ); | 192 | if (to) mailimf_address_list_free( to ); |
191 | err_free_from: | 193 | err_free_from: |
192 | if (from) mailimf_mailbox_list_free( from ); | 194 | if (from) mailimf_mailbox_list_free( from ); |
193 | err_free_fromBox: | 195 | err_free_fromBox: |
194 | mailimf_mailbox_free( fromBox ); | 196 | mailimf_mailbox_free( fromBox ); |
195 | err_free_sender: | 197 | err_free_sender: |
196 | if (sender) mailimf_mailbox_free( sender ); | 198 | if (sender) mailimf_mailbox_free( sender ); |
197 | err_free: | 199 | err_free: |
198 | if (subject) free( subject ); | 200 | if (subject) free( subject ); |
199 | qDebug( "createImfFields - error" ); | 201 | qDebug( "createImfFields - error" ); |
200 | 202 | ||
201 | return NULL; // Error :( | 203 | return NULL; // Error :( |
202 | } | 204 | } |
203 | 205 | ||
204 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 206 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
205 | { | 207 | { |
206 | mailmime *txtPart; | 208 | mailmime *txtPart; |
207 | mailmime_fields *fields; | 209 | mailmime_fields *fields; |
208 | mailmime_content *content; | 210 | mailmime_content *content; |
209 | mailmime_parameter *param; | 211 | mailmime_parameter *param; |
210 | int err; | 212 | int err; |
211 | 213 | ||
212 | param = mailmime_parameter_new( strdup( "charset" ), | 214 | param = mailmime_parameter_new( strdup( "charset" ), |
213 | strdup( "iso-8859-1" ) ); | 215 | strdup( "iso-8859-1" ) ); |
214 | if ( param == NULL ) goto err_free; | 216 | if ( param == NULL ) goto err_free; |
215 | 217 | ||
216 | content = mailmime_content_new_with_str( "text/plain" ); | 218 | content = mailmime_content_new_with_str( "text/plain" ); |
217 | if ( content == NULL ) goto err_free_param; | 219 | if ( content == NULL ) goto err_free_param; |
218 | 220 | ||
219 | err = clist_append( content->ct_parameters, param ); | 221 | err = clist_append( content->ct_parameters, param ); |
220 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 222 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
221 | 223 | ||
222 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 224 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
223 | if ( fields == NULL ) goto err_free_content; | 225 | if ( fields == NULL ) goto err_free_content; |
224 | 226 | ||
225 | txtPart = mailmime_new_empty( content, fields ); | 227 | txtPart = mailmime_new_empty( content, fields ); |
226 | if ( txtPart == NULL ) goto err_free_fields; | 228 | if ( txtPart == NULL ) goto err_free_fields; |
227 | 229 | ||
228 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 230 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
229 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 231 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
230 | 232 | ||
231 | return txtPart; // Success :) | 233 | return txtPart; // Success :) |
232 | 234 | ||
233 | err_free_txtPart: | 235 | err_free_txtPart: |
234 | mailmime_free( txtPart ); | 236 | mailmime_free( txtPart ); |
235 | err_free_fields: | 237 | err_free_fields: |
236 | mailmime_fields_free( fields ); | 238 | mailmime_fields_free( fields ); |
237 | err_free_content: | 239 | err_free_content: |
238 | mailmime_content_free( content ); | 240 | mailmime_content_free( content ); |
239 | err_free_param: | 241 | err_free_param: |
240 | mailmime_parameter_free( param ); | 242 | mailmime_parameter_free( param ); |
241 | err_free: | 243 | err_free: |
242 | qDebug( "buildTxtPart - error" ); | 244 | qDebug( "buildTxtPart - error" ); |
243 | 245 | ||
244 | return NULL; // Error :( | 246 | return NULL; // Error :( |
245 | } | 247 | } |
246 | 248 | ||
247 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) | 249 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
248 | { | 250 | { |
249 | mailmime * filePart = 0; | 251 | mailmime * filePart = 0; |
250 | mailmime_fields * fields = 0; | 252 | mailmime_fields * fields = 0; |
251 | mailmime_content * content = 0; | 253 | mailmime_content * content = 0; |
252 | mailmime_parameter * param = 0; | 254 | mailmime_parameter * param = 0; |
253 | char*name = 0; | 255 | char*name = 0; |
254 | char*file = 0; | 256 | char*file = 0; |
255 | int err; | 257 | int err; |
256 | 258 | ||
257 | int pos = filename.findRev( '/' ); | 259 | int pos = filename.findRev( '/' ); |
258 | 260 | ||
259 | if (filename.length()>0) { | 261 | if (filename.length()>0) { |
260 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 262 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
261 | name = strdup( tmp.latin1() ); // just filename | 263 | name = strdup( tmp.latin1() ); // just filename |
262 | file = strdup( filename.latin1() ); // full name with path | 264 | file = strdup( filename.latin1() ); // full name with path |
263 | } | 265 | } |
264 | 266 | ||
265 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 267 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
266 | int mechanism = MAILMIME_MECHANISM_BASE64; | 268 | int mechanism = MAILMIME_MECHANISM_BASE64; |
267 | 269 | ||
268 | if ( mimetype.startsWith( "text/" ) ) { | 270 | if ( mimetype.startsWith( "text/" ) ) { |
269 | param = mailmime_parameter_new( strdup( "charset" ), | 271 | param = mailmime_parameter_new( strdup( "charset" ), |
270 | strdup( "iso-8859-1" ) ); | 272 | strdup( "iso-8859-1" ) ); |
271 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 273 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
272 | } | 274 | } |
273 | 275 | ||
274 | fields = mailmime_fields_new_filename( | 276 | fields = mailmime_fields_new_filename( |
275 | disptype, name, | 277 | disptype, name, |
276 | mechanism ); | 278 | mechanism ); |
277 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 279 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
278 | if (content!=0 && fields != 0) { | 280 | if (content!=0 && fields != 0) { |
279 | if (param) { | 281 | if (param) { |
280 | clist_append(content->ct_parameters,param); | 282 | clist_append(content->ct_parameters,param); |
281 | param = 0; | 283 | param = 0; |
282 | } | 284 | } |
283 | if (filename.length()>0) { | 285 | if (filename.length()>0) { |
284 | QFileInfo f(filename); | 286 | QFileInfo f(filename); |
285 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 287 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
286 | clist_append(content->ct_parameters,param); | 288 | clist_append(content->ct_parameters,param); |
287 | param = 0; | 289 | param = 0; |
288 | } | 290 | } |
289 | filePart = mailmime_new_empty( content, fields ); | 291 | filePart = mailmime_new_empty( content, fields ); |
290 | } | 292 | } |
291 | if (filePart) { | 293 | if (filePart) { |
292 | if (filename.length()>0) { | 294 | if (filename.length()>0) { |
293 | err = mailmime_set_body_file( filePart, file ); | 295 | err = mailmime_set_body_file( filePart, file ); |
294 | } else { | 296 | } else { |
295 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | 297 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); |
296 | } | 298 | } |
297 | if (err != MAILIMF_NO_ERROR) { | 299 | if (err != MAILIMF_NO_ERROR) { |
298 | qDebug("Error setting body with file %s",file); | 300 | qDebug("Error setting body with file %s",file); |
299 | mailmime_free( filePart ); | 301 | mailmime_free( filePart ); |
300 | filePart = 0; | 302 | filePart = 0; |
301 | } | 303 | } |
302 | } | 304 | } |
303 | 305 | ||
304 | if (!filePart) { | 306 | if (!filePart) { |
305 | if ( param != NULL ) { | 307 | if ( param != NULL ) { |
306 | mailmime_parameter_free( param ); | 308 | mailmime_parameter_free( param ); |
307 | } | 309 | } |
308 | if (content) { | 310 | if (content) { |
309 | mailmime_content_free( content ); | 311 | mailmime_content_free( content ); |
310 | } | 312 | } |
311 | if (fields) { | 313 | if (fields) { |
312 | mailmime_fields_free( fields ); | 314 | mailmime_fields_free( fields ); |
313 | } else { | 315 | } else { |
314 | if (name) { | 316 | if (name) { |
315 | free( name ); | 317 | free( name ); |
316 | } | 318 | } |
317 | if (file) { | 319 | if (file) { |
318 | free( file ); | 320 | free( file ); |
319 | } | 321 | } |
320 | } | 322 | } |
321 | } | 323 | } |
322 | return filePart; // Success :) | 324 | return filePart; // Success :) |
323 | 325 | ||
324 | } | 326 | } |
325 | 327 | ||
326 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 328 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
327 | { | 329 | { |
328 | const Attachment *it; | 330 | const Attachment *it; |
329 | unsigned int count = files.count(); | 331 | unsigned int count = files.count(); |
330 | qDebug("List contains %i values",count); | 332 | qDebug("List contains %i values",count); |
331 | for ( unsigned int i = 0; i < count; ++i ) { | 333 | for ( unsigned int i = 0; i < count; ++i ) { |
332 | qDebug( "Adding file" ); | 334 | qDebug( "Adding file" ); |
333 | mailmime *filePart; | 335 | mailmime *filePart; |
334 | int err; | 336 | int err; |
335 | it = ((QList<Attachment>)files).at(i); | 337 | it = ((QList<Attachment>)files).at(i); |
336 | 338 | ||
337 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 339 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
338 | if ( filePart == NULL ) { | 340 | if ( filePart == NULL ) { |
339 | qDebug( "addFileParts: error adding file:" ); | 341 | qDebug( "addFileParts: error adding file:" ); |
340 | qDebug( it->getFileName() ); | 342 | qDebug( it->getFileName() ); |
341 | continue; | 343 | continue; |
342 | } | 344 | } |
343 | err = mailmime_smart_add_part( message, filePart ); | 345 | err = mailmime_smart_add_part( message, filePart ); |
344 | if ( err != MAILIMF_NO_ERROR ) { | 346 | if ( err != MAILIMF_NO_ERROR ) { |
345 | mailmime_free( filePart ); | 347 | mailmime_free( filePart ); |
346 | qDebug("error smart add"); | 348 | qDebug("error smart add"); |
347 | } | 349 | } |
348 | } | 350 | } |
349 | } | 351 | } |
350 | 352 | ||
351 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 353 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
352 | { | 354 | { |
353 | mailmime *message, *txtPart; | 355 | mailmime *message, *txtPart; |
354 | mailimf_fields *fields; | 356 | mailimf_fields *fields; |
355 | int err; | 357 | int err; |
356 | 358 | ||
357 | fields = createImfFields( mail ); | 359 | fields = createImfFields( mail ); |
358 | if ( fields == NULL ) goto err_free; | 360 | if ( fields == NULL ) goto err_free; |
359 | 361 | ||
360 | message = mailmime_new_message_data( NULL ); | 362 | message = mailmime_new_message_data( NULL ); |
361 | if ( message == NULL ) goto err_free_fields; | 363 | if ( message == NULL ) goto err_free_fields; |
362 | 364 | ||
363 | mailmime_set_imf_fields( message, fields ); | 365 | mailmime_set_imf_fields( message, fields ); |
364 | 366 | ||
365 | txtPart = buildTxtPart( mail.getMessage() ); | 367 | txtPart = buildTxtPart( mail.getMessage() ); |
366 | 368 | ||
367 | if ( txtPart == NULL ) goto err_free_message; | 369 | if ( txtPart == NULL ) goto err_free_message; |
368 | 370 | ||
369 | err = mailmime_smart_add_part( message, txtPart ); | 371 | err = mailmime_smart_add_part( message, txtPart ); |
370 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 372 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
371 | 373 | ||
372 | addFileParts( message, mail.getAttachments() ); | 374 | addFileParts( message, mail.getAttachments() ); |
373 | 375 | ||
374 | return message; // Success :) | 376 | return message; // Success :) |
375 | 377 | ||
376 | err_free_txtPart: | 378 | err_free_txtPart: |
377 | mailmime_free( txtPart ); | 379 | mailmime_free( txtPart ); |
378 | err_free_message: | 380 | err_free_message: |
379 | mailmime_free( message ); | 381 | mailmime_free( message ); |
380 | err_free_fields: | 382 | err_free_fields: |
381 | mailimf_fields_free( fields ); | 383 | mailimf_fields_free( fields ); |
382 | err_free: | 384 | err_free: |
383 | qDebug( "createMimeMail: error" ); | 385 | qDebug( "createMimeMail: error" ); |
384 | 386 | ||
385 | return NULL; // Error :( | 387 | return NULL; // Error :( |
386 | } | 388 | } |
387 | 389 | ||
388 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 390 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
389 | { | 391 | { |
390 | mailimf_field *field; | 392 | mailimf_field *field; |
391 | clistiter *it; | 393 | clistiter *it; |
392 | 394 | ||
393 | it = clist_begin( fields->fld_list ); | 395 | it = clist_begin( fields->fld_list ); |
394 | while ( it ) { | 396 | while ( it ) { |
395 | field = (mailimf_field *) it->data; | 397 | field = (mailimf_field *) it->data; |
396 | if ( field->fld_type == type ) { | 398 | if ( field->fld_type == type ) { |
397 | return field; | 399 | return field; |
398 | } | 400 | } |
399 | it = it->next; | 401 | it = it->next; |
400 | } | 402 | } |
401 | 403 | ||
402 | return NULL; | 404 | return NULL; |
403 | } | 405 | } |
404 | 406 | ||
405 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 407 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
406 | { | 408 | { |
407 | clistiter *it, *it2; | 409 | clistiter *it, *it2; |
408 | 410 | ||
409 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 411 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
410 | mailimf_address *addr; | 412 | mailimf_address *addr; |
411 | addr = (mailimf_address *) it->data; | 413 | addr = (mailimf_address *) it->data; |
412 | 414 | ||
413 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 415 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
414 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 416 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
415 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 417 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
416 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 418 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
417 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 419 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
418 | mailimf_mailbox *mbox; | 420 | mailimf_mailbox *mbox; |
419 | mbox = (mailimf_mailbox *) it2->data; | 421 | mbox = (mailimf_mailbox *) it2->data; |
420 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 422 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
421 | } | 423 | } |
422 | } | 424 | } |
423 | } | 425 | } |
424 | } | 426 | } |
425 | 427 | ||
426 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 428 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
427 | { | 429 | { |
428 | clist *rcptList; | 430 | clist *rcptList; |
429 | mailimf_field *field; | 431 | mailimf_field *field; |
430 | 432 | ||
431 | rcptList = esmtp_address_list_new(); | 433 | rcptList = esmtp_address_list_new(); |
432 | 434 | ||
433 | field = getField( fields, MAILIMF_FIELD_TO ); | 435 | field = getField( fields, MAILIMF_FIELD_TO ); |
434 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 436 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
435 | && field->fld_data.fld_to->to_addr_list ) { | 437 | && field->fld_data.fld_to->to_addr_list ) { |
436 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 438 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
437 | } | 439 | } |
438 | 440 | ||
439 | field = getField( fields, MAILIMF_FIELD_CC ); | 441 | field = getField( fields, MAILIMF_FIELD_CC ); |
440 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 442 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
441 | && field->fld_data.fld_cc->cc_addr_list ) { | 443 | && field->fld_data.fld_cc->cc_addr_list ) { |
442 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 444 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
443 | } | 445 | } |
444 | 446 | ||
445 | field = getField( fields, MAILIMF_FIELD_BCC ); | 447 | field = getField( fields, MAILIMF_FIELD_BCC ); |
446 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 448 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
447 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 449 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
448 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 450 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
449 | } | 451 | } |
450 | 452 | ||
451 | return rcptList; | 453 | return rcptList; |
452 | } | 454 | } |
453 | 455 | ||
454 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) | 456 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
455 | { | 457 | { |
456 | char *from = NULL; | 458 | char *from = NULL; |
457 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 459 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
458 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 460 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
459 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 461 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
460 | clistiter *it; | 462 | clistiter *it; |
461 | for ( it = clist_begin( cl ); it; it = it->next ) { | 463 | for ( it = clist_begin( cl ); it; it = it->next ) { |
462 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 464 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
463 | from = strdup( mb->mb_addr_spec ); | 465 | from = strdup( mb->mb_addr_spec ); |
464 | } | 466 | } |
465 | } | 467 | } |
466 | 468 | ||
467 | return from; | 469 | return from; |
468 | } | 470 | } |
469 | 471 | ||
470 | char *SMTPwrapper::getFrom( mailmime *mail ) | 472 | char *SMTPwrapper::getFrom( mailmime *mail ) |
471 | { | 473 | { |
472 | /* no need to delete - its just a pointer to structure content */ | 474 | /* no need to delete - its just a pointer to structure content */ |
473 | mailimf_field *ffrom = 0; | 475 | mailimf_field *ffrom = 0; |
474 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 476 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
475 | return getFrom(ffrom); | 477 | return getFrom(ffrom); |
476 | } | 478 | } |
477 | 479 | ||
478 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 480 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
479 | { | 481 | { |
480 | if (SMTPwrapper::sendProgress) { | 482 | if (SMTPwrapper::sendProgress) { |
481 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 483 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
482 | qApp->processEvents(); | 484 | qApp->processEvents(); |
483 | } | 485 | } |
484 | } | 486 | } |
485 | 487 | ||
486 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 488 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
487 | { | 489 | { |
488 | if (!mail) return; | 490 | if (!mail) return; |
489 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 491 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
490 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 492 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
491 | wrap->storeMessage(mail,length,box); | 493 | wrap->storeMessage(mail,length,box); |
492 | delete wrap; | 494 | delete wrap; |
493 | } | 495 | } |
494 | 496 | ||
495 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | 497 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
496 | { | 498 | { |
497 | clist *rcpts = 0; | 499 | clist *rcpts = 0; |
498 | char *from, *data; | 500 | char *from, *data; |
499 | size_t size; | 501 | size_t size; |
500 | 502 | ||
501 | if ( smtp == NULL ) { | 503 | if ( smtp == NULL ) { |
502 | return; | 504 | return; |
503 | } | 505 | } |
504 | from = data = 0; | 506 | from = data = 0; |
505 | 507 | ||
506 | mailmessage * msg = 0; | 508 | mailmessage * msg = 0; |
507 | msg = mime_message_init(mail); | 509 | msg = mime_message_init(mail); |
508 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 510 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
509 | int r = mailmessage_fetch(msg,&data,&size); | 511 | int r = mailmessage_fetch(msg,&data,&size); |
510 | mime_message_detach_mime(msg); | 512 | mime_message_detach_mime(msg); |
511 | mailmessage_free(msg); | 513 | mailmessage_free(msg); |
512 | if (r != MAIL_NO_ERROR || !data) { | 514 | if (r != MAIL_NO_ERROR || !data) { |
513 | if (data) free(data); | 515 | if (data) free(data); |
514 | qDebug("Error fetching mime..."); | 516 | qDebug("Error fetching mime..."); |
515 | return; | 517 | return; |
516 | } | 518 | } |
517 | QString tmp = data; | 519 | QString tmp = data; |
518 | tmp.replace(QRegExp("\r+",true,false),""); | 520 | tmp.replace(QRegExp("\r+",true,false),""); |
519 | msg = 0; | 521 | msg = 0; |
520 | if (later) { | 522 | if (later) { |
521 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); | 523 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); |
522 | if (data) free( data ); | 524 | if (data) free( data ); |
523 | Config cfg( "mail" ); | 525 | Config cfg( "mail" ); |
524 | cfg.setGroup( "Status" ); | 526 | cfg.setGroup( "Status" ); |
525 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 527 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
526 | emit queuedMails( m_queuedMail ); | 528 | emit queuedMails( m_queuedMail ); |
527 | return; | 529 | return; |
528 | } | 530 | } |
529 | from = getFrom( mail ); | 531 | from = getFrom( mail ); |
530 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 532 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
531 | smtpSend(from,rcpts,data,size,smtp); | 533 | smtpSend(from,rcpts,data,size,smtp); |
532 | if (data) {free(data);} | 534 | if (data) {free(data);} |
533 | if (from) {free(from);} | 535 | if (from) {free(from);} |
534 | if (rcpts) smtp_address_list_free( rcpts ); | 536 | if (rcpts) smtp_address_list_free( rcpts ); |
535 | } | 537 | } |
536 | 538 | ||
537 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | 539 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) |
538 | { | 540 | { |
539 | char *server, *user, *pass; | 541 | char *server, *user, *pass; |
540 | bool ssl; | 542 | bool ssl; |
541 | uint16_t port; | 543 | uint16_t port; |
542 | mailsmtp *session; | 544 | mailsmtp *session; |
543 | int err,result; | 545 | int err,result; |
544 | 546 | ||
545 | result = 1; | 547 | result = 1; |
546 | server = user = pass = 0; | 548 | server = user = pass = 0; |
547 | server = strdup( smtp->getServer().latin1() ); | 549 | server = strdup( smtp->getServer().latin1() ); |
548 | ssl = smtp->getSSL(); | 550 | ssl = smtp->getSSL(); |
549 | port = smtp->getPort().toUInt(); | 551 | port = smtp->getPort().toUInt(); |
550 | 552 | ||
551 | session = mailsmtp_new( 20, &progress ); | 553 | session = mailsmtp_new( 20, &progress ); |
552 | if ( session == NULL ) goto free_mem; | 554 | if ( session == NULL ) goto free_mem; |
553 | 555 | ||
554 | qDebug( "Servername %s at port %i", server, port ); | 556 | qDebug( "Servername %s at port %i", server, port ); |
555 | if ( ssl ) { | 557 | if ( ssl ) { |
556 | qDebug( "SSL session" ); | 558 | qDebug( "SSL session" ); |
557 | err = mailsmtp_ssl_connect( session, server, port ); | 559 | err = mailsmtp_ssl_connect( session, server, port ); |
558 | } else { | 560 | } else { |
559 | qDebug( "No SSL session" ); | 561 | qDebug( "No SSL session" ); |
560 | err = mailsmtp_socket_connect( session, server, port ); | 562 | err = mailsmtp_socket_connect( session, server, port ); |
561 | } | 563 | } |
562 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} | 564 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
563 | 565 | ||
564 | err = mailsmtp_init( session ); | 566 | err = mailsmtp_init( session ); |
565 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 567 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
566 | 568 | ||
567 | qDebug( "INIT OK" ); | 569 | qDebug( "INIT OK" ); |
568 | 570 | ||
569 | if ( smtp->getLogin() ) { | 571 | if ( smtp->getLogin() ) { |
570 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 572 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
571 | // get'em | 573 | // get'em |
572 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 574 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
573 | login.show(); | 575 | login.show(); |
574 | if ( QDialog::Accepted == login.exec() ) { | 576 | if ( QDialog::Accepted == login.exec() ) { |
575 | // ok | 577 | // ok |
576 | user = strdup( login.getUser().latin1() ); | 578 | user = strdup( login.getUser().latin1() ); |
577 | pass = strdup( login.getPassword().latin1() ); | 579 | pass = strdup( login.getPassword().latin1() ); |
578 | } else { | 580 | } else { |
579 | result = 0; goto free_con_session; | 581 | result = 0; goto free_con_session; |
580 | } | 582 | } |
581 | } else { | 583 | } else { |
582 | user = strdup( smtp->getUser().latin1() ); | 584 | user = strdup( smtp->getUser().latin1() ); |
583 | pass = strdup( smtp->getPassword().latin1() ); | 585 | pass = strdup( smtp->getPassword().latin1() ); |
584 | } | 586 | } |
585 | qDebug( "session->auth: %i", session->auth); | 587 | qDebug( "session->auth: %i", session->auth); |
586 | err = mailsmtp_auth( session, user, pass ); | 588 | err = mailsmtp_auth( session, user, pass ); |
587 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 589 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
588 | qDebug( "Done auth!" ); | 590 | qDebug( "Done auth!" ); |
589 | } | 591 | } |
590 | 592 | ||
591 | err = mailsmtp_send( session, from, rcpts, data, size ); | 593 | err = mailsmtp_send( session, from, rcpts, data, size ); |
592 | if ( err != MAILSMTP_NO_ERROR ) { | 594 | if ( err != MAILSMTP_NO_ERROR ) { |
593 | qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); | 595 | qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); |
594 | result = 0; goto free_con_session; | 596 | result = 0; goto free_con_session; |
595 | } | 597 | } |
596 | 598 | ||
597 | qDebug( "Mail sent." ); | 599 | qDebug( "Mail sent." ); |
598 | storeMail(data,size,"Sent"); | 600 | storeMail(data,size,"Sent"); |
599 | 601 | ||
600 | free_con_session: | 602 | free_con_session: |
601 | mailsmtp_quit( session ); | 603 | mailsmtp_quit( session ); |
602 | free_mem_session: | 604 | free_mem_session: |
603 | mailsmtp_free( session ); | 605 | mailsmtp_free( session ); |
604 | free_mem: | 606 | free_mem: |
605 | if (server) free( server ); | 607 | if (server) free( server ); |
606 | if ( smtp->getLogin() ) { | 608 | if ( smtp->getLogin() ) { |
607 | free( user ); | 609 | free( user ); |
608 | free( pass ); | 610 | free( pass ); |
609 | } | 611 | } |
610 | return result; | 612 | return result; |
611 | } | 613 | } |
612 | 614 | ||
613 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) | 615 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) |
614 | { | 616 | { |
615 | mailmime * mimeMail; | 617 | mailmime * mimeMail; |
616 | 618 | ||
617 | SMTPaccount *smtp = aSmtp; | 619 | SMTPaccount *smtp = aSmtp; |
618 | 620 | ||
619 | if (!later && !smtp) { | 621 | if (!later && !smtp) { |
620 | qDebug("Didn't get any send method - giving up"); | 622 | qDebug("Didn't get any send method - giving up"); |
621 | return; | 623 | return; |
622 | } | 624 | } |
623 | mimeMail = createMimeMail(mail ); | 625 | mimeMail = createMimeMail(mail ); |
624 | if ( mimeMail == NULL ) { | 626 | if ( mimeMail == NULL ) { |
625 | qDebug( "sendMail: error creating mime mail" ); | 627 | qDebug( "sendMail: error creating mime mail" ); |
626 | } else { | 628 | } else { |
627 | sendProgress = new progressMailSend(); | 629 | sendProgress = new progressMailSend(); |
628 | sendProgress->show(); | 630 | sendProgress->show(); |
629 | sendProgress->setMaxMails(1); | 631 | sendProgress->setMaxMails(1); |
630 | smtpSend( mimeMail,later,smtp); | 632 | smtpSend( mimeMail,later,smtp); |
631 | qDebug("Clean up done"); | 633 | qDebug("Clean up done"); |
632 | sendProgress->hide(); | 634 | sendProgress->hide(); |
633 | delete sendProgress; | 635 | delete sendProgress; |
634 | sendProgress = 0; | 636 | sendProgress = 0; |
635 | mailmime_free( mimeMail ); | 637 | mailmime_free( mimeMail ); |
636 | } | 638 | } |
637 | } | 639 | } |
638 | 640 | ||
639 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | 641 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) |
640 | { | 642 | { |
641 | char*data = 0; | 643 | char*data = 0; |
642 | size_t length = 0; | 644 | size_t length = 0; |
643 | size_t curTok = 0; | 645 | size_t curTok = 0; |
644 | mailimf_fields *fields = 0; | 646 | mailimf_fields *fields = 0; |
645 | mailimf_field*ffrom = 0; | 647 | mailimf_field*ffrom = 0; |
646 | clist *rcpts = 0; | 648 | clist *rcpts = 0; |
647 | char*from = 0; | 649 | char*from = 0; |
648 | int res = 0; | 650 | int res = 0; |
649 | 651 | ||
650 | wrap->fetchRawBody(*which,&data,&length); | 652 | wrap->fetchRawBody(*which,&data,&length); |
651 | if (!data) return 0; | 653 | if (!data) return 0; |
652 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | 654 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); |
653 | if (err != MAILIMF_NO_ERROR) { | 655 | if (err != MAILIMF_NO_ERROR) { |
654 | free(data); | 656 | free(data); |
655 | delete wrap; | 657 | delete wrap; |
656 | return 0; | 658 | return 0; |
657 | } | 659 | } |
658 | 660 | ||
659 | rcpts = createRcptList( fields ); | 661 | rcpts = createRcptList( fields ); |
660 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 662 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
661 | from = getFrom(ffrom); | 663 | from = getFrom(ffrom); |
662 | 664 | ||
663 | qDebug("Size: %i vs. %i",length,strlen(data)); | 665 | qDebug("Size: %i vs. %i",length,strlen(data)); |
664 | if (rcpts && from) { | 666 | if (rcpts && from) { |
665 | res = smtpSend(from,rcpts,data,length,smtp ); | 667 | res = smtpSend(from,rcpts,data,length,smtp ); |
666 | } | 668 | } |
667 | if (fields) { | 669 | if (fields) { |
668 | mailimf_fields_free(fields); | 670 | mailimf_fields_free(fields); |
669 | fields = 0; | 671 | fields = 0; |
670 | } | 672 | } |
671 | if (data) { | 673 | if (data) { |
672 | free(data); | 674 | free(data); |
673 | } | 675 | } |
674 | if (from) { | 676 | if (from) { |
675 | free(from); | 677 | free(from); |
676 | } | 678 | } |
677 | if (rcpts) { | 679 | if (rcpts) { |
678 | smtp_address_list_free( rcpts ); | 680 | smtp_address_list_free( rcpts ); |
679 | } | 681 | } |
680 | return res; | 682 | return res; |
681 | } | 683 | } |
682 | 684 | ||
683 | /* this is a special fun */ | 685 | /* this is a special fun */ |
684 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | 686 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) |
685 | { | 687 | { |
686 | bool returnValue = true; | 688 | bool returnValue = true; |
687 | 689 | ||
688 | if (!smtp) return false; | 690 | if (!smtp) return false; |
689 | 691 | ||
690 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 692 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
691 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 693 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
692 | if (!wrap) { | 694 | if (!wrap) { |
693 | qDebug("memory error"); | 695 | qDebug("memory error"); |
694 | return false; | 696 | return false; |
695 | } | 697 | } |
696 | QList<RecMail> mailsToSend; | 698 | QList<RecMail> mailsToSend; |
697 | QList<RecMail> mailsToRemove; | 699 | QList<RecMail> mailsToRemove; |
698 | QString mbox("Outgoing"); | 700 | QString mbox("Outgoing"); |
699 | wrap->listMessages(mbox,mailsToSend); | 701 | wrap->listMessages(mbox,mailsToSend); |
700 | if (mailsToSend.count()==0) { | 702 | if (mailsToSend.count()==0) { |
701 | delete wrap; | 703 | delete wrap; |
702 | return false; | 704 | return false; |
703 | } | 705 | } |
704 | mailsToSend.setAutoDelete(false); | 706 | mailsToSend.setAutoDelete(false); |
705 | sendProgress = new progressMailSend(); | 707 | sendProgress = new progressMailSend(); |
706 | sendProgress->show(); | 708 | sendProgress->show(); |
707 | sendProgress->setMaxMails(mailsToSend.count()); | 709 | sendProgress->setMaxMails(mailsToSend.count()); |
708 | 710 | ||
709 | while (mailsToSend.count()>0) { | 711 | while (mailsToSend.count()>0) { |
710 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 712 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
711 | QMessageBox::critical(0,tr("Error sending mail"), | 713 | QMessageBox::critical(0,tr("Error sending mail"), |
712 | tr("Error sending queued mail - breaking")); | 714 | tr("Error sending queued mail - breaking")); |
713 | returnValue = false; | 715 | returnValue = false; |
714 | break; | 716 | break; |
715 | } | 717 | } |
716 | mailsToRemove.append(mailsToSend.at(0)); | 718 | mailsToRemove.append(mailsToSend.at(0)); |
717 | mailsToSend.removeFirst(); | 719 | mailsToSend.removeFirst(); |
718 | sendProgress->setCurrentMails(mailsToRemove.count()); | 720 | sendProgress->setCurrentMails(mailsToRemove.count()); |
719 | } | 721 | } |
720 | Config cfg( "mail" ); | 722 | Config cfg( "mail" ); |
721 | cfg.setGroup( "Status" ); | 723 | cfg.setGroup( "Status" ); |
722 | m_queuedMail = 0; | 724 | m_queuedMail = 0; |
723 | cfg.writeEntry( "outgoing", m_queuedMail ); | 725 | cfg.writeEntry( "outgoing", m_queuedMail ); |
724 | emit queuedMails( m_queuedMail ); | 726 | emit queuedMails( m_queuedMail ); |
725 | sendProgress->hide(); | 727 | sendProgress->hide(); |
726 | delete sendProgress; | 728 | delete sendProgress; |
727 | sendProgress = 0; | 729 | sendProgress = 0; |
728 | wrap->deleteMails(mbox,mailsToRemove); | 730 | wrap->deleteMails(mbox,mailsToRemove); |
729 | mailsToSend.setAutoDelete(true); | 731 | mailsToSend.setAutoDelete(true); |
730 | delete wrap; | 732 | delete wrap; |
731 | return returnValue; | 733 | return returnValue; |
732 | } | 734 | } |
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index 2c15a7b..69e1450 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro | |||
@@ -1,76 +1,52 @@ | |||
1 | CONFIG += qt warn_on debug quick-app | 1 | CONFIG += qt warn_on debug quick-app |
2 | 2 | ||
3 | HEADERS = defines.h \ | 3 | HEADERS = defines.h \ |
4 | logindialog.h \ | ||
5 | settings.h \ | ||
6 | editaccounts.h \ | 4 | editaccounts.h \ |
7 | mailwrapper.h \ | ||
8 | composemail.h \ | 5 | composemail.h \ |
9 | accountview.h \ | 6 | accountview.h \ |
10 | mainwindow.h \ | 7 | mainwindow.h \ |
11 | viewmail.h \ | 8 | viewmail.h \ |
12 | viewmailbase.h \ | 9 | viewmailbase.h \ |
13 | opiemail.h \ | 10 | opiemail.h \ |
14 | imapwrapper.h \ | ||
15 | mailtypes.h \ | ||
16 | mailistviewitem.h \ | 11 | mailistviewitem.h \ |
17 | pop3wrapper.h \ | ||
18 | abstractmail.h \ | ||
19 | settingsdialog.h \ | 12 | settingsdialog.h \ |
20 | statuswidget.h \ | 13 | statuswidget.h \ |
21 | smtpwrapper.h \ | ||
22 | genericwrapper.h \ | ||
23 | mboxwrapper.h \ | ||
24 | sendmailprogress.h \ | ||
25 | newmaildir.h | 14 | newmaildir.h |
26 | 15 | ||
27 | SOURCES = main.cpp \ | 16 | SOURCES = main.cpp \ |
28 | opiemail.cpp \ | 17 | opiemail.cpp \ |
29 | mainwindow.cpp \ | 18 | mainwindow.cpp \ |
30 | accountview.cpp \ | 19 | accountview.cpp \ |
31 | composemail.cpp \ | 20 | composemail.cpp \ |
32 | mailwrapper.cpp \ | ||
33 | imapwrapper.cpp \ | ||
34 | addresspicker.cpp \ | 21 | addresspicker.cpp \ |
35 | editaccounts.cpp \ | 22 | editaccounts.cpp \ |
36 | logindialog.cpp \ | ||
37 | viewmail.cpp \ | 23 | viewmail.cpp \ |
38 | viewmailbase.cpp \ | 24 | viewmailbase.cpp \ |
39 | settings.cpp \ | ||
40 | mailtypes.cpp \ | ||
41 | pop3wrapper.cpp \ | ||
42 | abstractmail.cpp \ | ||
43 | settingsdialog.cpp \ | 25 | settingsdialog.cpp \ |
44 | statuswidget.cpp \ | 26 | statuswidget.cpp \ |
45 | smtpwrapper.cpp \ | ||
46 | genericwrapper.cpp \ | ||
47 | mboxwrapper.cpp \ | ||
48 | sendmailprogress.cpp \ | ||
49 | newmaildir.cpp | 27 | newmaildir.cpp |
50 | 28 | ||
51 | INTERFACES = editaccountsui.ui \ | 29 | INTERFACES = editaccountsui.ui \ |
52 | selectmailtypeui.ui \ | 30 | selectmailtypeui.ui \ |
53 | imapconfigui.ui \ | 31 | imapconfigui.ui \ |
54 | pop3configui.ui \ | 32 | pop3configui.ui \ |
55 | nntpconfigui.ui \ | 33 | nntpconfigui.ui \ |
56 | smtpconfigui.ui \ | 34 | smtpconfigui.ui \ |
57 | addresspickerui.ui \ | 35 | addresspickerui.ui \ |
58 | logindialogui.ui \ | ||
59 | composemailui.ui \ | 36 | composemailui.ui \ |
60 | settingsdialogui.ui \ | 37 | settingsdialogui.ui \ |
61 | statuswidgetui.ui \ | 38 | statuswidgetui.ui \ |
62 | sendmailprogressui.ui \ | ||
63 | newmaildirui.ui | 39 | newmaildirui.ui |
64 | 40 | ||
65 | INCLUDEPATH += $(OPIEDIR)/include | 41 | INCLUDEPATH += $(OPIEDIR)/include |
66 | 42 | ||
67 | CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) | 43 | CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) |
68 | contains( CONFTEST, y ){ | 44 | contains( CONFTEST, y ){ |
69 | LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv | 45 | LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv |
70 | }else{ | 46 | }else{ |
71 | LIBS += -lqpe -letpan -lssl -lcrypto -lopie | 47 | LIBS += -lqpe -lopie -llibmailwrapper |
72 | } | 48 | } |
73 | 49 | ||
74 | TARGET = opiemail | 50 | TARGET = opiemail |
75 | 51 | ||
76 | include ( $(OPIEDIR)/include.pro ) | 52 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp index 2a74286..6511b1f 100644 --- a/noncore/net/mail/mainwindow.cpp +++ b/noncore/net/mail/mainwindow.cpp | |||
@@ -1,299 +1,300 @@ | |||
1 | #include <qlabel.h> | 1 | #include <qlabel.h> |
2 | #include <qvbox.h> | 2 | #include <qvbox.h> |
3 | #include <qheader.h> | 3 | #include <qheader.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | #include <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <qtextstream.h> | 7 | #include <qtextstream.h> |
8 | 8 | ||
9 | #include <qpe/qpeapplication.h> | 9 | #include <qpe/qpeapplication.h> |
10 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
11 | 11 | ||
12 | #include "defines.h" | 12 | #include "defines.h" |
13 | #include "mainwindow.h" | 13 | #include "mainwindow.h" |
14 | #include "viewmail.h" | 14 | #include "viewmail.h" |
15 | #include "mailtypes.h" | 15 | #include "mailtypes.h" |
16 | #include "mailistviewitem.h" | 16 | #include "mailistviewitem.h" |
17 | 17 | ||
18 | 18 | ||
19 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) | 19 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) |
20 | : QMainWindow( parent, name, flags ) | 20 | : QMainWindow( parent, name, flags ) |
21 | { | 21 | { |
22 | |||
22 | setCaption( tr( "Mail" ) ); | 23 | setCaption( tr( "Mail" ) ); |
23 | setToolBarsMovable( false ); | 24 | setToolBarsMovable( false ); |
24 | 25 | ||
25 | toolBar = new QToolBar( this ); | 26 | toolBar = new QToolBar( this ); |
26 | menuBar = new QMenuBar( toolBar ); | 27 | menuBar = new QMenuBar( toolBar ); |
27 | mailMenu = new QPopupMenu( menuBar ); | 28 | mailMenu = new QPopupMenu( menuBar ); |
28 | menuBar->insertItem( tr( "Mail" ), mailMenu ); | 29 | menuBar->insertItem( tr( "Mail" ), mailMenu ); |
29 | settingsMenu = new QPopupMenu( menuBar ); | 30 | settingsMenu = new QPopupMenu( menuBar ); |
30 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); | 31 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); |
31 | 32 | ||
32 | addToolBar( toolBar ); | 33 | addToolBar( toolBar ); |
33 | toolBar->setHorizontalStretchable( true ); | 34 | toolBar->setHorizontalStretchable( true ); |
34 | 35 | ||
35 | QLabel *spacer = new QLabel( toolBar ); | 36 | QLabel *spacer = new QLabel( toolBar ); |
36 | spacer->setBackgroundMode( QWidget::PaletteButton ); | 37 | spacer->setBackgroundMode( QWidget::PaletteButton ); |
37 | toolBar->setStretchableWidget( spacer ); | 38 | toolBar->setStretchableWidget( spacer ); |
38 | 39 | ||
39 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, | 40 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, |
40 | 0, 0, this ); | 41 | 0, 0, this ); |
41 | composeMail->addTo( toolBar ); | 42 | composeMail->addTo( toolBar ); |
42 | composeMail->addTo( mailMenu ); | 43 | composeMail->addTo( mailMenu ); |
43 | 44 | ||
44 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, | 45 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, |
45 | 0, 0, this ); | 46 | 0, 0, this ); |
46 | sendQueued->addTo( toolBar ); | 47 | sendQueued->addTo( toolBar ); |
47 | sendQueued->addTo( mailMenu ); | 48 | sendQueued->addTo( mailMenu ); |
48 | 49 | ||
49 | /* | 50 | /* |
50 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, | 51 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, |
51 | 0, 0, this ); | 52 | 0, 0, this ); |
52 | syncFolders->addTo( toolBar ); | 53 | syncFolders->addTo( toolBar ); |
53 | syncFolders->addTo( mailMenu ); | 54 | syncFolders->addTo( mailMenu ); |
54 | */ | 55 | */ |
55 | 56 | ||
56 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, | 57 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, |
57 | 0, 0, this, 0, true ); | 58 | 0, 0, this, 0, true ); |
58 | showFolders->addTo( toolBar ); | 59 | showFolders->addTo( toolBar ); |
59 | showFolders->addTo( mailMenu ); | 60 | showFolders->addTo( mailMenu ); |
60 | showFolders->setOn( true ); | 61 | showFolders->setOn( true ); |
61 | connect(showFolders, SIGNAL( toggled( bool ) ), | 62 | connect(showFolders, SIGNAL( toggled( bool ) ), |
62 | SLOT( slotShowFolders( bool ) ) ); | 63 | SLOT( slotShowFolders( bool ) ) ); |
63 | 64 | ||
64 | /* | 65 | /* |
65 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, | 66 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, |
66 | 0, 0, this ); | 67 | 0, 0, this ); |
67 | searchMails->addTo( toolBar ); | 68 | searchMails->addTo( toolBar ); |
68 | searchMails->addTo( mailMenu ); | 69 | searchMails->addTo( mailMenu ); |
69 | */ | 70 | */ |
70 | 71 | ||
71 | deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); | 72 | deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); |
72 | deleteMails->addTo( toolBar ); | 73 | deleteMails->addTo( toolBar ); |
73 | deleteMails->addTo( mailMenu ); | 74 | deleteMails->addTo( mailMenu ); |
74 | connect( deleteMails, SIGNAL( activated() ), | 75 | connect( deleteMails, SIGNAL( activated() ), |
75 | SLOT( slotDeleteMail() ) ); | 76 | SLOT( slotDeleteMail() ) ); |
76 | 77 | ||
77 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, | 78 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, |
78 | 0, 0, this ); | 79 | 0, 0, this ); |
79 | editSettings->addTo( settingsMenu ); | 80 | editSettings->addTo( settingsMenu ); |
80 | connect( editSettings, SIGNAL( activated() ), | 81 | connect( editSettings, SIGNAL( activated() ), |
81 | SLOT( slotEditSettings() ) ); | 82 | SLOT( slotEditSettings() ) ); |
82 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, | 83 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, |
83 | 0, 0, this ); | 84 | 0, 0, this ); |
84 | editAccounts->addTo( settingsMenu ); | 85 | editAccounts->addTo( settingsMenu ); |
85 | 86 | ||
86 | //setCentralWidget( view ); | 87 | //setCentralWidget( view ); |
87 | 88 | ||
88 | QVBox* wrapperBox = new QVBox( this ); | 89 | QVBox* wrapperBox = new QVBox( this ); |
89 | setCentralWidget( wrapperBox ); | 90 | setCentralWidget( wrapperBox ); |
90 | 91 | ||
91 | QWidget *view = new QWidget( wrapperBox ); | 92 | QWidget *view = new QWidget( wrapperBox ); |
92 | 93 | ||
93 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); | 94 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); |
94 | 95 | ||
95 | folderView = new AccountView( view ); | 96 | folderView = new AccountView( view ); |
96 | folderView->header()->hide(); | 97 | folderView->header()->hide(); |
97 | folderView->setRootIsDecorated( true ); | 98 | folderView->setRootIsDecorated( true ); |
98 | folderView->addColumn( tr( "Mailbox" ) ); | 99 | folderView->addColumn( tr( "Mailbox" ) ); |
99 | 100 | ||
100 | layout->addWidget( folderView ); | 101 | layout->addWidget( folderView ); |
101 | 102 | ||
102 | mailView = new QListView( view ); | 103 | mailView = new QListView( view ); |
103 | mailView->addColumn( tr( "" ) ); | 104 | mailView->addColumn( tr( "" ) ); |
104 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); | 105 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); |
105 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); | 106 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); |
106 | mailView->addColumn( tr( "Size" ),QListView::Manual); | 107 | mailView->addColumn( tr( "Size" ),QListView::Manual); |
107 | mailView->addColumn( tr( "Date" )); | 108 | mailView->addColumn( tr( "Date" )); |
108 | mailView->setAllColumnsShowFocus(true); | 109 | mailView->setAllColumnsShowFocus(true); |
109 | mailView->setSorting(-1); | 110 | mailView->setSorting(-1); |
110 | 111 | ||
111 | statusWidget = new StatusWidget( wrapperBox ); | 112 | statusWidget = new StatusWidget( wrapperBox ); |
112 | statusWidget->hide(); | 113 | statusWidget->hide(); |
113 | 114 | ||
114 | layout->addWidget( mailView ); | 115 | layout->addWidget( mailView ); |
115 | layout->setStretchFactor( folderView, 1 ); | 116 | layout->setStretchFactor( folderView, 1 ); |
116 | layout->setStretchFactor( mailView, 2 ); | 117 | layout->setStretchFactor( mailView, 2 ); |
117 | 118 | ||
118 | slotAdjustLayout(); | 119 | slotAdjustLayout(); |
119 | 120 | ||
120 | QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); | 121 | QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); |
121 | QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); | 122 | QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); |
122 | 123 | ||
123 | connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this, | 124 | connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this, |
124 | SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) ); | 125 | SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) ); |
125 | connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, | 126 | connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, |
126 | SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) ); | 127 | SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) ); |
127 | connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); | 128 | connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); |
128 | 129 | ||
129 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); | 130 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); |
130 | } | 131 | } |
131 | 132 | ||
132 | 133 | ||
133 | void MainWindow::slotAdjustLayout() { | 134 | void MainWindow::slotAdjustLayout() { |
134 | 135 | ||
135 | QWidget *d = QApplication::desktop(); | 136 | QWidget *d = QApplication::desktop(); |
136 | 137 | ||
137 | if ( d->width() < d->height() ) { | 138 | if ( d->width() < d->height() ) { |
138 | layout->setDirection( QBoxLayout::TopToBottom ); | 139 | layout->setDirection( QBoxLayout::TopToBottom ); |
139 | } else { | 140 | } else { |
140 | layout->setDirection( QBoxLayout::LeftToRight ); | 141 | layout->setDirection( QBoxLayout::LeftToRight ); |
141 | } | 142 | } |
142 | } | 143 | } |
143 | 144 | ||
144 | void MainWindow::slotAdjustColumns() | 145 | void MainWindow::slotAdjustColumns() |
145 | { | 146 | { |
146 | bool hidden = folderView->isHidden(); | 147 | bool hidden = folderView->isHidden(); |
147 | if ( hidden ) folderView->show(); | 148 | if ( hidden ) folderView->show(); |
148 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); | 149 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); |
149 | if ( hidden ) folderView->hide(); | 150 | if ( hidden ) folderView->hide(); |
150 | 151 | ||
151 | mailView->setColumnWidth( 0, 10 ); | 152 | mailView->setColumnWidth( 0, 10 ); |
152 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); | 153 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); |
153 | mailView->setColumnWidth( 2, 80 ); | 154 | mailView->setColumnWidth( 2, 80 ); |
154 | mailView->setColumnWidth( 3, 50 ); | 155 | mailView->setColumnWidth( 3, 50 ); |
155 | mailView->setColumnWidth( 4, 50 ); | 156 | mailView->setColumnWidth( 4, 50 ); |
156 | } | 157 | } |
157 | 158 | ||
158 | void MainWindow::slotEditSettings() | 159 | void MainWindow::slotEditSettings() |
159 | { | 160 | { |
160 | } | 161 | } |
161 | 162 | ||
162 | void MainWindow::slotShowFolders( bool show ) | 163 | void MainWindow::slotShowFolders( bool show ) |
163 | { | 164 | { |
164 | qDebug( "Show Folders" ); | 165 | qDebug( "Show Folders" ); |
165 | if ( show && folderView->isHidden() ) { | 166 | if ( show && folderView->isHidden() ) { |
166 | qDebug( "-> showing" ); | 167 | qDebug( "-> showing" ); |
167 | folderView->show(); | 168 | folderView->show(); |
168 | } else if ( !show && !folderView->isHidden() ) { | 169 | } else if ( !show && !folderView->isHidden() ) { |
169 | qDebug( "-> hiding" ); | 170 | qDebug( "-> hiding" ); |
170 | folderView->hide(); | 171 | folderView->hide(); |
171 | } | 172 | } |
172 | } | 173 | } |
173 | 174 | ||
174 | void MainWindow::refreshMailView(QList<RecMail>*list) | 175 | void MainWindow::refreshMailView(QList<RecMail>*list) |
175 | { | 176 | { |
176 | MailListViewItem*item = 0; | 177 | MailListViewItem*item = 0; |
177 | mailView->clear(); | 178 | mailView->clear(); |
178 | for (unsigned int i = 0; i < list->count();++i) { | 179 | for (unsigned int i = 0; i < list->count();++i) { |
179 | item = new MailListViewItem(mailView,item); | 180 | item = new MailListViewItem(mailView,item); |
180 | item->storeData(*(list->at(i))); | 181 | item->storeData(*(list->at(i))); |
181 | item->showEntry(); | 182 | item->showEntry(); |
182 | } | 183 | } |
183 | } | 184 | } |
184 | void MainWindow::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) | 185 | void MainWindow::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) |
185 | { | 186 | { |
186 | /* just LEFT button - or tap with stylus on pda */ | 187 | /* just LEFT button - or tap with stylus on pda */ |
187 | if (button!=1) return; | 188 | if (button!=1) return; |
188 | if (!item) return; | 189 | if (!item) return; |
189 | displayMail(); | 190 | displayMail(); |
190 | } | 191 | } |
191 | 192 | ||
192 | void MainWindow::displayMail() | 193 | void MainWindow::displayMail() |
193 | { | 194 | { |
194 | QListViewItem*item = mailView->currentItem(); | 195 | QListViewItem*item = mailView->currentItem(); |
195 | if (!item) return; | 196 | if (!item) return; |
196 | RecMail mail = ((MailListViewItem*)item)->data(); | 197 | RecMail mail = ((MailListViewItem*)item)->data(); |
197 | RecBody body = folderView->fetchBody(mail); | 198 | RecBody body = folderView->fetchBody(mail); |
198 | ViewMail readMail( this ); | 199 | ViewMail readMail( this ); |
199 | readMail.setBody( body ); | 200 | readMail.setBody( body ); |
200 | readMail.setMail( mail ); | 201 | readMail.setMail( mail ); |
201 | readMail.showMaximized(); | 202 | readMail.showMaximized(); |
202 | readMail.exec(); | 203 | readMail.exec(); |
203 | 204 | ||
204 | if ( readMail.deleted ) { | 205 | if ( readMail.deleted ) { |
205 | folderView->refreshCurrent(); | 206 | folderView->refreshCurrent(); |
206 | } else { | 207 | } else { |
207 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") ); | 208 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") ); |
208 | } | 209 | } |
209 | } | 210 | } |
210 | 211 | ||
211 | void MainWindow::slotDeleteMail() | 212 | void MainWindow::slotDeleteMail() |
212 | { | 213 | { |
213 | if (!mailView->currentItem()) return; | 214 | if (!mailView->currentItem()) return; |
214 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 215 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
215 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 216 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
216 | mail.Wrapper()->deleteMail( mail ); | 217 | mail.Wrapper()->deleteMail( mail ); |
217 | folderView->refreshCurrent(); | 218 | folderView->refreshCurrent(); |
218 | } | 219 | } |
219 | } | 220 | } |
220 | 221 | ||
221 | void MainWindow::mailHold(int button, QListViewItem *item,const QPoint&,int ) | 222 | void MainWindow::mailHold(int button, QListViewItem *item,const QPoint&,int ) |
222 | { | 223 | { |
223 | /* just the RIGHT button - or hold on pda */ | 224 | /* just the RIGHT button - or hold on pda */ |
224 | if (button!=2) {return;} | 225 | if (button!=2) {return;} |
225 | qDebug("Event right/hold"); | 226 | qDebug("Event right/hold"); |
226 | if (!item) return; | 227 | if (!item) return; |
227 | QPopupMenu *m = new QPopupMenu(0); | 228 | QPopupMenu *m = new QPopupMenu(0); |
228 | if (m) { | 229 | if (m) { |
229 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); | 230 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); |
230 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); | 231 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); |
231 | m->setFocus(); | 232 | m->setFocus(); |
232 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 233 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
233 | delete m; | 234 | delete m; |
234 | } | 235 | } |
235 | } | 236 | } |
236 | 237 | ||
237 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) | 238 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) |
238 | :QListViewItem(parent,item),mail_data() | 239 | :QListViewItem(parent,item),mail_data() |
239 | { | 240 | { |
240 | } | 241 | } |
241 | 242 | ||
242 | void MailListViewItem::showEntry() | 243 | void MailListViewItem::showEntry() |
243 | { | 244 | { |
244 | if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { | 245 | if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { |
245 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); | 246 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); |
246 | } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { | 247 | } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { |
247 | /* I think it looks nicer if there are not such a log of icons but only on mails | 248 | /* I think it looks nicer if there are not such a log of icons but only on mails |
248 | replied or new - Alwin*/ | 249 | replied or new - Alwin*/ |
249 | //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); | 250 | //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); |
250 | } else { | 251 | } else { |
251 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); | 252 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); |
252 | } | 253 | } |
253 | double s = mail_data.Msgsize(); | 254 | double s = mail_data.Msgsize(); |
254 | int w; | 255 | int w; |
255 | w=0; | 256 | w=0; |
256 | 257 | ||
257 | while (s>1024) { | 258 | while (s>1024) { |
258 | s/=1024; | 259 | s/=1024; |
259 | ++w; | 260 | ++w; |
260 | if (w>=2) break; | 261 | if (w>=2) break; |
261 | } | 262 | } |
262 | 263 | ||
263 | QString q=""; | 264 | QString q=""; |
264 | QString fsize=""; | 265 | QString fsize=""; |
265 | switch(w) { | 266 | switch(w) { |
266 | case 1: | 267 | case 1: |
267 | q="k"; | 268 | q="k"; |
268 | break; | 269 | break; |
269 | case 2: | 270 | case 2: |
270 | q="M"; | 271 | q="M"; |
271 | break; | 272 | break; |
272 | default: | 273 | default: |
273 | break; | 274 | break; |
274 | } | 275 | } |
275 | 276 | ||
276 | { | 277 | { |
277 | QTextOStream o(&fsize); | 278 | QTextOStream o(&fsize); |
278 | if (w>0) o.precision(2); else o.precision(0); | 279 | if (w>0) o.precision(2); else o.precision(0); |
279 | o.setf(QTextStream::fixed); | 280 | o.setf(QTextStream::fixed); |
280 | o << s << " " << q << "Byte"; | 281 | o << s << " " << q << "Byte"; |
281 | } | 282 | } |
282 | 283 | ||
283 | setText(1,mail_data.getSubject()); | 284 | setText(1,mail_data.getSubject()); |
284 | setText(2,mail_data.getFrom()); | 285 | setText(2,mail_data.getFrom()); |
285 | setText(3,fsize); | 286 | setText(3,fsize); |
286 | setText(4,mail_data.getDate()); | 287 | setText(4,mail_data.getDate()); |
287 | } | 288 | } |
288 | 289 | ||
289 | void MailListViewItem::storeData(const RecMail&data) | 290 | void MailListViewItem::storeData(const RecMail&data) |
290 | { | 291 | { |
291 | mail_data = data; | 292 | mail_data = data; |
292 | } | 293 | } |
293 | 294 | ||
294 | const RecMail& MailListViewItem::data()const | 295 | const RecMail& MailListViewItem::data()const |
295 | { | 296 | { |
296 | return mail_data; | 297 | return mail_data; |
297 | } | 298 | } |
298 | 299 | ||
299 | 300 | ||