summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.cpp7
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/kmicromail/libmailwrapper/mailwrapper.cpp b/kmicromail/libmailwrapper/mailwrapper.cpp
index 9400649..2ee1ab3 100644
--- a/kmicromail/libmailwrapper/mailwrapper.cpp
+++ b/kmicromail/libmailwrapper/mailwrapper.cpp
@@ -1,180 +1,181 @@
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 12
13#define UNDEFINED 64 13#define UNDEFINED 64
14#define MAXLINE 76 14#define MAXLINE 76
15#define UTF16MASK 0x03FFUL 15#define UTF16MASK 0x03FFUL
16#define UTF16SHIFT 10 16#define UTF16SHIFT 10
17#define UTF16BASE 0x10000UL 17#define UTF16BASE 0x10000UL
18#define UTF16HIGHSTART 0xD800UL 18#define UTF16HIGHSTART 0xD800UL
19#define UTF16HIGHEND 0xDBFFUL 19#define UTF16HIGHEND 0xDBFFUL
20#define UTF16LOSTART 0xDC00UL 20#define UTF16LOSTART 0xDC00UL
21#define UTF16LOEND 0xDFFFUL 21#define UTF16LOEND 0xDFFFUL
22 22
23 23
24using namespace Opie::Core; 24using namespace Opie::Core;
25Attachment::Attachment( QString lnk ) 25Attachment::Attachment( QString lnk )
26{ 26{
27 doc = lnk; 27 doc = lnk;
28 size = QFileInfo( doc ).size(); 28 size = QFileInfo( doc ).size();
29 mPix = SmallIcon( "files" ); 29 mPix = SmallIcon( "files" );
30} 30}
31 31
32Folder::Folder(const QString&tmp_name, const QString&sep ) 32Folder::Folder(const QString&tmp_name, const QString&sep )
33{ 33{
34 name = tmp_name; 34 name = tmp_name;
35 nameDisplay = name; 35 nameDisplay = name;
36 separator = sep; 36 separator = sep;
37 prefix = ""; 37 prefix = "";
38} 38}
39 39
40Folder::~Folder() 40Folder::~Folder()
41{ 41{
42} 42}
43 43
44const QString& Folder::Separator()const 44const QString& Folder::Separator()const
45{ 45{
46 return separator; 46 return separator;
47} 47}
48 48
49IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) 49IMAPFolder::IMAPFolder(const QString&t_name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
50 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) 50 : Folder( t_name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
51{ 51{
52 // Decode IMAP foldername 52 // Decode IMAP foldername
53 nameDisplay = IMAPFolder::decodeFolderName( name ); 53 nameDisplay = IMAPFolder::decodeFolderName( t_name );
54 name = nameDisplay ;
54 /* 55 /*
55 odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; 56 odebug << "folder " + name + " - displayed as " + nameDisplay << oendl;
56 */ 57 */
57 prefix = aprefix; 58 prefix = aprefix;
58 59
59 if (prefix.length()>0) { 60 if (prefix.length()>0) {
60 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 61 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
61 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 62 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
62 } 63 }
63 } 64 }
64} 65}
65 66
66IMAPFolder::~IMAPFolder() 67IMAPFolder::~IMAPFolder()
67{ 68{
68} 69}
69 70
70static unsigned char base64chars[] = 71static unsigned char base64chars[] =
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 72 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
72 73
73/** 74/**
74 * Decodes base64 encoded parts of the imapfolder name 75 * Decodes base64 encoded parts of the imapfolder name
75 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 76 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
76 */ 77 */
77QString IMAPFolder::decodeFolderName( const QString &name ) 78QString IMAPFolder::decodeFolderName( const QString &name )
78{ 79{
79 unsigned char c, i, bitcount; 80 unsigned char c, i, bitcount;
80 unsigned long ucs4, utf16, bitbuf; 81 unsigned long ucs4, utf16, bitbuf;
81 unsigned char base64[256], utf8[6]; 82 unsigned char base64[256], utf8[6];
82 unsigned long srcPtr = 0; 83 unsigned long srcPtr = 0;
83 QCString dst = ""; 84 QCString dst = "";
84 QCString src = name.ascii(); 85 QCString src = name.ascii();
85 86
86 /* initialize modified base64 decoding table */ 87 /* initialize modified base64 decoding table */
87 memset(base64, UNDEFINED, sizeof(base64)); 88 memset(base64, UNDEFINED, sizeof(base64));
88 for (i = 0; i < sizeof(base64chars); ++i) { 89 for (i = 0; i < sizeof(base64chars); ++i) {
89 base64[(int)base64chars[i]] = i; 90 base64[(int)base64chars[i]] = i;
90 } 91 }
91 92
92 /* loop until end of string */ 93 /* loop until end of string */
93 while (srcPtr < src.length ()) { 94 while (srcPtr < src.length ()) {
94 c = src[srcPtr++]; 95 c = src[srcPtr++];
95 /* deal with literal characters and &- */ 96 /* deal with literal characters and &- */
96 if (c != '&' || src[srcPtr] == '-') { 97 if (c != '&' || src[srcPtr] == '-') {
97 /* encode literally */ 98 /* encode literally */
98 dst += c; 99 dst += c;
99 /* skip over the '-' if this is an &- sequence */ 100 /* skip over the '-' if this is an &- sequence */
100 if (c == '&') 101 if (c == '&')
101 srcPtr++; 102 srcPtr++;
102 } else { 103 } else {
103 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 104 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
104 bitbuf = 0; 105 bitbuf = 0;
105 bitcount = 0; 106 bitcount = 0;
106 ucs4 = 0; 107 ucs4 = 0;
107 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 108 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
108 ++srcPtr; 109 ++srcPtr;
109 bitbuf = (bitbuf << 6) | c; 110 bitbuf = (bitbuf << 6) | c;
110 bitcount += 6; 111 bitcount += 6;
111 /* enough bits for a UTF-16 character? */ 112 /* enough bits for a UTF-16 character? */
112 if (bitcount >= 16) { 113 if (bitcount >= 16) {
113 bitcount -= 16; 114 bitcount -= 16;
114 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 115 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
115 /* convert UTF16 to UCS4 */ 116 /* convert UTF16 to UCS4 */
116 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 117 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
117 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 118 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
118 continue; 119 continue;
119 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 120 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
120 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 121 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
121 } else { 122 } else {
122 ucs4 = utf16; 123 ucs4 = utf16;
123 } 124 }
124 /* convert UTF-16 range of UCS4 to UTF-8 */ 125 /* convert UTF-16 range of UCS4 to UTF-8 */
125 if (ucs4 <= 0x7fUL) { 126 if (ucs4 <= 0x7fUL) {
126 utf8[0] = ucs4; 127 utf8[0] = ucs4;
127 i = 1; 128 i = 1;
128 } else if (ucs4 <= 0x7ffUL) { 129 } else if (ucs4 <= 0x7ffUL) {
129 utf8[0] = 0xc0 | (ucs4 >> 6); 130 utf8[0] = 0xc0 | (ucs4 >> 6);
130 utf8[1] = 0x80 | (ucs4 & 0x3f); 131 utf8[1] = 0x80 | (ucs4 & 0x3f);
131 i = 2; 132 i = 2;
132 } else if (ucs4 <= 0xffffUL) { 133 } else if (ucs4 <= 0xffffUL) {
133 utf8[0] = 0xe0 | (ucs4 >> 12); 134 utf8[0] = 0xe0 | (ucs4 >> 12);
134 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 135 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
135 utf8[2] = 0x80 | (ucs4 & 0x3f); 136 utf8[2] = 0x80 | (ucs4 & 0x3f);
136 i = 3; 137 i = 3;
137 } else { 138 } else {
138 utf8[0] = 0xf0 | (ucs4 >> 18); 139 utf8[0] = 0xf0 | (ucs4 >> 18);
139 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 140 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
140 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 141 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
141 utf8[3] = 0x80 | (ucs4 & 0x3f); 142 utf8[3] = 0x80 | (ucs4 & 0x3f);
142 i = 4; 143 i = 4;
143 } 144 }
144 /* copy it */ 145 /* copy it */
145 for (c = 0; c < i; ++c) { 146 for (c = 0; c < i; ++c) {
146 dst += utf8[c]; 147 dst += utf8[c];
147 } 148 }
148 } 149 }
149 } 150 }
150 /* skip over trailing '-' in modified UTF-7 encoding */ 151 /* skip over trailing '-' in modified UTF-7 encoding */
151 if (src[srcPtr] == '-') 152 if (src[srcPtr] == '-')
152 ++srcPtr; 153 ++srcPtr;
153 } 154 }
154 } 155 }
155 156
156 return QString::fromUtf8( dst.data() ); 157 return QString::fromUtf8( dst.data() );
157} 158}
158 159
159Mail::Mail() 160Mail::Mail()
160 :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 161 :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
161{ 162{
162} 163}
163 164
164MHFolder::MHFolder(const QString&disp_name,const QString&mbox) 165MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
165 : Folder( disp_name,"/" ) 166 : Folder( disp_name,"/" )
166{ 167{
167 separator = "/"; 168 separator = "/";
168 name = mbox; 169 name = mbox;
169 if (!disp_name.startsWith("/") && disp_name.length()>0) 170 if (!disp_name.startsWith("/") && disp_name.length()>0)
170 name+="/"; 171 name+="/";
171 name+=disp_name; 172 name+=disp_name;
172 if (disp_name.length()==0) { 173 if (disp_name.length()==0) {
173 nameDisplay = separator; 174 nameDisplay = separator;
174 } 175 }
175 prefix = mbox; 176 prefix = mbox;
176} 177}
177 178
178MHFolder::~MHFolder() 179MHFolder::~MHFolder()
179{ 180{
180} 181}
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h
index cefe64e..2ba908b 100644
--- a/kmicromail/libmailwrapper/mailwrapper.h
+++ b/kmicromail/libmailwrapper/mailwrapper.h
@@ -1,128 +1,128 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9#include <kiconloader.h> 9#include <kiconloader.h>
10 10
11#include "settings.h" 11#include "settings.h"
12 12
13#include <opie2/osmartpointer.h> 13#include <opie2/osmartpointer.h>
14/* 14/*
15class Attachment 15class Attachment
16{ 16{
17public: 17public:
18 Attachment( DocLnk lnk ); 18 Attachment( DocLnk lnk );
19 virtual ~Attachment(){} 19 virtual ~Attachment(){}
20 const QString getFileName()const{ return doc.file(); } 20 const QString getFileName()const{ return doc.file(); }
21 const QString getName()const{ return doc.name(); } 21 const QString getName()const{ return doc.name(); }
22 const QString getMimeType()const{ return doc.type(); } 22 const QString getMimeType()const{ return doc.type(); }
23 const QPixmap getPixmap()const{ return doc.pixmap(); } 23 const QPixmap getPixmap()const{ return doc.pixmap(); }
24 const int getSize()const { return size; } 24 const int getSize()const { return size; }
25 DocLnk getDocLnk() { return doc; } 25 DocLnk getDocLnk() { return doc; }
26 26
27protected: 27protected:
28 DocLnk doc; 28 DocLnk doc;
29 int size; 29 int size;
30 30
31}; 31};
32*/ 32*/
33 33
34class Attachment 34class Attachment
35{ 35{
36public: 36public:
37 Attachment( QString lnk ); 37 Attachment( QString lnk );
38 virtual ~Attachment(){} 38 virtual ~Attachment(){}
39 const QString getFileName()const{ return doc; } 39 const QString getFileName()const{ return doc; }
40 const QString getName()const{ return QFileInfo( doc ).baseName (); } 40 const QString getName()const{ return QFileInfo( doc ).baseName (); }
41 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } 41 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); }
42 const QPixmap getPixmap()const{ return mPix; } 42 const QPixmap getPixmap()const{ return mPix; }
43 const int getSize()const { return size; } 43 const int getSize()const { return size; }
44 QString getDocLnk() { return doc; } 44 QString getDocLnk() { return doc; }
45 45
46protected: 46protected:
47 QPixmap mPix; 47 QPixmap mPix;
48 QString doc; 48 QString doc;
49 int size; 49 int size;
50 50
51}; 51};
52 52
53class Mail:public Opie::Core::ORefCount 53class Mail:public Opie::Core::ORefCount
54{ 54{
55public: 55public:
56 Mail(); 56 Mail();
57 /* Possible that this destructor must not be declared virtual 57 /* Possible that this destructor must not be declared virtual
58 * 'cause it seems that it will never have some child classes. 58 * 'cause it seems that it will never have some child classes.
59 * in this case this object will not get a virtual table -> memory and 59 * in this case this object will not get a virtual table -> memory and
60 * speed will be a little bit better? 60 * speed will be a little bit better?
61 */ 61 */
62 virtual ~Mail(){} 62 virtual ~Mail(){}
63 void addAttachment( Attachment *att ) { attList.append( att ); } 63 void addAttachment( Attachment *att ) { attList.append( att ); }
64 const QList<Attachment>& getAttachments()const { return attList; } 64 const QList<Attachment>& getAttachments()const { return attList; }
65 void removeAttachment( Attachment *att ) { attList.remove( att ); } 65 void removeAttachment( Attachment *att ) { attList.remove( att ); }
66 const QString&getName()const { return name; } 66 const QString&getName()const { return name; }
67 void setName( QString s ) { name = s; } 67 void setName( QString s ) { name = s; }
68 const QString&getMail()const{ return mail; } 68 const QString&getMail()const{ return mail; }
69 void setMail( const QString&s ) { mail = s; } 69 void setMail( const QString&s ) { mail = s; }
70 const QString&getTo()const{ return to; } 70 const QString&getTo()const{ return to; }
71 void setTo( const QString&s ) { to = s; } 71 void setTo( const QString&s ) { to = s; }
72 const QString&getCC()const{ return cc; } 72 const QString&getCC()const{ return cc; }
73 void setCC( const QString&s ) { cc = s; } 73 void setCC( const QString&s ) { cc = s; }
74 const QString&getBCC()const { return bcc; } 74 const QString&getBCC()const { return bcc; }
75 void setBCC( const QString&s ) { bcc = s; } 75 void setBCC( const QString&s ) { bcc = s; }
76 const QString&getMessage()const { return message; } 76 const QString&getMessage()const { return message; }
77 void setMessage( const QString&s ) { message = s; } 77 void setMessage( const QString&s ) { message = s; }
78 const QString&getSubject()const { return subject; } 78 const QString&getSubject()const { return subject; }
79 void setSubject( const QString&s ) { subject = s; } 79 void setSubject( const QString&s ) { subject = s; }
80 const QString&getReply()const{ return reply; } 80 const QString&getReply()const{ return reply; }
81 void setReply( const QString&a ) { reply = a; } 81 void setReply( const QString&a ) { reply = a; }
82 void setInreply(const QStringList&list){m_in_reply_to = list;} 82 void setInreply(const QStringList&list){m_in_reply_to = list;}
83 const QStringList&Inreply()const{return m_in_reply_to;} 83 const QStringList&Inreply()const{return m_in_reply_to;}
84 84
85private: 85private:
86 QList<Attachment> attList; 86 QList<Attachment> attList;
87 QString name, mail, to, cc, bcc, reply, subject, message; 87 QString name, mail, to, cc, bcc, reply, subject, message;
88 QStringList m_in_reply_to; 88 QStringList m_in_reply_to;
89}; 89};
90 90
91class Folder:public Opie::Core::ORefCount 91class Folder:public Opie::Core::ORefCount
92{ 92{
93public: 93public:
94 Folder( const QString&init_name,const QString&sep ); 94 Folder( const QString&init_name,const QString&sep );
95 virtual ~Folder(); 95 virtual ~Folder();
96 const QString&getDisplayName()const { return nameDisplay; } 96 const QString&getDisplayName()const { return nameDisplay; }
97 const QString&getName()const { return name; } 97 const QString&getName()const { return name; }
98 const QString&getPrefix()const{return prefix; } 98 const QString&getPrefix()const{return prefix; }
99 virtual bool may_select()const{return true;} 99 virtual bool may_select()const{return true;}
100 virtual bool no_inferior()const{return true;} 100 virtual bool no_inferior()const{return true;}
101 const QString&Separator()const; 101 const QString&Separator()const;
102 102
103protected: 103protected:
104 QString nameDisplay, name, separator,prefix; 104 QString nameDisplay, name, separator,prefix;
105}; 105};
106 106
107typedef Opie::Core::OSmartPointer<Folder> FolderP; 107typedef Opie::Core::OSmartPointer<Folder> FolderP;
108 108
109class MHFolder : public Folder 109class MHFolder : public Folder
110{ 110{
111public: 111public:
112 MHFolder(const QString&disp_name,const QString&mbox); 112 MHFolder(const QString&disp_name,const QString&mbox);
113 virtual ~MHFolder(); 113 virtual ~MHFolder();
114}; 114};
115 115
116class IMAPFolder : public Folder 116class IMAPFolder : public Folder
117{ 117{
118 public: 118 public:
119 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); 119 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
120 virtual ~IMAPFolder(); 120 virtual ~IMAPFolder();
121 virtual bool may_select()const{return m_MaySelect;} 121 virtual bool may_select()const{return m_MaySelect;}
122 virtual bool no_inferior()const{return m_NoInferior;} 122 virtual bool no_inferior()const{return m_NoInferior;}
123 private:
124 static QString decodeFolderName( const QString &name ); 123 static QString decodeFolderName( const QString &name );
124 private:
125 bool m_MaySelect,m_NoInferior; 125 bool m_MaySelect,m_NoInferior;
126}; 126};
127 127
128#endif 128#endif