summaryrefslogtreecommitdiff
path: root/noncore/net/mail/mailwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/mailwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/mailwrapper.cpp137
1 files changed, 0 insertions, 137 deletions
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
deleted file mode 100644
index 9398823..0000000
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/dev/null
@@ -1,137 +0,0 @@
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
13Attachment::Attachment( DocLnk lnk )
14{
15 doc = lnk;
16 size = QFileInfo( doc.file() ).size();
17}
18
19Folder::Folder(const QString&tmp_name, const QString&sep )
20{
21 name = tmp_name;
22 nameDisplay = name;
23 separator = sep;
24}
25
26const QString& Folder::Separator()const
27{
28 return separator;
29}
30
31IMAPFolder::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)
33{
34 // Decode IMAP foldername
35 nameDisplay = IMAPFolder::decodeFolderName( name );
36 qDebug( "folder " + name + " - displayed as " + nameDisplay );
37
38 if (prefix.length()>0) {
39 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
40 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
41 }
42 }
43}
44
45static unsigned char base64chars[] =
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
47
48/**
49 * Decodes base64 encoded parts of the imapfolder name
50 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
51 */
52QString IMAPFolder::decodeFolderName( const QString &name )
53{
54 unsigned char c, i, bitcount;
55 unsigned long ucs4, utf16, bitbuf;
56 unsigned char base64[256], utf8[6];
57 unsigned long srcPtr = 0;
58 QCString dst = "";
59 QCString src = name.ascii();
60
61 /* initialize modified base64 decoding table */
62 memset(base64, UNDEFINED, sizeof(base64));
63 for (i = 0; i < sizeof(base64chars); ++i) {
64 base64[(int)base64chars[i]] = i;
65 }
66
67 /* loop until end of string */
68 while (srcPtr < src.length ()) {
69 c = src[srcPtr++];
70 /* deal with literal characters and &- */
71 if (c != '&' || src[srcPtr] == '-') {
72 /* encode literally */
73 dst += c;
74 /* skip over the '-' if this is an &- sequence */
75 if (c == '&')
76 srcPtr++;
77 } else {
78 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
79 bitbuf = 0;
80 bitcount = 0;
81 ucs4 = 0;
82 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
83 ++srcPtr;
84 bitbuf = (bitbuf << 6) | c;
85 bitcount += 6;
86 /* enough bits for a UTF-16 character? */
87 if (bitcount >= 16) {
88 bitcount -= 16;
89 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
90 /* convert UTF16 to UCS4 */
91 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
92 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
93 continue;
94 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
95 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
96 } else {
97 ucs4 = utf16;
98 }
99 /* convert UTF-16 range of UCS4 to UTF-8 */
100 if (ucs4 <= 0x7fUL) {
101 utf8[0] = ucs4;
102 i = 1;
103 } else if (ucs4 <= 0x7ffUL) {
104 utf8[0] = 0xc0 | (ucs4 >> 6);
105 utf8[1] = 0x80 | (ucs4 & 0x3f);
106 i = 2;
107 } else if (ucs4 <= 0xffffUL) {
108 utf8[0] = 0xe0 | (ucs4 >> 12);
109 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
110 utf8[2] = 0x80 | (ucs4 & 0x3f);
111 i = 3;
112 } else {
113 utf8[0] = 0xf0 | (ucs4 >> 18);
114 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
115 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
116 utf8[3] = 0x80 | (ucs4 & 0x3f);
117 i = 4;
118 }
119 /* copy it */
120 for (c = 0; c < i; ++c) {
121 dst += utf8[c];
122 }
123 }
124 }
125 /* skip over trailing '-' in modified UTF-7 encoding */
126 if (src[srcPtr] == '-')
127 ++srcPtr;
128 }
129 }
130
131 return QString::fromUtf8( dst.data() );
132}
133
134Mail::Mail()
135 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
136{
137}