summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/defines.h11
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp107
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h2
-rw-r--r--noncore/net/mail/mailwrapper.cpp107
-rw-r--r--noncore/net/mail/mailwrapper.h2
5 files changed, 201 insertions, 28 deletions
diff --git a/noncore/net/mail/defines.h b/noncore/net/mail/defines.h
index 9036658..d9cdab0 100644
--- a/noncore/net/mail/defines.h
+++ b/noncore/net/mail/defines.h
@@ -1,40 +1,51 @@
1#ifndef DEFINE_CONSTANTS_H 1#ifndef DEFINE_CONSTANTS_H
2#define DEFINE_CONSTANTS_H 2#define DEFINE_CONSTANTS_H
3 3
4#include <qpe/resource.h> 4#include <qpe/resource.h>
5 5
6#define USER_AGENT "OpieMail v0.1" 6#define USER_AGENT "OpieMail v0.1"
7 7
8#define PIC_COMPOSEMAIL "mail/composemail" 8#define PIC_COMPOSEMAIL "mail/composemail"
9#define PIC_SENDQUEUED "mail/sendqueued" 9#define PIC_SENDQUEUED "mail/sendqueued"
10#define PIC_SHOWFOLDERS "mail/showfolders" 10#define PIC_SHOWFOLDERS "mail/showfolders"
11#define PIC_SEARCHMAILS "mail/searchmails" 11#define PIC_SEARCHMAILS "mail/searchmails"
12#define PIC_EDITSETTINGS "mail/editsettings" 12#define PIC_EDITSETTINGS "mail/editsettings"
13#define PIC_EDITACCOUNTS "mail/editaccounts" 13#define PIC_EDITACCOUNTS "mail/editaccounts"
14#define PIC_SYNC "mail/sync" 14#define PIC_SYNC "mail/sync"
15#define PIC_IMAPFOLDER "mail/imapfolder" 15#define PIC_IMAPFOLDER "mail/imapfolder"
16#define PIC_POP3FOLDER "mail/pop3folder" 16#define PIC_POP3FOLDER "mail/pop3folder"
17#define PIC_INBOXFOLDER "mail/inbox" 17#define PIC_INBOXFOLDER "mail/inbox"
18 18
19#define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) ) 19#define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) )
20#define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) ) 20#define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) )
21#define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) ) 21#define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) )
22#define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) ) 22#define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) )
23#define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) ) 23#define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) )
24#define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) ) 24#define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) )
25#define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) ) 25#define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) )
26 26
27#define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) ) 27#define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) )
28#define PIXMAP_POP3FOLDER QPixmap( Resource::loadPixmap( PIC_POP3FOLDER ) ) 28#define PIXMAP_POP3FOLDER QPixmap( Resource::loadPixmap( PIC_POP3FOLDER ) )
29#define PIXMAP_INBOXFOLDER QPixmap( Resource::loadPixmap( PIC_INBOXFOLDER) ) 29#define PIXMAP_INBOXFOLDER QPixmap( Resource::loadPixmap( PIC_INBOXFOLDER) )
30 30
31#define IMAP_PORT "143" 31#define IMAP_PORT "143"
32#define IMAP_SSL_PORT "993" 32#define IMAP_SSL_PORT "993"
33#define SMTP_PORT "25" 33#define SMTP_PORT "25"
34#define SMTP_SSL_PORT "465" 34#define SMTP_SSL_PORT "465"
35#define POP3_PORT "110" 35#define POP3_PORT "110"
36#define POP3_SSL_PORT "995" 36#define POP3_SSL_PORT "995"
37#define NNTP_PORT "119" 37#define NNTP_PORT "119"
38#define NNTP_SSL_PORT "563" 38#define NNTP_SSL_PORT "563"
39 39
40/* used for decoding imapfoldername */
41#define UNDEFINED 64
42#define MAXLINE 76
43#define UTF16MASK 0x03FFUL
44#define UTF16SHIFT 10
45#define UTF16BASE 0x10000UL
46#define UTF16HIGHSTART 0xD800UL
47#define UTF16HIGHEND 0xDBFFUL
48#define UTF16LOSTART 0xDC00UL
49#define UTF16LOEND 0xDFFFUL
50
40#endif 51#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 858283f..75c06f9 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,119 +1,198 @@
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 "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name, const QString&sep ) 20Folder::Folder(const QString&tmp_name, const QString&sep )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 }
36 }
37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38 separator = sep; 24 separator = sep;
39} 25}
40 26
41const QString& Folder::Separator()const 27const QString& Folder::Separator()const
42{ 28{
43 return separator; 29 return separator;
44} 30}
45 31
46IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) 32IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
47 : Folder( name,sep ),m_MaySelect(select) 33 : Folder( name,sep ),m_MaySelect(select)
48{ 34{
35 // Decode IMAP foldername
36 nameDisplay = IMAPFolder::decodeFolderName( name );
37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38
49 if (prefix.length()>0) { 39 if (prefix.length()>0) {
50 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 40 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
51 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 41 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
52 } 42 }
53 } 43 }
54} 44}
55 45
46static unsigned char base64chars[] =
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
48
49/**
50 * Decodes base64 encoded parts of the imapfolder name
51 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
52 */
53QString IMAPFolder::decodeFolderName( const QString &name )
54{
55 unsigned char c, i, bitcount;
56 unsigned long ucs4, utf16, bitbuf;
57 unsigned char base64[256], utf8[6];
58 unsigned long srcPtr = 0;
59 QCString dst;
60 QCString src = name.ascii();
61
62 /* initialize modified base64 decoding table */
63 memset(base64, UNDEFINED, sizeof(base64));
64 for (i = 0; i < sizeof(base64chars); ++i) {
65 base64[(int)base64chars[i]] = i;
66 }
67
68 /* loop until end of string */
69 while (srcPtr < src.length ()) {
70 c = src[srcPtr++];
71 /* deal with literal characters and &- */
72 if (c != '&' || src[srcPtr] == '-') {
73 /* encode literally */
74 dst += c;
75 /* skip over the '-' if this is an &- sequence */
76 if (c == '&')
77 srcPtr++;
78 } else {
79 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
80 bitbuf = 0;
81 bitcount = 0;
82 ucs4 = 0;
83 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
84 ++srcPtr;
85 bitbuf = (bitbuf << 6) | c;
86 bitcount += 6;
87 /* enough bits for a UTF-16 character? */
88 if (bitcount >= 16) {
89 bitcount -= 16;
90 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
91 /* convert UTF16 to UCS4 */
92 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
93 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
94 continue;
95 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
96 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
97 } else {
98 ucs4 = utf16;
99 }
100 /* convert UTF-16 range of UCS4 to UTF-8 */
101 if (ucs4 <= 0x7fUL) {
102 utf8[0] = ucs4;
103 i = 1;
104 } else if (ucs4 <= 0x7ffUL) {
105 utf8[0] = 0xc0 | (ucs4 >> 6);
106 utf8[1] = 0x80 | (ucs4 & 0x3f);
107 i = 2;
108 } else if (ucs4 <= 0xffffUL) {
109 utf8[0] = 0xe0 | (ucs4 >> 12);
110 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
111 utf8[2] = 0x80 | (ucs4 & 0x3f);
112 i = 3;
113 } else {
114 utf8[0] = 0xf0 | (ucs4 >> 18);
115 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
116 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
117 utf8[3] = 0x80 | (ucs4 & 0x3f);
118 i = 4;
119 }
120 /* copy it */
121 for (c = 0; c < i; ++c) {
122 dst += utf8[c];
123 }
124 }
125 }
126 /* skip over trailing '-' in modified UTF-7 encoding */
127 if (src[srcPtr] == '-')
128 ++srcPtr;
129 }
130 }
131
132 return QString::fromUtf8( dst.data() );
133}
134
56MailWrapper::MailWrapper( Settings *s ) 135MailWrapper::MailWrapper( Settings *s )
57 : QObject() 136 : QObject()
58{ 137{
59 settings = s; 138 settings = s;
60} 139}
61 140
62QString MailWrapper::mailsmtpError( int errnum ) 141QString MailWrapper::mailsmtpError( int errnum )
63{ 142{
64 switch ( errnum ) { 143 switch ( errnum ) {
65 case MAILSMTP_NO_ERROR: 144 case MAILSMTP_NO_ERROR:
66 return tr( "No error" ); 145 return tr( "No error" );
67 case MAILSMTP_ERROR_UNEXPECTED_CODE: 146 case MAILSMTP_ERROR_UNEXPECTED_CODE:
68 return tr( "Unexpected error code" ); 147 return tr( "Unexpected error code" );
69 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 148 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
70 return tr( "Service not available" ); 149 return tr( "Service not available" );
71 case MAILSMTP_ERROR_STREAM: 150 case MAILSMTP_ERROR_STREAM:
72 return tr( "Stream error" ); 151 return tr( "Stream error" );
73 case MAILSMTP_ERROR_HOSTNAME: 152 case MAILSMTP_ERROR_HOSTNAME:
74 return tr( "gethostname() failed" ); 153 return tr( "gethostname() failed" );
75 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 154 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
76 return tr( "Not implemented" ); 155 return tr( "Not implemented" );
77 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 156 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
78 return tr( "Error, action not taken" ); 157 return tr( "Error, action not taken" );
79 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 158 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
80 return tr( "Data exceeds storage allocation" ); 159 return tr( "Data exceeds storage allocation" );
81 case MAILSMTP_ERROR_IN_PROCESSING: 160 case MAILSMTP_ERROR_IN_PROCESSING:
82 return tr( "Error in processing" ); 161 return tr( "Error in processing" );
83 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 162 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
84 // return tr( "Insufficient system storage" ); 163 // return tr( "Insufficient system storage" );
85 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 164 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
86 return tr( "Mailbox unavailable" ); 165 return tr( "Mailbox unavailable" );
87 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 166 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
88 return tr( "Mailbox name not allowed" ); 167 return tr( "Mailbox name not allowed" );
89 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 168 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
90 return tr( "Bad command sequence" ); 169 return tr( "Bad command sequence" );
91 case MAILSMTP_ERROR_USER_NOT_LOCAL: 170 case MAILSMTP_ERROR_USER_NOT_LOCAL:
92 return tr( "User not local" ); 171 return tr( "User not local" );
93 case MAILSMTP_ERROR_TRANSACTION_FAILED: 172 case MAILSMTP_ERROR_TRANSACTION_FAILED:
94 return tr( "Transaction failed" ); 173 return tr( "Transaction failed" );
95 case MAILSMTP_ERROR_MEMORY: 174 case MAILSMTP_ERROR_MEMORY:
96 return tr( "Memory error" ); 175 return tr( "Memory error" );
97 case MAILSMTP_ERROR_CONNECTION_REFUSED: 176 case MAILSMTP_ERROR_CONNECTION_REFUSED:
98 return tr( "Connection refused" ); 177 return tr( "Connection refused" );
99 default: 178 default:
100 return tr( "Unknown error code" ); 179 return tr( "Unknown error code" );
101 } 180 }
102} 181}
103 182
104mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 183mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
105{ 184{
106 return mailimf_mailbox_new( strdup( name.latin1() ), 185 return mailimf_mailbox_new( strdup( name.latin1() ),
107 strdup( mail.latin1() ) ); 186 strdup( mail.latin1() ) );
108} 187}
109 188
110mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 189mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
111{ 190{
112 mailimf_address_list *addresses; 191 mailimf_address_list *addresses;
113 192
114 if ( addr.isEmpty() ) return NULL; 193 if ( addr.isEmpty() ) return NULL;
115 194
116 addresses = mailimf_address_list_new_empty(); 195 addresses = mailimf_address_list_new_empty();
117 196
118 QStringList list = QStringList::split( ',', addr ); 197 QStringList list = QStringList::split( ',', addr );
119 QStringList::Iterator it; 198 QStringList::Iterator it;
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index d78f8e9..02fe4b7 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -27,98 +27,100 @@ public:
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name,const QString&sep ); 74 Folder( const QString&init_name,const QString&sep );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 const QString&Separator()const; 78 const QString&Separator()const;
79 79
80protected: 80protected:
81 QString nameDisplay, name, separator; 81 QString nameDisplay, name, separator;
82 82
83}; 83};
84 84
85class IMAPFolder : public Folder 85class IMAPFolder : public Folder
86{ 86{
87 public: 87 public:
88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); 88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
89 virtual bool may_select()const{return m_MaySelect;} 89 virtual bool may_select()const{return m_MaySelect;}
90 private: 90 private:
91 static QString decodeFolderName( const QString &name );
91 bool m_MaySelect; 92 bool m_MaySelect;
93
92}; 94};
93 95
94class MailWrapper : public QObject 96class MailWrapper : public QObject
95{ 97{
96 Q_OBJECT 98 Q_OBJECT
97 99
98public: 100public:
99 MailWrapper( Settings *s ); 101 MailWrapper( Settings *s );
100 void sendMail( Mail mail ); 102 void sendMail( Mail mail );
101 103
102private: 104private:
103 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 105 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
104 mailimf_address_list *parseAddresses(const QString&addr ); 106 mailimf_address_list *parseAddresses(const QString&addr );
105 mailimf_fields *createImfFields( Mail *mail ); 107 mailimf_fields *createImfFields( Mail *mail );
106 mailmime *buildTxtPart( QString str ); 108 mailmime *buildTxtPart( QString str );
107 mailmime *buildFilePart( QString filename, QString mimetype ); 109 mailmime *buildFilePart( QString filename, QString mimetype );
108 void addFileParts( mailmime *message, QList<Attachment> files ); 110 void addFileParts( mailmime *message, QList<Attachment> files );
109 mailmime *createMimeMail( Mail *mail ); 111 mailmime *createMimeMail( Mail *mail );
110 void smtpSend( mailmime *mail ); 112 void smtpSend( mailmime *mail );
111 mailimf_field *getField( mailimf_fields *fields, int type ); 113 mailimf_field *getField( mailimf_fields *fields, int type );
112 clist *createRcptList( mailimf_fields *fields ); 114 clist *createRcptList( mailimf_fields *fields );
113 char *getFrom( mailmime *mail ); 115 char *getFrom( mailmime *mail );
114 SMTPaccount *getAccount( QString from ); 116 SMTPaccount *getAccount( QString from );
115 void writeToFile( QString file, mailmime *mail ); 117 void writeToFile( QString file, mailmime *mail );
116 void readFromFile( QString file, char **data, size_t *size ); 118 void readFromFile( QString file, char **data, size_t *size );
117 static QString mailsmtpError( int err ); 119 static QString mailsmtpError( int err );
118 static QString getTmpFile(); 120 static QString getTmpFile();
119 121
120 Settings *settings; 122 Settings *settings;
121 123
122}; 124};
123 125
124#endif 126#endif
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 858283f..75c06f9 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -1,119 +1,198 @@
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 "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name, const QString&sep ) 20Folder::Folder(const QString&tmp_name, const QString&sep )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 }
36 }
37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38 separator = sep; 24 separator = sep;
39} 25}
40 26
41const QString& Folder::Separator()const 27const QString& Folder::Separator()const
42{ 28{
43 return separator; 29 return separator;
44} 30}
45 31
46IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) 32IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
47 : Folder( name,sep ),m_MaySelect(select) 33 : Folder( name,sep ),m_MaySelect(select)
48{ 34{
35 // Decode IMAP foldername
36 nameDisplay = IMAPFolder::decodeFolderName( name );
37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38
49 if (prefix.length()>0) { 39 if (prefix.length()>0) {
50 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 40 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
51 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 41 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
52 } 42 }
53 } 43 }
54} 44}
55 45
46static unsigned char base64chars[] =
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
48
49/**
50 * Decodes base64 encoded parts of the imapfolder name
51 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
52 */
53QString IMAPFolder::decodeFolderName( const QString &name )
54{
55 unsigned char c, i, bitcount;
56 unsigned long ucs4, utf16, bitbuf;
57 unsigned char base64[256], utf8[6];
58 unsigned long srcPtr = 0;
59 QCString dst;
60 QCString src = name.ascii();
61
62 /* initialize modified base64 decoding table */
63 memset(base64, UNDEFINED, sizeof(base64));
64 for (i = 0; i < sizeof(base64chars); ++i) {
65 base64[(int)base64chars[i]] = i;
66 }
67
68 /* loop until end of string */
69 while (srcPtr < src.length ()) {
70 c = src[srcPtr++];
71 /* deal with literal characters and &- */
72 if (c != '&' || src[srcPtr] == '-') {
73 /* encode literally */
74 dst += c;
75 /* skip over the '-' if this is an &- sequence */
76 if (c == '&')
77 srcPtr++;
78 } else {
79 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
80 bitbuf = 0;
81 bitcount = 0;
82 ucs4 = 0;
83 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
84 ++srcPtr;
85 bitbuf = (bitbuf << 6) | c;
86 bitcount += 6;
87 /* enough bits for a UTF-16 character? */
88 if (bitcount >= 16) {
89 bitcount -= 16;
90 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
91 /* convert UTF16 to UCS4 */
92 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
93 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
94 continue;
95 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
96 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
97 } else {
98 ucs4 = utf16;
99 }
100 /* convert UTF-16 range of UCS4 to UTF-8 */
101 if (ucs4 <= 0x7fUL) {
102 utf8[0] = ucs4;
103 i = 1;
104 } else if (ucs4 <= 0x7ffUL) {
105 utf8[0] = 0xc0 | (ucs4 >> 6);
106 utf8[1] = 0x80 | (ucs4 & 0x3f);
107 i = 2;
108 } else if (ucs4 <= 0xffffUL) {
109 utf8[0] = 0xe0 | (ucs4 >> 12);
110 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
111 utf8[2] = 0x80 | (ucs4 & 0x3f);
112 i = 3;
113 } else {
114 utf8[0] = 0xf0 | (ucs4 >> 18);
115 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
116 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
117 utf8[3] = 0x80 | (ucs4 & 0x3f);
118 i = 4;
119 }
120 /* copy it */
121 for (c = 0; c < i; ++c) {
122 dst += utf8[c];
123 }
124 }
125 }
126 /* skip over trailing '-' in modified UTF-7 encoding */
127 if (src[srcPtr] == '-')
128 ++srcPtr;
129 }
130 }
131
132 return QString::fromUtf8( dst.data() );
133}
134
56MailWrapper::MailWrapper( Settings *s ) 135MailWrapper::MailWrapper( Settings *s )
57 : QObject() 136 : QObject()
58{ 137{
59 settings = s; 138 settings = s;
60} 139}
61 140
62QString MailWrapper::mailsmtpError( int errnum ) 141QString MailWrapper::mailsmtpError( int errnum )
63{ 142{
64 switch ( errnum ) { 143 switch ( errnum ) {
65 case MAILSMTP_NO_ERROR: 144 case MAILSMTP_NO_ERROR:
66 return tr( "No error" ); 145 return tr( "No error" );
67 case MAILSMTP_ERROR_UNEXPECTED_CODE: 146 case MAILSMTP_ERROR_UNEXPECTED_CODE:
68 return tr( "Unexpected error code" ); 147 return tr( "Unexpected error code" );
69 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 148 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
70 return tr( "Service not available" ); 149 return tr( "Service not available" );
71 case MAILSMTP_ERROR_STREAM: 150 case MAILSMTP_ERROR_STREAM:
72 return tr( "Stream error" ); 151 return tr( "Stream error" );
73 case MAILSMTP_ERROR_HOSTNAME: 152 case MAILSMTP_ERROR_HOSTNAME:
74 return tr( "gethostname() failed" ); 153 return tr( "gethostname() failed" );
75 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 154 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
76 return tr( "Not implemented" ); 155 return tr( "Not implemented" );
77 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 156 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
78 return tr( "Error, action not taken" ); 157 return tr( "Error, action not taken" );
79 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 158 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
80 return tr( "Data exceeds storage allocation" ); 159 return tr( "Data exceeds storage allocation" );
81 case MAILSMTP_ERROR_IN_PROCESSING: 160 case MAILSMTP_ERROR_IN_PROCESSING:
82 return tr( "Error in processing" ); 161 return tr( "Error in processing" );
83 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 162 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
84 // return tr( "Insufficient system storage" ); 163 // return tr( "Insufficient system storage" );
85 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 164 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
86 return tr( "Mailbox unavailable" ); 165 return tr( "Mailbox unavailable" );
87 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 166 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
88 return tr( "Mailbox name not allowed" ); 167 return tr( "Mailbox name not allowed" );
89 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 168 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
90 return tr( "Bad command sequence" ); 169 return tr( "Bad command sequence" );
91 case MAILSMTP_ERROR_USER_NOT_LOCAL: 170 case MAILSMTP_ERROR_USER_NOT_LOCAL:
92 return tr( "User not local" ); 171 return tr( "User not local" );
93 case MAILSMTP_ERROR_TRANSACTION_FAILED: 172 case MAILSMTP_ERROR_TRANSACTION_FAILED:
94 return tr( "Transaction failed" ); 173 return tr( "Transaction failed" );
95 case MAILSMTP_ERROR_MEMORY: 174 case MAILSMTP_ERROR_MEMORY:
96 return tr( "Memory error" ); 175 return tr( "Memory error" );
97 case MAILSMTP_ERROR_CONNECTION_REFUSED: 176 case MAILSMTP_ERROR_CONNECTION_REFUSED:
98 return tr( "Connection refused" ); 177 return tr( "Connection refused" );
99 default: 178 default:
100 return tr( "Unknown error code" ); 179 return tr( "Unknown error code" );
101 } 180 }
102} 181}
103 182
104mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 183mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
105{ 184{
106 return mailimf_mailbox_new( strdup( name.latin1() ), 185 return mailimf_mailbox_new( strdup( name.latin1() ),
107 strdup( mail.latin1() ) ); 186 strdup( mail.latin1() ) );
108} 187}
109 188
110mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 189mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
111{ 190{
112 mailimf_address_list *addresses; 191 mailimf_address_list *addresses;
113 192
114 if ( addr.isEmpty() ) return NULL; 193 if ( addr.isEmpty() ) return NULL;
115 194
116 addresses = mailimf_address_list_new_empty(); 195 addresses = mailimf_address_list_new_empty();
117 196
118 QStringList list = QStringList::split( ',', addr ); 197 QStringList list = QStringList::split( ',', addr );
119 QStringList::Iterator it; 198 QStringList::Iterator it;
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index d78f8e9..02fe4b7 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -27,98 +27,100 @@ public:
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name,const QString&sep ); 74 Folder( const QString&init_name,const QString&sep );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 const QString&Separator()const; 78 const QString&Separator()const;
79 79
80protected: 80protected:
81 QString nameDisplay, name, separator; 81 QString nameDisplay, name, separator;
82 82
83}; 83};
84 84
85class IMAPFolder : public Folder 85class IMAPFolder : public Folder
86{ 86{
87 public: 87 public:
88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); 88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
89 virtual bool may_select()const{return m_MaySelect;} 89 virtual bool may_select()const{return m_MaySelect;}
90 private: 90 private:
91 static QString decodeFolderName( const QString &name );
91 bool m_MaySelect; 92 bool m_MaySelect;
93
92}; 94};
93 95
94class MailWrapper : public QObject 96class MailWrapper : public QObject
95{ 97{
96 Q_OBJECT 98 Q_OBJECT
97 99
98public: 100public:
99 MailWrapper( Settings *s ); 101 MailWrapper( Settings *s );
100 void sendMail( Mail mail ); 102 void sendMail( Mail mail );
101 103
102private: 104private:
103 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 105 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
104 mailimf_address_list *parseAddresses(const QString&addr ); 106 mailimf_address_list *parseAddresses(const QString&addr );
105 mailimf_fields *createImfFields( Mail *mail ); 107 mailimf_fields *createImfFields( Mail *mail );
106 mailmime *buildTxtPart( QString str ); 108 mailmime *buildTxtPart( QString str );
107 mailmime *buildFilePart( QString filename, QString mimetype ); 109 mailmime *buildFilePart( QString filename, QString mimetype );
108 void addFileParts( mailmime *message, QList<Attachment> files ); 110 void addFileParts( mailmime *message, QList<Attachment> files );
109 mailmime *createMimeMail( Mail *mail ); 111 mailmime *createMimeMail( Mail *mail );
110 void smtpSend( mailmime *mail ); 112 void smtpSend( mailmime *mail );
111 mailimf_field *getField( mailimf_fields *fields, int type ); 113 mailimf_field *getField( mailimf_fields *fields, int type );
112 clist *createRcptList( mailimf_fields *fields ); 114 clist *createRcptList( mailimf_fields *fields );
113 char *getFrom( mailmime *mail ); 115 char *getFrom( mailmime *mail );
114 SMTPaccount *getAccount( QString from ); 116 SMTPaccount *getAccount( QString from );
115 void writeToFile( QString file, mailmime *mail ); 117 void writeToFile( QString file, mailmime *mail );
116 void readFromFile( QString file, char **data, size_t *size ); 118 void readFromFile( QString file, char **data, size_t *size );
117 static QString mailsmtpError( int err ); 119 static QString mailsmtpError( int err );
118 static QString getTmpFile(); 120 static QString getTmpFile();
119 121
120 Settings *settings; 122 Settings *settings;
121 123
122}; 124};
123 125
124#endif 126#endif