summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/mailwrapper.cpp
authorzautrix <zautrix>2004-07-03 16:33:12 (UTC)
committer zautrix <zautrix>2004-07-03 16:33:12 (UTC)
commite3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff)
tree162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/libmailwrapper/mailwrapper.cpp
parent2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff)
downloadkdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2
Initial revision
Diffstat (limited to 'kmicromail/libmailwrapper/mailwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.cpp180
1 files changed, 180 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/mailwrapper.cpp b/kmicromail/libmailwrapper/mailwrapper.cpp
new file mode 100644
index 0000000..9400649
--- a/dev/null
+++ b/kmicromail/libmailwrapper/mailwrapper.cpp
@@ -0,0 +1,180 @@
1#include <stdlib.h>
2#include <sys/stat.h>
3#include <sys/types.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <string.h>
7#include <qdir.h>
8
9#include "mailwrapper.h"
10//#include "logindialog.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
23
24using namespace Opie::Core;
25Attachment::Attachment( QString lnk )
26{
27 doc = lnk;
28 size = QFileInfo( doc ).size();
29 mPix = SmallIcon( "files" );
30}
31
32Folder::Folder(const QString&tmp_name, const QString&sep )
33{
34 name = tmp_name;
35 nameDisplay = name;
36 separator = sep;
37 prefix = "";
38}
39
40Folder::~Folder()
41{
42}
43
44const QString& Folder::Separator()const
45{
46 return separator;
47}
48
49IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
50 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
51{
52 // Decode IMAP foldername
53 nameDisplay = IMAPFolder::decodeFolderName( name );
54 /*
55 odebug << "folder " + name + " - displayed as " + nameDisplay << oendl;
56 */
57 prefix = aprefix;
58
59 if (prefix.length()>0) {
60 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
61 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
62 }
63 }
64}
65
66IMAPFolder::~IMAPFolder()
67{
68}
69
70static unsigned char base64chars[] =
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
72
73/**
74 * Decodes base64 encoded parts of the imapfolder name
75 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
76 */
77QString IMAPFolder::decodeFolderName( const QString &name )
78{
79 unsigned char c, i, bitcount;
80 unsigned long ucs4, utf16, bitbuf;
81 unsigned char base64[256], utf8[6];
82 unsigned long srcPtr = 0;
83 QCString dst = "";
84 QCString src = name.ascii();
85
86 /* initialize modified base64 decoding table */
87 memset(base64, UNDEFINED, sizeof(base64));
88 for (i = 0; i < sizeof(base64chars); ++i) {
89 base64[(int)base64chars[i]] = i;
90 }
91
92 /* loop until end of string */
93 while (srcPtr < src.length ()) {
94 c = src[srcPtr++];
95 /* deal with literal characters and &- */
96 if (c != '&' || src[srcPtr] == '-') {
97 /* encode literally */
98 dst += c;
99 /* skip over the '-' if this is an &- sequence */
100 if (c == '&')
101 srcPtr++;
102 } else {
103 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
104 bitbuf = 0;
105 bitcount = 0;
106 ucs4 = 0;
107 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
108 ++srcPtr;
109 bitbuf = (bitbuf << 6) | c;
110 bitcount += 6;
111 /* enough bits for a UTF-16 character? */
112 if (bitcount >= 16) {
113 bitcount -= 16;
114 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
115 /* convert UTF16 to UCS4 */
116 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
117 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
118 continue;
119 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
120 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
121 } else {
122 ucs4 = utf16;
123 }
124 /* convert UTF-16 range of UCS4 to UTF-8 */
125 if (ucs4 <= 0x7fUL) {
126 utf8[0] = ucs4;
127 i = 1;
128 } else if (ucs4 <= 0x7ffUL) {
129 utf8[0] = 0xc0 | (ucs4 >> 6);
130 utf8[1] = 0x80 | (ucs4 & 0x3f);
131 i = 2;
132 } else if (ucs4 <= 0xffffUL) {
133 utf8[0] = 0xe0 | (ucs4 >> 12);
134 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
135 utf8[2] = 0x80 | (ucs4 & 0x3f);
136 i = 3;
137 } else {
138 utf8[0] = 0xf0 | (ucs4 >> 18);
139 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
140 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
141 utf8[3] = 0x80 | (ucs4 & 0x3f);
142 i = 4;
143 }
144 /* copy it */
145 for (c = 0; c < i; ++c) {
146 dst += utf8[c];
147 }
148 }
149 }
150 /* skip over trailing '-' in modified UTF-7 encoding */
151 if (src[srcPtr] == '-')
152 ++srcPtr;
153 }
154 }
155
156 return QString::fromUtf8( dst.data() );
157}
158
159Mail::Mail()
160 :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
161{
162}
163
164MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
165 : Folder( disp_name,"/" )
166{
167 separator = "/";
168 name = mbox;
169 if (!disp_name.startsWith("/") && disp_name.length()>0)
170 name+="/";
171 name+=disp_name;
172 if (disp_name.length()==0) {
173 nameDisplay = separator;
174 }
175 prefix = mbox;
176}
177
178MHFolder::~MHFolder()
179{
180}