summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/mailwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/mailwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp15
1 files changed, 13 insertions, 2 deletions
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,107 +1,118 @@
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
13Attachment::Attachment( DocLnk lnk ) 24Attachment::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
19Folder::Folder(const QString&tmp_name, const QString&sep ) 30Folder::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
26const QString& Folder::Separator()const 37const QString& Folder::Separator()const
27{ 38{
28 return separator; 39 return separator;
29} 40}
30 41
31IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) 42IMAPFolder::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
45static unsigned char base64chars[] = 56static 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 */
52QString IMAPFolder::decodeFolderName( const QString &name ) 63QString 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) {