-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index d71d35c..ac6f380 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,166 +1,166 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "nntpwrapper.h" | 4 | #include "nntpwrapper.h" |
5 | #include "mhwrapper.h" | 5 | #include "mhwrapper.h" |
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | 7 | ||
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <libetpan/mailmime_content.h> | 11 | #include <libetpan/mailmime_content.h> |
12 | #include <libetpan/mailmime.h> | 12 | #include <libetpan/mailmime.h> |
13 | 13 | ||
14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
15 | { | 15 | { |
16 | return new IMAPwrapper(a); | 16 | return new IMAPwrapper(a); |
17 | } | 17 | } |
18 | 18 | ||
19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
20 | { | 20 | { |
21 | return new POP3wrapper(a); | 21 | return new POP3wrapper(a); |
22 | } | 22 | } |
23 | 23 | ||
24 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 24 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
25 | { | 25 | { |
26 | return new NNTPwrapper(a); | 26 | return new NNTPwrapper(a); |
27 | } | 27 | } |
28 | 28 | ||
29 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 29 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
30 | { | 30 | { |
31 | return new MHwrapper(a,name); | 31 | return new MHwrapper(a,name); |
32 | } | 32 | } |
33 | 33 | ||
34 | AbstractMail* AbstractMail::getWrapper(Account*a) | 34 | AbstractMail* AbstractMail::getWrapper(Account*a) |
35 | { | 35 | { |
36 | if (!a) return 0; | 36 | if (!a) return 0; |
37 | switch (a->getType()) { | 37 | switch (a->getType()) { |
38 | case MAILLIB::A_IMAP: | 38 | case MAILLIB::A_IMAP: |
39 | return new IMAPwrapper((IMAPaccount*)a); | 39 | return new IMAPwrapper((IMAPaccount*)a); |
40 | break; | 40 | break; |
41 | case MAILLIB::A_POP3: | 41 | case MAILLIB::A_POP3: |
42 | return new POP3wrapper((POP3account*)a); | 42 | return new POP3wrapper((POP3account*)a); |
43 | break; | 43 | break; |
44 | case MAILLIB::A_NNTP: | 44 | case MAILLIB::A_NNTP: |
45 | return new NNTPwrapper((NNTPaccount*)a); | 45 | return new NNTPwrapper((NNTPaccount*)a); |
46 | break; | 46 | break; |
47 | default: | 47 | default: |
48 | return 0; | 48 | return 0; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 52 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
53 | { | 53 | { |
54 | qDebug("Decode string start"); | 54 | qDebug("Decode string start"); |
55 | char*result_text; | 55 | char*result_text; |
56 | size_t index = 0; | 56 | size_t index = 0; |
57 | /* reset for recursive use! */ | 57 | /* reset for recursive use! */ |
58 | size_t target_length = 0; | 58 | size_t target_length = 0; |
59 | result_text = 0; | 59 | result_text = 0; |
60 | int mimetype = MAILMIME_MECHANISM_7BIT; | 60 | int mimetype = MAILMIME_MECHANISM_7BIT; |
61 | if (enc.lower()=="quoted-printable") { | 61 | if (enc.lower()=="quoted-printable") { |
62 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 62 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
63 | } else if (enc.lower()=="base64") { | 63 | } else if (enc.lower()=="base64") { |
64 | mimetype = MAILMIME_MECHANISM_BASE64; | 64 | mimetype = MAILMIME_MECHANISM_BASE64; |
65 | } else if (enc.lower()=="8bit") { | 65 | } else if (enc.lower()=="8bit") { |
66 | mimetype = MAILMIME_MECHANISM_8BIT; | 66 | mimetype = MAILMIME_MECHANISM_8BIT; |
67 | } else if (enc.lower()=="binary") { | 67 | } else if (enc.lower()=="binary") { |
68 | mimetype = MAILMIME_MECHANISM_BINARY; | 68 | mimetype = MAILMIME_MECHANISM_BINARY; |
69 | } | 69 | } |
70 | 70 | ||
71 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 71 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
72 | &result_text,&target_length); | 72 | &result_text,&target_length); |
73 | 73 | ||
74 | encodedString* result = new encodedString(); | 74 | encodedString* result = new encodedString(); |
75 | if (err == MAILIMF_NO_ERROR) { | 75 | if (err == MAILIMF_NO_ERROR) { |
76 | result->setContent(result_text,target_length); | 76 | result->setContent(result_text,target_length); |
77 | } | 77 | } |
78 | qDebug("Decode string finished"); | 78 | qDebug("Decode string finished"); |
79 | return result; | 79 | return result; |
80 | } | 80 | } |
81 | 81 | ||
82 | QString AbstractMail::convert_String(const char*text) | 82 | QString AbstractMail::convert_String(const char*text) |
83 | { | 83 | { |
84 | size_t index = 0; | 84 | size_t index = 0; |
85 | char*res = 0; | 85 | char*res = 0; |
86 | int err = MAILIMF_NO_ERROR; | ||
86 | 87 | ||
87 | /* attention - doesn't work with arm systems! */ | 88 | QString result(text); |
88 | int err = mailmime_encoded_phrase_parse("iso-8859-1", | 89 | |
89 | text, strlen(text),&index, "iso-8859-1",&res); | 90 | /* due a bug in libetpan it isn't usable this moment */ |
90 | if (err != MAILIMF_NO_ERROR) { | 91 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", |
91 | if (res) free(res); | 92 | text, strlen(text),&index, "iso-8859-1",&res);*/ |
92 | return QString(text); | 93 | //qDebug("Input: %s",text); |
93 | } | 94 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
94 | if (res) { | 95 | // result = QString(res); |
95 | QString result(res); | 96 | // qDebug("Res: %s, length: %i",res,strlen(res)); |
96 | free(res); | ||
97 | return result; | ||
98 | } | 97 | } |
99 | return QString(text); | 98 | if (res) free(res); |
99 | return result; | ||
100 | } | 100 | } |
101 | 101 | ||
102 | /* cp & paste from launcher */ | 102 | /* cp & paste from launcher */ |
103 | QString AbstractMail::gen_attachment_id() | 103 | QString AbstractMail::gen_attachment_id() |
104 | { | 104 | { |
105 | QFile file( "/proc/sys/kernel/random/uuid" ); | 105 | QFile file( "/proc/sys/kernel/random/uuid" ); |
106 | if (!file.open(IO_ReadOnly ) ) | 106 | if (!file.open(IO_ReadOnly ) ) |
107 | return QString::null; | 107 | return QString::null; |
108 | 108 | ||
109 | QTextStream stream(&file); | 109 | QTextStream stream(&file); |
110 | 110 | ||
111 | return "{" + stream.read().stripWhiteSpace() + "}"; | 111 | return "{" + stream.read().stripWhiteSpace() + "}"; |
112 | } | 112 | } |
113 | 113 | ||
114 | int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) | 114 | int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) |
115 | { | 115 | { |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | 118 | ||
119 | QString AbstractMail::defaultLocalfolder() | 119 | QString AbstractMail::defaultLocalfolder() |
120 | { | 120 | { |
121 | QString f = getenv( "HOME" ); | 121 | QString f = getenv( "HOME" ); |
122 | f += "/Applications/opiemail/localmail"; | 122 | f += "/Applications/opiemail/localmail"; |
123 | return f; | 123 | return f; |
124 | } | 124 | } |
125 | 125 | ||
126 | QString AbstractMail::draftFolder() | 126 | QString AbstractMail::draftFolder() |
127 | { | 127 | { |
128 | return QString("Drafts"); | 128 | return QString("Drafts"); |
129 | } | 129 | } |
130 | 130 | ||
131 | /* temporary - will be removed when implemented in all classes */ | 131 | /* temporary - will be removed when implemented in all classes */ |
132 | void AbstractMail::deleteMails(const QString &,QList<RecMail> &) | 132 | void AbstractMail::deleteMails(const QString &,QList<RecMail> &) |
133 | { | 133 | { |
134 | } | 134 | } |
135 | 135 | ||
136 | void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 136 | void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
137 | { | 137 | { |
138 | QList<RecMail> t; | 138 | QList<RecMail> t; |
139 | listMessages(fromFolder->getName(),t); | 139 | listMessages(fromFolder->getName(),t); |
140 | encodedString*st = 0; | 140 | encodedString*st = 0; |
141 | while (t.count()>0) { | 141 | while (t.count()>0) { |
142 | RecMail*r = t.at(0); | 142 | RecMail*r = t.at(0); |
143 | st = fetchRawBody(*r); | 143 | st = fetchRawBody(*r); |
144 | if (st) { | 144 | if (st) { |
145 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 145 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
146 | delete st; | 146 | delete st; |
147 | } | 147 | } |
148 | t.removeFirst(); | 148 | t.removeFirst(); |
149 | } | 149 | } |
150 | if (moveit) { | 150 | if (moveit) { |
151 | deleteAllMail(fromFolder); | 151 | deleteAllMail(fromFolder); |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 155 | void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
156 | { | 156 | { |
157 | encodedString*st = 0; | 157 | encodedString*st = 0; |
158 | st = fetchRawBody(mail); | 158 | st = fetchRawBody(mail); |
159 | if (st) { | 159 | if (st) { |
160 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 160 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
161 | delete st; | 161 | delete st; |
162 | } | 162 | } |
163 | if (moveit) { | 163 | if (moveit) { |
164 | deleteMail(mail); | 164 | deleteMail(mail); |
165 | } | 165 | } |
166 | } | 166 | } |