-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 9 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 16 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 19 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mboxwrapper.cpp | 1 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 1 |
5 files changed, 41 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 8ee112c..ed5c898 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -1,230 +1,231 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "abstractmail.h" | 2 | #include "abstractmail.h" |
3 | #include "imapwrapper.h" | 3 | #include "imapwrapper.h" |
4 | #include "pop3wrapper.h" | 4 | #include "pop3wrapper.h" |
5 | #include "nntpwrapper.h" | 5 | #include "nntpwrapper.h" |
6 | #include "mhwrapper.h" | 6 | #include "mhwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qprogressbar.h> | 11 | #include <qprogressbar.h> |
12 | #include <qapplication.h> | 12 | #include <qapplication.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | #include <klocale.h> | 14 | #include <klocale.h> |
15 | #include <kdecore/kstandarddirs.h> | 15 | #include <kdecore/kstandarddirs.h> |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qtextstream.h> | 17 | #include <qtextstream.h> |
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | #include <libetpan/mailmime_content.h> | 19 | #include <libetpan/mailmime_content.h> |
20 | #include <libetpan/mailmime.h> | 20 | #include <libetpan/mailmime.h> |
21 | 21 | ||
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
24 | { | 24 | { |
25 | return new IMAPwrapper(a); | 25 | return new IMAPwrapper(a); |
26 | } | 26 | } |
27 | 27 | ||
28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
29 | { | 29 | { |
30 | return new POP3wrapper(a); | 30 | return new POP3wrapper(a); |
31 | } | 31 | } |
32 | 32 | ||
33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
34 | { | 34 | { |
35 | return new NNTPwrapper(a); | 35 | return new NNTPwrapper(a); |
36 | } | 36 | } |
37 | 37 | ||
38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
39 | { | 39 | { |
40 | return new MHwrapper(a,name); | 40 | return new MHwrapper(a,name); |
41 | } | 41 | } |
42 | 42 | ||
43 | AbstractMail* AbstractMail::getWrapper(Account*a) | 43 | AbstractMail* AbstractMail::getWrapper(Account*a) |
44 | { | 44 | { |
45 | if (!a) return 0; | 45 | if (!a) return 0; |
46 | switch (a->getType()) { | 46 | switch (a->getType()) { |
47 | case MAILLIB::A_IMAP: | 47 | case MAILLIB::A_IMAP: |
48 | return new IMAPwrapper((IMAPaccount*)a); | 48 | return new IMAPwrapper((IMAPaccount*)a); |
49 | break; | 49 | break; |
50 | case MAILLIB::A_POP3: | 50 | case MAILLIB::A_POP3: |
51 | return new POP3wrapper((POP3account*)a); | 51 | return new POP3wrapper((POP3account*)a); |
52 | break; | 52 | break; |
53 | case MAILLIB::A_NNTP: | 53 | case MAILLIB::A_NNTP: |
54 | return new NNTPwrapper((NNTPaccount*)a); | 54 | return new NNTPwrapper((NNTPaccount*)a); |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | return 0; | 57 | return 0; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
62 | { | 62 | { |
63 | // odebug << "Decode string start" << oendl; | 63 | // odebug << "Decode string start" << oendl; |
64 | char*result_text; | 64 | char*result_text; |
65 | size_t index = 0; | 65 | size_t index = 0; |
66 | /* reset for recursive use! */ | 66 | /* reset for recursive use! */ |
67 | size_t target_length = 0; | 67 | size_t target_length = 0; |
68 | result_text = 0; | 68 | result_text = 0; |
69 | int mimetype = MAILMIME_MECHANISM_7BIT; | 69 | int mimetype = MAILMIME_MECHANISM_7BIT; |
70 | if (enc.lower()=="quoted-printable") { | 70 | if (enc.lower()=="quoted-printable") { |
71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
72 | } else if (enc.lower()=="base64") { | 72 | } else if (enc.lower()=="base64") { |
73 | mimetype = MAILMIME_MECHANISM_BASE64; | 73 | mimetype = MAILMIME_MECHANISM_BASE64; |
74 | } else if (enc.lower()=="8bit") { | 74 | } else if (enc.lower()=="8bit") { |
75 | mimetype = MAILMIME_MECHANISM_8BIT; | 75 | mimetype = MAILMIME_MECHANISM_8BIT; |
76 | } else if (enc.lower()=="binary") { | 76 | } else if (enc.lower()=="binary") { |
77 | mimetype = MAILMIME_MECHANISM_BINARY; | 77 | mimetype = MAILMIME_MECHANISM_BINARY; |
78 | } | 78 | } |
79 | |||
80 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 79 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
81 | &result_text,&target_length); | 80 | &result_text,&target_length); |
82 | 81 | ||
83 | encodedString* result = new encodedString(); | 82 | encodedString* result = new encodedString(); |
84 | if (err == MAILIMF_NO_ERROR) { | 83 | if (err == MAILIMF_NO_ERROR) { |
85 | result->setContent(result_text,target_length); | 84 | result->setContent(result_text,target_length); |
86 | } | 85 | } |
87 | //odebug << "Decode string finished" << oendl; | 86 | //odebug << "Decode string finished" << oendl; |
88 | return result; | 87 | return result; |
89 | } | 88 | } |
90 | 89 | ||
91 | QString AbstractMail::convert_String(const char*text) | 90 | QString AbstractMail::convert_String(const char*text) |
92 | { | 91 | { |
93 | size_t index = 0; | 92 | size_t index = 0; |
94 | char*res = 0; | 93 | char*res = 0; |
95 | int err = MAILIMF_NO_ERROR; | 94 | int err = MAILIMF_NO_ERROR; |
96 | 95 | ||
97 | QString result(text); | 96 | QString result(text); |
98 | 97 | //qDebug("convert_String %s ", text); | |
98 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | ||
99 | // text, strlen(text),&index, "iso-8859-1",&res); | ||
99 | err = mailmime_encoded_phrase_parse("iso-8859-1", | 100 | err = mailmime_encoded_phrase_parse("iso-8859-1", |
100 | text, strlen(text),&index, "iso-8859-1",&res); | 101 | text, strlen(text),&index, "utf-8",&res); |
101 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 102 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
102 | result = QString(res); | 103 | result = QString::fromUtf8(res); |
103 | } | 104 | } |
104 | //qDebug("convert_String:%s ",result.latin1() ); | 105 | //qDebug("convert_String:%s ",result.latin1() ); |
105 | if (res) free(res); | 106 | if (res) free(res); |
106 | return result; | 107 | return result; |
107 | } | 108 | } |
108 | 109 | ||
109 | /* cp & paste from launcher */ | 110 | /* cp & paste from launcher */ |
110 | QString AbstractMail::gen_attachment_id() | 111 | QString AbstractMail::gen_attachment_id() |
111 | { | 112 | { |
112 | QFile file( "/proc/sys/kernel/random/uuid" ); | 113 | QFile file( "/proc/sys/kernel/random/uuid" ); |
113 | if (!file.open(IO_ReadOnly ) ) | 114 | if (!file.open(IO_ReadOnly ) ) |
114 | return QString::null; | 115 | return QString::null; |
115 | 116 | ||
116 | QTextStream stream(&file); | 117 | QTextStream stream(&file); |
117 | 118 | ||
118 | return "{" + stream.read().stripWhiteSpace() + "}"; | 119 | return "{" + stream.read().stripWhiteSpace() + "}"; |
119 | } | 120 | } |
120 | 121 | ||
121 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 122 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
122 | { | 123 | { |
123 | return 0; | 124 | return 0; |
124 | } | 125 | } |
125 | 126 | ||
126 | QString AbstractMail::defaultLocalfolder() | 127 | QString AbstractMail::defaultLocalfolder() |
127 | { | 128 | { |
128 | // QString f = getenv( "HOME" ); | 129 | // QString f = getenv( "HOME" ); |
129 | QString f = locateLocal( "data", "kopiemail/localmail"); | 130 | QString f = locateLocal( "data", "kopiemail/localmail"); |
130 | // f += "/Applications/opiemail/localmail"; | 131 | // f += "/Applications/opiemail/localmail"; |
131 | return f; | 132 | return f; |
132 | } | 133 | } |
133 | 134 | ||
134 | QString AbstractMail::draftFolder() | 135 | QString AbstractMail::draftFolder() |
135 | { | 136 | { |
136 | return QString("Drafts"); | 137 | return QString("Drafts"); |
137 | } | 138 | } |
138 | 139 | ||
139 | /* temporary - will be removed when implemented in all classes */ | 140 | /* temporary - will be removed when implemented in all classes */ |
140 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 141 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) |
141 | { | 142 | { |
142 | } | 143 | } |
143 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) | 144 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) |
144 | { | 145 | { |
145 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); | 146 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); |
146 | // this is currently re-implemented in pop3wrapper and imapwrapper | 147 | // this is currently re-implemented in pop3wrapper and imapwrapper |
147 | int iii = 0; | 148 | int iii = 0; |
148 | int count = target.count(); | 149 | int count = target.count(); |
149 | QProgressBar wid ( count ); | 150 | QProgressBar wid ( count ); |
150 | wid.setCaption( i18n("Deleting ...")); | 151 | wid.setCaption( i18n("Deleting ...")); |
151 | wid.show(); | 152 | wid.show(); |
152 | while (iii < count ) { | 153 | while (iii < count ) { |
153 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 154 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
154 | wid.setProgress( iii ); | 155 | wid.setProgress( iii ); |
155 | wid.raise(); | 156 | wid.raise(); |
156 | qApp->processEvents(); | 157 | qApp->processEvents(); |
157 | RecMailP mail = (*target.at( iii )); | 158 | RecMailP mail = (*target.at( iii )); |
158 | deleteMail(mail); | 159 | deleteMail(mail); |
159 | ++iii; | 160 | ++iii; |
160 | } | 161 | } |
161 | } | 162 | } |
162 | 163 | ||
163 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) | 164 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) |
164 | { | 165 | { |
165 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); | 166 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); |
166 | // get local folder | 167 | // get local folder |
167 | Account * acc = getAccount(); | 168 | Account * acc = getAccount(); |
168 | if ( !acc ) return; | 169 | if ( !acc ) return; |
169 | QString lfName = acc->getLocalFolder(); | 170 | QString lfName = acc->getLocalFolder(); |
170 | if ( lfName.isEmpty() ) | 171 | if ( lfName.isEmpty() ) |
171 | lfName = acc->getAccountName(); | 172 | lfName = acc->getAccountName(); |
172 | // create local folder | 173 | // create local folder |
173 | if ( !targetMail->createMbox(lfName)) | 174 | if ( !targetMail->createMbox(lfName)) |
174 | { | 175 | { |
175 | QMessageBox::critical(0,i18n("Error creating new Folder"), | 176 | QMessageBox::critical(0,i18n("Error creating new Folder"), |
176 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); | 177 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); |
177 | return; | 178 | return; |
178 | } | 179 | } |
179 | QValueList<RecMailP> t; | 180 | QValueList<RecMailP> t; |
180 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); | 181 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); |
181 | if ( t.count() == 0 ) { | 182 | if ( t.count() == 0 ) { |
182 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); | 183 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); |
183 | Global::statusMessage(i18n("There are no new messages")); | 184 | Global::statusMessage(i18n("There are no new messages")); |
184 | return; | 185 | return; |
185 | } | 186 | } |
186 | QValueList<RecMailP> e; | 187 | QValueList<RecMailP> e; |
187 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); | 188 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); |
188 | //qDebug("target has mails %d ", e.count()); | 189 | //qDebug("target has mails %d ", e.count()); |
189 | QValueList<RecMailP> n; | 190 | QValueList<RecMailP> n; |
190 | int iii = 0; | 191 | int iii = 0; |
191 | int count = t.count(); | 192 | int count = t.count(); |
192 | while (iii < count ) { | 193 | while (iii < count ) { |
193 | RecMailP r = (*t.at( iii )); | 194 | RecMailP r = (*t.at( iii )); |
194 | bool found = false; | 195 | bool found = false; |
195 | int jjj = 0; | 196 | int jjj = 0; |
196 | int countE = e.count(); | 197 | int countE = e.count(); |
197 | while (jjj < countE ) { | 198 | while (jjj < countE ) { |
198 | RecMailP re = (*e.at( jjj )); | 199 | RecMailP re = (*e.at( jjj )); |
199 | if ( re->isEqual(r) ) { | 200 | if ( re->isEqual(r) ) { |
200 | found = true; | 201 | found = true; |
201 | break; | 202 | break; |
202 | } | 203 | } |
203 | ++jjj; | 204 | ++jjj; |
204 | } | 205 | } |
205 | if ( !found ) { | 206 | if ( !found ) { |
206 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); | 207 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); |
207 | n.append( r ); | 208 | n.append( r ); |
208 | } | 209 | } |
209 | ++iii; | 210 | ++iii; |
210 | } | 211 | } |
211 | qDebug("Downloaded %d messages ",n.count() ); | 212 | qDebug("Downloaded %d messages ",n.count() ); |
212 | if ( n.count() == 0 ) { | 213 | if ( n.count() == 0 ) { |
213 | Global::statusMessage(i18n("There are no new messages")); | 214 | Global::statusMessage(i18n("There are no new messages")); |
214 | return; | 215 | return; |
215 | } | 216 | } |
216 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); | 217 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); |
217 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); | 218 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); |
218 | 219 | ||
219 | #if 0 | 220 | #if 0 |
220 | QValueList<RecMailP> t; | 221 | QValueList<RecMailP> t; |
221 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 222 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
222 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 223 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
223 | #endif | 224 | #endif |
224 | 225 | ||
225 | } | 226 | } |
226 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 227 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
227 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 228 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
228 | { | 229 | { |
229 | QValueList<RecMailP> t; | 230 | QValueList<RecMailP> t; |
230 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 231 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index d89a5f9..49227dd 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -95,381 +95,395 @@ void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | |||
95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
96 | case MAILMIME_DISCRETE_TYPE_TEXT: | 96 | case MAILMIME_DISCRETE_TYPE_TEXT: |
97 | target->setType("text"); | 97 | target->setType("text"); |
98 | break; | 98 | break; |
99 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 99 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
100 | target->setType("image"); | 100 | target->setType("image"); |
101 | break; | 101 | break; |
102 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 102 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
103 | target->setType("audio"); | 103 | target->setType("audio"); |
104 | break; | 104 | break; |
105 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 105 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
106 | target->setType("video"); | 106 | target->setType("video"); |
107 | break; | 107 | break; |
108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
109 | target->setType("application"); | 109 | target->setType("application"); |
110 | break; | 110 | break; |
111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
112 | default: | 112 | default: |
113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
115 | } | 115 | } |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | if (type->ct_parameters) { | 118 | if (type->ct_parameters) { |
119 | fillParameters(target,type->ct_parameters); | 119 | fillParameters(target,type->ct_parameters); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
124 | field = (mailmime_field*)current->data; | 124 | field = (mailmime_field*)current->data; |
125 | switch(field->fld_type) { | 125 | switch(field->fld_type) { |
126 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 126 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | 127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
128 | break; | 128 | break; |
129 | case MAILMIME_FIELD_ID: | 129 | case MAILMIME_FIELD_ID: |
130 | target->setIdentifier(field->fld_data.fld_id); | 130 | target->setIdentifier(field->fld_data.fld_id); |
131 | break; | 131 | break; |
132 | case MAILMIME_FIELD_DESCRIPTION: | 132 | case MAILMIME_FIELD_DESCRIPTION: |
133 | target->setDescription(field->fld_data.fld_description); | 133 | target->setDescription(field->fld_data.fld_description); |
134 | break; | 134 | break; |
135 | default: | 135 | default: |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | 142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
143 | { | 143 | { |
144 | if (!parameters) {return;} | 144 | if (!parameters) {return;} |
145 | clistcell*current=0; | 145 | clistcell*current=0; |
146 | mailmime_parameter*param; | 146 | mailmime_parameter*param; |
147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
148 | param = (mailmime_parameter*)current->data; | 148 | param = (mailmime_parameter*)current->data; |
149 | if (param) { | 149 | if (param) { |
150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
156 | { | 156 | { |
157 | QString enc="7bit"; | 157 | QString enc="7bit"; |
158 | if (!aEnc) return enc; | 158 | if (!aEnc) return enc; |
159 | switch(aEnc->enc_type) { | 159 | switch(aEnc->enc_type) { |
160 | case MAILMIME_MECHANISM_7BIT: | 160 | case MAILMIME_MECHANISM_7BIT: |
161 | enc = "7bit"; | 161 | enc = "7bit"; |
162 | break; | 162 | break; |
163 | case MAILMIME_MECHANISM_8BIT: | 163 | case MAILMIME_MECHANISM_8BIT: |
164 | enc = "8bit"; | 164 | enc = "8bit"; |
165 | break; | 165 | break; |
166 | case MAILMIME_MECHANISM_BINARY: | 166 | case MAILMIME_MECHANISM_BINARY: |
167 | enc = "binary"; | 167 | enc = "binary"; |
168 | break; | 168 | break; |
169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
170 | enc = "quoted-printable"; | 170 | enc = "quoted-printable"; |
171 | break; | 171 | break; |
172 | case MAILMIME_MECHANISM_BASE64: | 172 | case MAILMIME_MECHANISM_BASE64: |
173 | enc = "base64"; | 173 | enc = "base64"; |
174 | break; | 174 | break; |
175 | case MAILMIME_MECHANISM_TOKEN: | 175 | case MAILMIME_MECHANISM_TOKEN: |
176 | default: | 176 | default: |
177 | if (aEnc->enc_token) { | 177 | if (aEnc->enc_token) { |
178 | enc = QString(aEnc->enc_token); | 178 | enc = QString(aEnc->enc_token); |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | } | 181 | } |
182 | return enc; | 182 | return enc; |
183 | } | 183 | } |
184 | 184 | ||
185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) |
186 | { | 186 | { |
187 | if (current_rec >= 10) { | 187 | if (current_rec >= 10) { |
188 | ; // odebug << "too deep recursion!" << oendl; | 188 | ; // odebug << "too deep recursion!" << oendl; |
189 | } | 189 | } |
190 | if (!message || !mime) { | 190 | if (!message || !mime) { |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | int r; | 193 | int r; |
194 | char*data = 0; | 194 | char*data = 0; |
195 | size_t len; | 195 | size_t len; |
196 | clistiter * cur = 0; | 196 | clistiter * cur = 0; |
197 | QString b; | 197 | QString b; |
198 | RecPartP part = new RecPart(); | 198 | RecPartP part = new RecPart(); |
199 | 199 | ||
200 | switch (mime->mm_type) { | 200 | switch (mime->mm_type) { |
201 | case MAILMIME_SINGLE: | 201 | case MAILMIME_SINGLE: |
202 | { | 202 | { |
203 | QValueList<int>countlist = recList; | 203 | QValueList<int>countlist = recList; |
204 | countlist.append(current_count); | 204 | countlist.append(current_count); |
205 | r = mailmessage_fetch_section(message,mime,&data,&len); | 205 | r = mailmessage_fetch_section(message,mime,&data,&len); |
206 | part->setSize(len); | 206 | part->setSize(len); |
207 | part->setPositionlist(countlist); | 207 | part->setPositionlist(countlist); |
208 | b = gen_attachment_id(); | 208 | b = gen_attachment_id(); |
209 | part->setIdentifier(b); | 209 | part->setIdentifier(b); |
210 | fillSingleBody(part,message,mime); | 210 | fillSingleBody(part,message,mime); |
211 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 211 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
212 | encodedString*rs = new encodedString(); | 212 | encodedString*rs = new encodedString(); |
213 | rs->setContent(data,len); | 213 | rs->setContent(data,len); |
214 | encodedString*res = decode_String(rs,part->Encoding()); | 214 | encodedString*res = decode_String(rs,part->Encoding()); |
215 | if (countlist.count()>2) { | 215 | if (countlist.count()>2) { |
216 | bodyCache[b]=rs; | 216 | bodyCache[b]=rs; |
217 | target->addPart(part); | 217 | target->addPart(part); |
218 | } else { | 218 | } else { |
219 | delete rs; | 219 | delete rs; |
220 | } | 220 | } |
221 | b = QString(res->Content()); | 221 | b = QString(res->Content()); |
222 | delete res; | 222 | delete res; |
223 | size_t index = 0; | ||
224 | char*resu = 0; | ||
225 | int err = MAILIMF_NO_ERROR; | ||
226 | QString charset = part->searchParamter( "charset"); | ||
227 | qDebug("CHARSET %s ",charset.latin1() ); | ||
228 | if ( !charset.isEmpty() ) { | ||
229 | err = mailmime_encoded_phrase_parse(charset.latin1(), | ||
230 | b.latin1(), b.length(),&index, "utf-8",&resu); | ||
231 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { | ||
232 | //qDebug("res %d %s ", index, resu); | ||
233 | b = QString::fromUtf8(resu); | ||
234 | } | ||
235 | if (resu) free(resu); | ||
236 | } | ||
223 | target->setBodytext(b); | 237 | target->setBodytext(b); |
224 | target->setDescription(part); | 238 | target->setDescription(part); |
225 | } else { | 239 | } else { |
226 | bodyCache[b]=new encodedString(data,len); | 240 | bodyCache[b]=new encodedString(data,len); |
227 | target->addPart(part); | 241 | target->addPart(part); |
228 | } | 242 | } |
229 | } | 243 | } |
230 | break; | 244 | break; |
231 | case MAILMIME_MULTIPLE: | 245 | case MAILMIME_MULTIPLE: |
232 | { | 246 | { |
233 | unsigned int ccount = 1; | 247 | unsigned int ccount = 1; |
234 | mailmime*cbody=0; | 248 | mailmime*cbody=0; |
235 | QValueList<int>countlist = recList; | 249 | QValueList<int>countlist = recList; |
236 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 250 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
237 | cbody = (mailmime*)clist_content(cur); | 251 | cbody = (mailmime*)clist_content(cur); |
238 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 252 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
239 | RecPartP targetPart = new RecPart(); | 253 | RecPartP targetPart = new RecPart(); |
240 | targetPart->setType("multipart"); | 254 | targetPart->setType("multipart"); |
241 | countlist.append(current_count); | 255 | countlist.append(current_count); |
242 | targetPart->setPositionlist(countlist); | 256 | targetPart->setPositionlist(countlist); |
243 | target->addPart(targetPart); | 257 | target->addPart(targetPart); |
244 | } | 258 | } |
245 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 259 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
246 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 260 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
247 | countlist = recList; | 261 | countlist = recList; |
248 | } | 262 | } |
249 | ++ccount; | 263 | ++ccount; |
250 | } | 264 | } |
251 | } | 265 | } |
252 | break; | 266 | break; |
253 | case MAILMIME_MESSAGE: | 267 | case MAILMIME_MESSAGE: |
254 | { | 268 | { |
255 | QValueList<int>countlist = recList; | 269 | QValueList<int>countlist = recList; |
256 | countlist.append(current_count); | 270 | countlist.append(current_count); |
257 | /* the own header is always at recursion 0 - we don't need that */ | 271 | /* the own header is always at recursion 0 - we don't need that */ |
258 | if (current_rec > 0) { | 272 | if (current_rec > 0) { |
259 | part->setPositionlist(countlist); | 273 | part->setPositionlist(countlist); |
260 | r = mailmessage_fetch_section(message,mime,&data,&len); | 274 | r = mailmessage_fetch_section(message,mime,&data,&len); |
261 | part->setSize(len); | 275 | part->setSize(len); |
262 | part->setPositionlist(countlist); | 276 | part->setPositionlist(countlist); |
263 | b = gen_attachment_id(); | 277 | b = gen_attachment_id(); |
264 | part->setIdentifier(b); | 278 | part->setIdentifier(b); |
265 | part->setType("message"); | 279 | part->setType("message"); |
266 | part->setSubtype("rfc822"); | 280 | part->setSubtype("rfc822"); |
267 | bodyCache[b]=new encodedString(data,len); | 281 | bodyCache[b]=new encodedString(data,len); |
268 | target->addPart(part); | 282 | target->addPart(part); |
269 | } | 283 | } |
270 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 284 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
271 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 285 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
272 | } | 286 | } |
273 | } | 287 | } |
274 | break; | 288 | break; |
275 | } | 289 | } |
276 | } | 290 | } |
277 | 291 | ||
278 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 292 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
279 | { | 293 | { |
280 | int err = MAILIMF_NO_ERROR; | 294 | int err = MAILIMF_NO_ERROR; |
281 | //mailmime_single_fields fields; | 295 | //mailmime_single_fields fields; |
282 | /* is bound to msg and will be freed there */ | 296 | /* is bound to msg and will be freed there */ |
283 | mailmime * mime=0; | 297 | mailmime * mime=0; |
284 | RecBodyP body = new RecBody(); | 298 | RecBodyP body = new RecBody(); |
285 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 299 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
286 | err = mailmessage_get_bodystructure(msg,&mime); | 300 | err = mailmessage_get_bodystructure(msg,&mime); |
287 | QValueList<int>recList; | 301 | QValueList<int>recList; |
288 | traverseBody(body,msg,mime,recList); | 302 | traverseBody(body,msg,mime,recList); |
289 | return body; | 303 | return body; |
290 | } | 304 | } |
291 | 305 | ||
292 | 306 | ||
293 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 307 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
294 | { | 308 | { |
295 | QString result( "" ); | 309 | QString result( "" ); |
296 | 310 | ||
297 | bool first = true; | 311 | bool first = true; |
298 | if (list == 0) return result; | 312 | if (list == 0) return result; |
299 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 313 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
300 | mailimf_address *addr = (mailimf_address *) current->data; | 314 | mailimf_address *addr = (mailimf_address *) current->data; |
301 | 315 | ||
302 | if ( !first ) { | 316 | if ( !first ) { |
303 | result.append( "," ); | 317 | result.append( "," ); |
304 | } else { | 318 | } else { |
305 | first = false; | 319 | first = false; |
306 | } | 320 | } |
307 | 321 | ||
308 | switch ( addr->ad_type ) { | 322 | switch ( addr->ad_type ) { |
309 | case MAILIMF_ADDRESS_MAILBOX: | 323 | case MAILIMF_ADDRESS_MAILBOX: |
310 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 324 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
311 | break; | 325 | break; |
312 | case MAILIMF_ADDRESS_GROUP: | 326 | case MAILIMF_ADDRESS_GROUP: |
313 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 327 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
314 | break; | 328 | break; |
315 | default: | 329 | default: |
316 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | 330 | ; // odebug << "Generic: unkown mailimf address type" << oendl; |
317 | break; | 331 | break; |
318 | } | 332 | } |
319 | } | 333 | } |
320 | 334 | ||
321 | return result; | 335 | return result; |
322 | } | 336 | } |
323 | 337 | ||
324 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 338 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
325 | { | 339 | { |
326 | QString result( "" ); | 340 | QString result( "" ); |
327 | 341 | ||
328 | result.append( group->grp_display_name ); | 342 | result.append( group->grp_display_name ); |
329 | result.append( ": " ); | 343 | result.append( ": " ); |
330 | 344 | ||
331 | if ( group->grp_mb_list != NULL ) { | 345 | if ( group->grp_mb_list != NULL ) { |
332 | result.append( parseMailboxList( group->grp_mb_list ) ); | 346 | result.append( parseMailboxList( group->grp_mb_list ) ); |
333 | } | 347 | } |
334 | 348 | ||
335 | result.append( ";" ); | 349 | result.append( ";" ); |
336 | 350 | ||
337 | return result; | 351 | return result; |
338 | } | 352 | } |
339 | 353 | ||
340 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 354 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
341 | { | 355 | { |
342 | QString result( "" ); | 356 | QString result( "" ); |
343 | 357 | ||
344 | if ( box->mb_display_name == NULL ) { | 358 | if ( box->mb_display_name == NULL ) { |
345 | result.append( box->mb_addr_spec ); | 359 | result.append( box->mb_addr_spec ); |
346 | } else { | 360 | } else { |
347 | result.append( convert_String(box->mb_display_name).latin1() ); | 361 | result.append( convert_String(box->mb_display_name) ); |
348 | result.append( " <" ); | 362 | result.append( " <" ); |
349 | result.append( box->mb_addr_spec ); | 363 | result.append( box->mb_addr_spec ); |
350 | result.append( ">" ); | 364 | result.append( ">" ); |
351 | } | 365 | } |
352 | 366 | ||
353 | return result; | 367 | return result; |
354 | } | 368 | } |
355 | 369 | ||
356 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 370 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
357 | { | 371 | { |
358 | QString result( "" ); | 372 | QString result( "" ); |
359 | 373 | ||
360 | bool first = true; | 374 | bool first = true; |
361 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 375 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
362 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 376 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
363 | 377 | ||
364 | if ( !first ) { | 378 | if ( !first ) { |
365 | result.append( "," ); | 379 | result.append( "," ); |
366 | } else { | 380 | } else { |
367 | first = false; | 381 | first = false; |
368 | } | 382 | } |
369 | 383 | ||
370 | result.append( parseMailbox( box ) ); | 384 | result.append( parseMailbox( box ) ); |
371 | } | 385 | } |
372 | 386 | ||
373 | return result; | 387 | return result; |
374 | } | 388 | } |
375 | 389 | ||
376 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | 390 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
377 | { | 391 | { |
378 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 392 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
379 | if (it==bodyCache.end()) return new encodedString(); | 393 | if (it==bodyCache.end()) return new encodedString(); |
380 | encodedString*t = decode_String(it.data(),part->Encoding()); | 394 | encodedString*t = decode_String(it.data(),part->Encoding()); |
381 | return t; | 395 | return t; |
382 | } | 396 | } |
383 | 397 | ||
384 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | 398 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
385 | { | 399 | { |
386 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 400 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
387 | if (it==bodyCache.end()) return new encodedString(); | 401 | if (it==bodyCache.end()) return new encodedString(); |
388 | encodedString*t = it.data(); | 402 | encodedString*t = it.data(); |
389 | return t; | 403 | return t; |
390 | } | 404 | } |
391 | 405 | ||
392 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 406 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
393 | { | 407 | { |
394 | encodedString*t = fetchDecodedPart(mail,part); | 408 | encodedString*t = fetchDecodedPart(mail,part); |
395 | QString text=t->Content(); | 409 | QString text=t->Content(); |
396 | delete t; | 410 | delete t; |
397 | return text; | 411 | return text; |
398 | } | 412 | } |
399 | 413 | ||
400 | void Genericwrapper::cleanMimeCache() | 414 | void Genericwrapper::cleanMimeCache() |
401 | { | 415 | { |
402 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 416 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
403 | for (;it!=bodyCache.end();++it) { | 417 | for (;it!=bodyCache.end();++it) { |
404 | encodedString*t = it.data(); | 418 | encodedString*t = it.data(); |
405 | //it.setValue(0); | 419 | //it.setValue(0); |
406 | if (t) delete t; | 420 | if (t) delete t; |
407 | } | 421 | } |
408 | bodyCache.clear(); | 422 | bodyCache.clear(); |
409 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | 423 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; |
410 | } | 424 | } |
411 | 425 | ||
412 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 426 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
413 | { | 427 | { |
414 | QStringList res; | 428 | QStringList res; |
415 | if (!in_replies || !in_replies->mid_list) return res; | 429 | if (!in_replies || !in_replies->mid_list) return res; |
416 | clistiter * current = 0; | 430 | clistiter * current = 0; |
417 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 431 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
418 | QString h((char*)current->data); | 432 | QString h((char*)current->data); |
419 | while (h.length()>0 && h[0]=='<') { | 433 | while (h.length()>0 && h[0]=='<') { |
420 | h.remove(0,1); | 434 | h.remove(0,1); |
421 | } | 435 | } |
422 | while (h.length()>0 && h[h.length()-1]=='>') { | 436 | while (h.length()>0 && h[h.length()-1]=='>') { |
423 | h.remove(h.length()-1,1); | 437 | h.remove(h.length()-1,1); |
424 | } | 438 | } |
425 | if (h.length()>0) { | 439 | if (h.length()>0) { |
426 | res.append(h); | 440 | res.append(h); |
427 | } | 441 | } |
428 | } | 442 | } |
429 | return res; | 443 | return res; |
430 | } | 444 | } |
431 | 445 | ||
432 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) | 446 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) |
433 | { | 447 | { |
434 | int r; | 448 | int r; |
435 | mailmessage_list * env_list = 0; | 449 | mailmessage_list * env_list = 0; |
436 | r = mailsession_get_messages_list(session,&env_list); | 450 | r = mailsession_get_messages_list(session,&env_list); |
437 | if (r != MAIL_NO_ERROR) { | 451 | if (r != MAIL_NO_ERROR) { |
438 | ; // odebug << "Error message list" << oendl; | 452 | ; // odebug << "Error message list" << oendl; |
439 | return; | 453 | return; |
440 | } | 454 | } |
441 | r = mailsession_get_envelopes_list(session, env_list); | 455 | r = mailsession_get_envelopes_list(session, env_list); |
442 | if (r != MAIL_NO_ERROR) { | 456 | if (r != MAIL_NO_ERROR) { |
443 | ; // odebug << "Error filling message list" << oendl; | 457 | ; // odebug << "Error filling message list" << oendl; |
444 | if (env_list) { | 458 | if (env_list) { |
445 | mailmessage_list_free(env_list); | 459 | mailmessage_list_free(env_list); |
446 | } | 460 | } |
447 | return; | 461 | return; |
448 | } | 462 | } |
449 | mailimf_references * refs = 0; | 463 | mailimf_references * refs = 0; |
450 | mailimf_in_reply_to * in_replies = 0; | 464 | mailimf_in_reply_to * in_replies = 0; |
451 | uint32_t i = 0; | 465 | uint32_t i = 0; |
452 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 466 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
453 | mailmessage * msg; | 467 | mailmessage * msg; |
454 | QBitArray mFlags(7); | 468 | QBitArray mFlags(7); |
455 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 469 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
456 | if (msg->msg_fields == NULL) { | 470 | if (msg->msg_fields == NULL) { |
457 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | 471 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; |
458 | continue; | 472 | continue; |
459 | } | 473 | } |
460 | RecMailP mail = new RecMail(); | 474 | RecMailP mail = new RecMail(); |
461 | mail->setWrapper(this); | 475 | mail->setWrapper(this); |
462 | mail_flags * flag_result = 0; | 476 | mail_flags * flag_result = 0; |
463 | r = mailmessage_get_flags(msg,&flag_result); | 477 | r = mailmessage_get_flags(msg,&flag_result); |
464 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 478 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
465 | mFlags.setBit(FLAG_SEEN); | 479 | mFlags.setBit(FLAG_SEEN); |
466 | } | 480 | } |
467 | mailimf_single_fields single_fields; | 481 | mailimf_single_fields single_fields; |
468 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 482 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
469 | mail->setMsgsize(msg->msg_size); | 483 | mail->setMsgsize(msg->msg_size); |
470 | mail->setFlags(mFlags); | 484 | mail->setFlags(mFlags); |
471 | mail->setMbox(mailbox); | 485 | mail->setMbox(mailbox); |
472 | mail->setNumber(msg->msg_index); | 486 | mail->setNumber(msg->msg_index); |
473 | if (single_fields.fld_subject) | 487 | if (single_fields.fld_subject) |
474 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 488 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
475 | if (single_fields.fld_from) | 489 | if (single_fields.fld_from) |
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index d90a8d2..eb2b47d 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -627,256 +627,275 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
627 | from = ""; | 627 | from = ""; |
628 | named_from = false; | 628 | named_from = false; |
629 | current_address=(mailimap_address*)current->data; | 629 | current_address=(mailimap_address*)current->data; |
630 | if (current_address->ad_personal_name){ | 630 | if (current_address->ad_personal_name){ |
631 | from+=convert_String((const char*)current_address->ad_personal_name); | 631 | from+=convert_String((const char*)current_address->ad_personal_name); |
632 | from+=" "; | 632 | from+=" "; |
633 | named_from = true; | 633 | named_from = true; |
634 | } | 634 | } |
635 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 635 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
636 | from+="<"; | 636 | from+="<"; |
637 | } | 637 | } |
638 | if (current_address->ad_mailbox_name) { | 638 | if (current_address->ad_mailbox_name) { |
639 | from+=QString(current_address->ad_mailbox_name); | 639 | from+=QString(current_address->ad_mailbox_name); |
640 | from+="@"; | 640 | from+="@"; |
641 | } | 641 | } |
642 | if (current_address->ad_host_name) { | 642 | if (current_address->ad_host_name) { |
643 | from+=QString(current_address->ad_host_name); | 643 | from+=QString(current_address->ad_host_name); |
644 | } | 644 | } |
645 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 645 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
646 | from+=">"; | 646 | from+=">"; |
647 | } | 647 | } |
648 | l.append(QString(from)); | 648 | l.append(QString(from)); |
649 | if (++count > 99) { | 649 | if (++count > 99) { |
650 | break; | 650 | break; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | return l; | 653 | return l; |
654 | } | 654 | } |
655 | 655 | ||
656 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 656 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
657 | { | 657 | { |
658 | encodedString*res=new encodedString; | 658 | encodedString*res=new encodedString; |
659 | int err; | 659 | int err; |
660 | mailimap_fetch_type *fetchType; | 660 | mailimap_fetch_type *fetchType; |
661 | mailimap_set *set; | 661 | mailimap_set *set; |
662 | clistcell*current,*cur; | 662 | clistcell*current,*cur; |
663 | mailimap_section_part * section_part = 0; | 663 | mailimap_section_part * section_part = 0; |
664 | mailimap_section_spec * section_spec = 0; | 664 | mailimap_section_spec * section_spec = 0; |
665 | mailimap_section * section = 0; | 665 | mailimap_section * section = 0; |
666 | mailimap_fetch_att * fetch_att = 0; | 666 | mailimap_fetch_att * fetch_att = 0; |
667 | 667 | ||
668 | login(); | 668 | login(); |
669 | if (!m_imap) { | 669 | if (!m_imap) { |
670 | return res; | 670 | return res; |
671 | } | 671 | } |
672 | if (!internal_call) { | 672 | if (!internal_call) { |
673 | err = selectMbox(mail->getMbox()); | 673 | err = selectMbox(mail->getMbox()); |
674 | if ( err != MAILIMAP_NO_ERROR ) { | 674 | if ( err != MAILIMAP_NO_ERROR ) { |
675 | return res; | 675 | return res; |
676 | } | 676 | } |
677 | } | 677 | } |
678 | set = mailimap_set_new_single(mail->getNumber()); | 678 | set = mailimap_set_new_single(mail->getNumber()); |
679 | 679 | ||
680 | clist*id_list = 0; | 680 | clist*id_list = 0; |
681 | 681 | ||
682 | /* if path == empty then its a request for the whole rfc822 mail and generates | 682 | /* if path == empty then its a request for the whole rfc822 mail and generates |
683 | a "fetch <id> (body[])" statement on imap server */ | 683 | a "fetch <id> (body[])" statement on imap server */ |
684 | if (path.count()>0 ) { | 684 | if (path.count()>0 ) { |
685 | id_list = clist_new(); | 685 | id_list = clist_new(); |
686 | for (unsigned j=0; j < path.count();++j) { | 686 | for (unsigned j=0; j < path.count();++j) { |
687 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 687 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
688 | *p_id = path[j]; | 688 | *p_id = path[j]; |
689 | clist_append(id_list,p_id); | 689 | clist_append(id_list,p_id); |
690 | } | 690 | } |
691 | section_part = mailimap_section_part_new(id_list); | 691 | section_part = mailimap_section_part_new(id_list); |
692 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 692 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
693 | } | 693 | } |
694 | 694 | ||
695 | section = mailimap_section_new(section_spec); | 695 | section = mailimap_section_new(section_spec); |
696 | fetch_att = mailimap_fetch_att_new_body_section(section); | 696 | fetch_att = mailimap_fetch_att_new_body_section(section); |
697 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 697 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
698 | 698 | ||
699 | clist*result = 0; | 699 | clist*result = 0; |
700 | 700 | ||
701 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 701 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
702 | mailimap_set_free( set ); | 702 | mailimap_set_free( set ); |
703 | mailimap_fetch_type_free( fetchType ); | 703 | mailimap_fetch_type_free( fetchType ); |
704 | 704 | ||
705 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 705 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
706 | mailimap_msg_att * msg_att; | 706 | mailimap_msg_att * msg_att; |
707 | msg_att = (mailimap_msg_att*)current->data; | 707 | msg_att = (mailimap_msg_att*)current->data; |
708 | mailimap_msg_att_item*msg_att_item; | 708 | mailimap_msg_att_item*msg_att_item; |
709 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 709 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
710 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 710 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
711 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 711 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
712 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 712 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
713 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 713 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
714 | /* detach - we take over the content */ | 714 | /* detach - we take over the content */ |
715 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 715 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
716 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 716 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | } | 719 | } |
720 | } else { | 720 | } else { |
721 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 721 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
722 | } | 722 | } |
723 | if (result) mailimap_fetch_list_free(result); | 723 | if (result) mailimap_fetch_list_free(result); |
724 | return res; | 724 | return res; |
725 | } | 725 | } |
726 | 726 | ||
727 | /* current_recursion is for recursive calls. | 727 | /* current_recursion is for recursive calls. |
728 | current_count means the position inside the internal loop! */ | 728 | current_count means the position inside the internal loop! */ |
729 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 729 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
730 | int current_recursion,QValueList<int>recList,int current_count) | 730 | int current_recursion,QValueList<int>recList,int current_count) |
731 | { | 731 | { |
732 | if (!body || current_recursion>=10) { | 732 | if (!body || current_recursion>=10) { |
733 | return; | 733 | return; |
734 | } | 734 | } |
735 | switch (body->bd_type) { | 735 | switch (body->bd_type) { |
736 | case MAILIMAP_BODY_1PART: | 736 | case MAILIMAP_BODY_1PART: |
737 | { | 737 | { |
738 | QValueList<int>countlist = recList; | 738 | QValueList<int>countlist = recList; |
739 | countlist.append(current_count); | 739 | countlist.append(current_count); |
740 | RecPartP currentPart = new RecPart(); | 740 | RecPartP currentPart = new RecPart(); |
741 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 741 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
742 | QString id(""); | 742 | QString id(""); |
743 | currentPart->setPositionlist(countlist); | 743 | currentPart->setPositionlist(countlist); |
744 | for (unsigned int j = 0; j < countlist.count();++j) { | 744 | for (unsigned int j = 0; j < countlist.count();++j) { |
745 | id+=(j>0?" ":""); | 745 | id+=(j>0?" ":""); |
746 | id+=QString("%1").arg(countlist[j]); | 746 | id+=QString("%1").arg(countlist[j]); |
747 | } | 747 | } |
748 | //odebug << "ID = " << id.latin1() << "" << oendl; | 748 | //odebug << "ID = " << id.latin1() << "" << oendl; |
749 | currentPart->setIdentifier(id); | 749 | currentPart->setIdentifier(id); |
750 | fillSinglePart(currentPart,part1); | 750 | fillSinglePart(currentPart,part1); |
751 | /* important: Check for is NULL 'cause a body can be empty! | 751 | /* important: Check for is NULL 'cause a body can be empty! |
752 | And we put it only into the mail if it is the FIRST part */ | 752 | And we put it only into the mail if it is the FIRST part */ |
753 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 753 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
754 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 754 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
755 | |||
756 | size_t index = 0; | ||
757 | char*res = 0; | ||
758 | int err = MAILIMF_NO_ERROR; | ||
759 | |||
760 | QString charset = currentPart->searchParamter( "charset"); | ||
761 | qDebug("CHARSET %s ",charset.latin1() ); | ||
762 | //if ( false ) { | ||
763 | if ( !charset.isEmpty() ) { | ||
764 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | ||
765 | // text, strlen(text),&index, "iso-8859-1",&res); | ||
766 | err = mailmime_encoded_phrase_parse(charset.latin1(), | ||
767 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); | ||
768 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | ||
769 | //qDebug("res %d %s ", index, res); | ||
770 | body_text = QString::fromUtf8(res); | ||
771 | } | ||
772 | if (res) free(res); | ||
773 | } | ||
755 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); | 774 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); |
756 | target_body->setDescription(currentPart); | 775 | target_body->setDescription(currentPart); |
757 | target_body->setBodytext(body_text); | 776 | target_body->setBodytext(body_text); |
758 | if (countlist.count()>1) { | 777 | if (countlist.count()>1) { |
759 | target_body->addPart(currentPart); | 778 | target_body->addPart(currentPart); |
760 | } | 779 | } |
761 | } else { | 780 | } else { |
762 | target_body->addPart(currentPart); | 781 | target_body->addPart(currentPart); |
763 | } | 782 | } |
764 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 783 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
765 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 784 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
766 | } | 785 | } |
767 | } | 786 | } |
768 | break; | 787 | break; |
769 | case MAILIMAP_BODY_MPART: | 788 | case MAILIMAP_BODY_MPART: |
770 | { | 789 | { |
771 | QValueList<int>countlist = recList; | 790 | QValueList<int>countlist = recList; |
772 | clistcell*current=0; | 791 | clistcell*current=0; |
773 | mailimap_body*current_body=0; | 792 | mailimap_body*current_body=0; |
774 | unsigned int ccount = 1; | 793 | unsigned int ccount = 1; |
775 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 794 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
776 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 795 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
777 | current_body = (mailimap_body*)current->data; | 796 | current_body = (mailimap_body*)current->data; |
778 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 797 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
779 | RecPartP targetPart = new RecPart(); | 798 | RecPartP targetPart = new RecPart(); |
780 | targetPart->setType("multipart"); | 799 | targetPart->setType("multipart"); |
781 | fillMultiPart(targetPart,mailDescription); | 800 | fillMultiPart(targetPart,mailDescription); |
782 | countlist.append(current_count); | 801 | countlist.append(current_count); |
783 | targetPart->setPositionlist(countlist); | 802 | targetPart->setPositionlist(countlist); |
784 | target_body->addPart(targetPart); | 803 | target_body->addPart(targetPart); |
785 | QString id(""); | 804 | QString id(""); |
786 | for (unsigned int j = 0; j < countlist.count();++j) { | 805 | for (unsigned int j = 0; j < countlist.count();++j) { |
787 | id+=(j>0?" ":""); | 806 | id+=(j>0?" ":""); |
788 | id+=QString("%1").arg(countlist[j]); | 807 | id+=QString("%1").arg(countlist[j]); |
789 | } | 808 | } |
790 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 809 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
791 | } | 810 | } |
792 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 811 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
793 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 812 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
794 | countlist = recList; | 813 | countlist = recList; |
795 | } | 814 | } |
796 | ++ccount; | 815 | ++ccount; |
797 | } | 816 | } |
798 | } | 817 | } |
799 | break; | 818 | break; |
800 | default: | 819 | default: |
801 | break; | 820 | break; |
802 | } | 821 | } |
803 | } | 822 | } |
804 | 823 | ||
805 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 824 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
806 | { | 825 | { |
807 | if (!Description) { | 826 | if (!Description) { |
808 | return; | 827 | return; |
809 | } | 828 | } |
810 | switch (Description->bd_type) { | 829 | switch (Description->bd_type) { |
811 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 830 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
812 | target_part->setType("text"); | 831 | target_part->setType("text"); |
813 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 832 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
814 | break; | 833 | break; |
815 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 834 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
816 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 835 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
817 | break; | 836 | break; |
818 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 837 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
819 | target_part->setType("message"); | 838 | target_part->setType("message"); |
820 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 839 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
821 | break; | 840 | break; |
822 | default: | 841 | default: |
823 | break; | 842 | break; |
824 | } | 843 | } |
825 | } | 844 | } |
826 | 845 | ||
827 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 846 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
828 | { | 847 | { |
829 | if (!which) { | 848 | if (!which) { |
830 | return; | 849 | return; |
831 | } | 850 | } |
832 | QString sub; | 851 | QString sub; |
833 | sub = which->bd_media_text; | 852 | sub = which->bd_media_text; |
834 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 853 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
835 | target_part->setSubtype(sub.lower()); | 854 | target_part->setSubtype(sub.lower()); |
836 | target_part->setLines(which->bd_lines); | 855 | target_part->setLines(which->bd_lines); |
837 | fillBodyFields(target_part,which->bd_fields); | 856 | fillBodyFields(target_part,which->bd_fields); |
838 | } | 857 | } |
839 | 858 | ||
840 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 859 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
841 | { | 860 | { |
842 | if (!which) { | 861 | if (!which) { |
843 | return; | 862 | return; |
844 | } | 863 | } |
845 | target_part->setSubtype("rfc822"); | 864 | target_part->setSubtype("rfc822"); |
846 | //odebug << "Message part" << oendl; | 865 | //odebug << "Message part" << oendl; |
847 | /* we set this type to text/plain */ | 866 | /* we set this type to text/plain */ |
848 | target_part->setLines(which->bd_lines); | 867 | target_part->setLines(which->bd_lines); |
849 | fillBodyFields(target_part,which->bd_fields); | 868 | fillBodyFields(target_part,which->bd_fields); |
850 | } | 869 | } |
851 | 870 | ||
852 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 871 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
853 | { | 872 | { |
854 | if (!which) return; | 873 | if (!which) return; |
855 | QString sub = which->bd_media_subtype; | 874 | QString sub = which->bd_media_subtype; |
856 | target_part->setSubtype(sub.lower()); | 875 | target_part->setSubtype(sub.lower()); |
857 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 876 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
858 | clistcell*cur = 0; | 877 | clistcell*cur = 0; |
859 | mailimap_single_body_fld_param*param=0; | 878 | mailimap_single_body_fld_param*param=0; |
860 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 879 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
861 | param = (mailimap_single_body_fld_param*)cur->data; | 880 | param = (mailimap_single_body_fld_param*)cur->data; |
862 | if (param) { | 881 | if (param) { |
863 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 882 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
864 | } | 883 | } |
865 | } | 884 | } |
866 | } | 885 | } |
867 | } | 886 | } |
868 | 887 | ||
869 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 888 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
870 | { | 889 | { |
871 | if (!which) { | 890 | if (!which) { |
872 | return; | 891 | return; |
873 | } | 892 | } |
874 | QString type,sub; | 893 | QString type,sub; |
875 | switch (which->bd_media_basic->med_type) { | 894 | switch (which->bd_media_basic->med_type) { |
876 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 895 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
877 | type = "application"; | 896 | type = "application"; |
878 | break; | 897 | break; |
879 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 898 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
880 | type = "audio"; | 899 | type = "audio"; |
881 | break; | 900 | break; |
882 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 901 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp index 0cdbae4..87f8c8a 100644 --- a/kmicromail/libmailwrapper/mboxwrapper.cpp +++ b/kmicromail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,255 +1,256 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <klocale.h> | 7 | #include <klocale.h> |
8 | 8 | ||
9 | 9 | ||
10 | #include <qpe/global.h> | 10 | #include <qpe/global.h> |
11 | 11 | ||
12 | using namespace Opie::Core; | 12 | using namespace Opie::Core; |
13 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | 13 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) |
14 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | 14 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) |
15 | { | 15 | { |
16 | QDir dir(MBOXPath); | 16 | QDir dir(MBOXPath); |
17 | if (!dir.exists()) { | 17 | if (!dir.exists()) { |
18 | dir.mkdir(MBOXPath); | 18 | dir.mkdir(MBOXPath); |
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | MBOXwrapper::~MBOXwrapper() | 22 | MBOXwrapper::~MBOXwrapper() |
23 | { | 23 | { |
24 | } | 24 | } |
25 | 25 | ||
26 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) | 26 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) |
27 | { | 27 | { |
28 | mailstorage*storage = mailstorage_new(NULL); | 28 | mailstorage*storage = mailstorage_new(NULL); |
29 | QString p = MBOXPath+"/"; | 29 | QString p = MBOXPath+"/"; |
30 | p+=mailbox; | 30 | p+=mailbox; |
31 | 31 | ||
32 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 32 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
33 | mailfolder*folder; | 33 | mailfolder*folder; |
34 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 34 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
35 | r = mailfolder_connect(folder); | 35 | r = mailfolder_connect(folder); |
36 | if (r != MAIL_NO_ERROR) { | 36 | if (r != MAIL_NO_ERROR) { |
37 | //odebug << "Error initializing mbox" << oendl; | 37 | //odebug << "Error initializing mbox" << oendl; |
38 | mailfolder_free(folder); | 38 | mailfolder_free(folder); |
39 | mailstorage_free(storage); | 39 | mailstorage_free(storage); |
40 | return; | 40 | return; |
41 | } | 41 | } |
42 | 42 | ||
43 | parseList(target,folder->fld_session,mailbox); | 43 | parseList(target,folder->fld_session,mailbox); |
44 | 44 | ||
45 | mailfolder_disconnect(folder); | 45 | mailfolder_disconnect(folder); |
46 | mailfolder_free(folder); | 46 | mailfolder_free(folder); |
47 | mailstorage_free(storage); | 47 | mailstorage_free(storage); |
48 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); | 48 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); |
49 | } | 49 | } |
50 | 50 | ||
51 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() | 51 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() |
52 | { | 52 | { |
53 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 53 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
54 | QDir dir(MBOXPath); | 54 | QDir dir(MBOXPath); |
55 | if (!dir.exists()) return folders; | 55 | if (!dir.exists()) return folders; |
56 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 56 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
57 | QStringList entries = dir.entryList(); | 57 | QStringList entries = dir.entryList(); |
58 | QStringList::ConstIterator it = entries.begin(); | 58 | QStringList::ConstIterator it = entries.begin(); |
59 | for (;it!=entries.end();++it) { | 59 | for (;it!=entries.end();++it) { |
60 | FolderP inb=new Folder(*it,"/"); | 60 | FolderP inb=new Folder(*it,"/"); |
61 | folders->append(inb); | 61 | folders->append(inb); |
62 | } | 62 | } |
63 | return folders; | 63 | return folders; |
64 | } | 64 | } |
65 | 65 | ||
66 | void MBOXwrapper::deleteMail(const RecMailP & mail) | 66 | void MBOXwrapper::deleteMail(const RecMailP & mail) |
67 | { | 67 | { |
68 | mailstorage*storage = mailstorage_new(NULL); | 68 | mailstorage*storage = mailstorage_new(NULL); |
69 | QString p = MBOXPath+"/"; | 69 | QString p = MBOXPath+"/"; |
70 | p+=mail->getMbox(); | 70 | p+=mail->getMbox(); |
71 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 71 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
72 | mailfolder*folder; | 72 | mailfolder*folder; |
73 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 73 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
74 | r = mailfolder_connect(folder); | 74 | r = mailfolder_connect(folder); |
75 | if (r != MAIL_NO_ERROR) { | 75 | if (r != MAIL_NO_ERROR) { |
76 | ; // << "Error initializing mbox" << oendl; | 76 | ; // << "Error initializing mbox" << oendl; |
77 | mailfolder_free(folder); | 77 | mailfolder_free(folder); |
78 | mailstorage_free(storage); | 78 | mailstorage_free(storage); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); | 81 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); |
82 | if (r != MAIL_NO_ERROR) { | 82 | if (r != MAIL_NO_ERROR) { |
83 | ; // << "error deleting mail" << oendl; | 83 | ; // << "error deleting mail" << oendl; |
84 | } | 84 | } |
85 | mailfolder_free(folder); | 85 | mailfolder_free(folder); |
86 | mailstorage_free(storage); | 86 | mailstorage_free(storage); |
87 | } | 87 | } |
88 | 88 | ||
89 | void MBOXwrapper::answeredMail(const RecMailP&) | 89 | void MBOXwrapper::answeredMail(const RecMailP&) |
90 | { | 90 | { |
91 | } | 91 | } |
92 | 92 | ||
93 | RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) | 93 | RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) |
94 | { | 94 | { |
95 | RecBodyP body = new RecBody(); | 95 | RecBodyP body = new RecBody(); |
96 | mailstorage*storage = mailstorage_new(NULL); | 96 | mailstorage*storage = mailstorage_new(NULL); |
97 | QString p = MBOXPath+"/"; | 97 | QString p = MBOXPath+"/"; |
98 | p+=mail->getMbox(); | 98 | p+=mail->getMbox(); |
99 | mailmessage * msg; | 99 | mailmessage * msg; |
100 | char*data=0; | 100 | char*data=0; |
101 | size_t size; | 101 | size_t size; |
102 | 102 | ||
103 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 103 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
104 | mailfolder*folder; | 104 | mailfolder*folder; |
105 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 105 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
106 | r = mailfolder_connect(folder); | 106 | r = mailfolder_connect(folder); |
107 | if (r != MAIL_NO_ERROR) { | 107 | if (r != MAIL_NO_ERROR) { |
108 | ; // << "Error initializing mbox" << oendl; | 108 | ; // << "Error initializing mbox" << oendl; |
109 | mailfolder_free(folder); | 109 | mailfolder_free(folder); |
110 | mailstorage_free(storage); | 110 | mailstorage_free(storage); |
111 | return body; | 111 | return body; |
112 | } | 112 | } |
113 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | 113 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); |
114 | if (r != MAIL_NO_ERROR) { | 114 | if (r != MAIL_NO_ERROR) { |
115 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; | 115 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; |
116 | mailfolder_free(folder); | 116 | mailfolder_free(folder); |
117 | mailstorage_free(storage); | 117 | mailstorage_free(storage); |
118 | return body; | 118 | return body; |
119 | } | 119 | } |
120 | r = mailmessage_fetch(msg,&data,&size); | 120 | r = mailmessage_fetch(msg,&data,&size); |
121 | if (r != MAIL_NO_ERROR) { | 121 | if (r != MAIL_NO_ERROR) { |
122 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; | 122 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; |
123 | mailfolder_free(folder); | 123 | mailfolder_free(folder); |
124 | mailstorage_free(storage); | 124 | mailstorage_free(storage); |
125 | mailmessage_free(msg); | 125 | mailmessage_free(msg); |
126 | return body; | 126 | return body; |
127 | } | 127 | } |
128 | qDebug("MBOXwrapper::fetchBody "); | ||
128 | body = parseMail(msg); | 129 | body = parseMail(msg); |
129 | mailmessage_fetch_result_free(msg,data); | 130 | mailmessage_fetch_result_free(msg,data); |
130 | mailfolder_free(folder); | 131 | mailfolder_free(folder); |
131 | mailstorage_free(storage); | 132 | mailstorage_free(storage); |
132 | 133 | ||
133 | return body; | 134 | return body; |
134 | } | 135 | } |
135 | 136 | ||
136 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 137 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
137 | { | 138 | { |
138 | ; // << "MBOX " << current << " von " << maximum << "" << oendl; | 139 | ; // << "MBOX " << current << " von " << maximum << "" << oendl; |
139 | } | 140 | } |
140 | 141 | ||
141 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) | 142 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) |
142 | { | 143 | { |
143 | QString p = MBOXPath+"/"; | 144 | QString p = MBOXPath+"/"; |
144 | p+=folder; | 145 | p+=folder; |
145 | QFileInfo fi(p); | 146 | QFileInfo fi(p); |
146 | if (fi.exists()) { | 147 | if (fi.exists()) { |
147 | Global::statusMessage(i18n("Mailbox exists.")); | 148 | Global::statusMessage(i18n("Mailbox exists.")); |
148 | return 0; | 149 | return 0; |
149 | } | 150 | } |
150 | mailmbox_folder*f = 0; | 151 | mailmbox_folder*f = 0; |
151 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 152 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
152 | Global::statusMessage(i18n("Error init folder")); | 153 | Global::statusMessage(i18n("Error init folder")); |
153 | return 0; | 154 | return 0; |
154 | } | 155 | } |
155 | if (f) mailmbox_done(f); | 156 | if (f) mailmbox_done(f); |
156 | return 1; | 157 | return 1; |
157 | } | 158 | } |
158 | 159 | ||
159 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 160 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
160 | { | 161 | { |
161 | QString p = MBOXPath+"/"; | 162 | QString p = MBOXPath+"/"; |
162 | p+=folder; | 163 | p+=folder; |
163 | mailmbox_folder*f = 0; | 164 | mailmbox_folder*f = 0; |
164 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 165 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
165 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
166 | Global::statusMessage(i18n("Error init folder")); | 167 | Global::statusMessage(i18n("Error init folder")); |
167 | return; | 168 | return; |
168 | } | 169 | } |
169 | r = mailmbox_append_message(f,msg,length); | 170 | r = mailmbox_append_message(f,msg,length); |
170 | if (r != MAIL_NO_ERROR) { | 171 | if (r != MAIL_NO_ERROR) { |
171 | Global::statusMessage(i18n("Error writing to message folder")); | 172 | Global::statusMessage(i18n("Error writing to message folder")); |
172 | } | 173 | } |
173 | mailmbox_done(f); | 174 | mailmbox_done(f); |
174 | } | 175 | } |
175 | 176 | ||
176 | encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) | 177 | encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) |
177 | { | 178 | { |
178 | RecBody body; | 179 | RecBody body; |
179 | mailstorage*storage = mailstorage_new(NULL); | 180 | mailstorage*storage = mailstorage_new(NULL); |
180 | QString p = MBOXPath+"/"; | 181 | QString p = MBOXPath+"/"; |
181 | p+=mail->getMbox(); | 182 | p+=mail->getMbox(); |
182 | mailmessage * msg; | 183 | mailmessage * msg; |
183 | char*data=0; | 184 | char*data=0; |
184 | size_t size; | 185 | size_t size; |
185 | 186 | ||
186 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 187 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
187 | mailfolder*folder; | 188 | mailfolder*folder; |
188 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 189 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
189 | r = mailfolder_connect(folder); | 190 | r = mailfolder_connect(folder); |
190 | if (r != MAIL_NO_ERROR) { | 191 | if (r != MAIL_NO_ERROR) { |
191 | Global::statusMessage(i18n("Error initializing mbox")); | 192 | Global::statusMessage(i18n("Error initializing mbox")); |
192 | mailfolder_free(folder); | 193 | mailfolder_free(folder); |
193 | mailstorage_free(storage); | 194 | mailstorage_free(storage); |
194 | return 0; | 195 | return 0; |
195 | } | 196 | } |
196 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | 197 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); |
197 | if (r != MAIL_NO_ERROR) { | 198 | if (r != MAIL_NO_ERROR) { |
198 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 199 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
199 | mailfolder_free(folder); | 200 | mailfolder_free(folder); |
200 | mailstorage_free(storage); | 201 | mailstorage_free(storage); |
201 | return 0; | 202 | return 0; |
202 | } | 203 | } |
203 | r = mailmessage_fetch(msg,&data,&size); | 204 | r = mailmessage_fetch(msg,&data,&size); |
204 | if (r != MAIL_NO_ERROR) { | 205 | if (r != MAIL_NO_ERROR) { |
205 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 206 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
206 | mailfolder_free(folder); | 207 | mailfolder_free(folder); |
207 | mailstorage_free(storage); | 208 | mailstorage_free(storage); |
208 | mailmessage_free(msg); | 209 | mailmessage_free(msg); |
209 | return 0; | 210 | return 0; |
210 | } | 211 | } |
211 | encodedString*result = new encodedString(data,size); | 212 | encodedString*result = new encodedString(data,size); |
212 | 213 | ||
213 | mailfolder_free(folder); | 214 | mailfolder_free(folder); |
214 | mailstorage_free(storage); | 215 | mailstorage_free(storage); |
215 | mailmessage_free(msg); | 216 | mailmessage_free(msg); |
216 | return result; | 217 | return result; |
217 | } | 218 | } |
218 | 219 | ||
219 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 220 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
220 | { | 221 | { |
221 | QString p = MBOXPath+"/"; | 222 | QString p = MBOXPath+"/"; |
222 | p+=mailbox; | 223 | p+=mailbox; |
223 | mailmbox_folder*f = 0; | 224 | mailmbox_folder*f = 0; |
224 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 225 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
225 | if (r != MAIL_NO_ERROR) { | 226 | if (r != MAIL_NO_ERROR) { |
226 | ; // << "Error init folder" << oendl; | 227 | ; // << "Error init folder" << oendl; |
227 | return; | 228 | return; |
228 | } | 229 | } |
229 | deleteMails(f,target); | 230 | deleteMails(f,target); |
230 | mailmbox_done(f); | 231 | mailmbox_done(f); |
231 | } | 232 | } |
232 | 233 | ||
233 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) | 234 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) |
234 | { | 235 | { |
235 | if (!f) return; | 236 | if (!f) return; |
236 | int r; | 237 | int r; |
237 | QValueList<RecMailP>::ConstIterator it; | 238 | QValueList<RecMailP>::ConstIterator it; |
238 | for (it=target.begin(); it != target.end();++it) { | 239 | for (it=target.begin(); it != target.end();++it) { |
239 | r = mailmbox_delete_msg(f,(*it)->getNumber()); | 240 | r = mailmbox_delete_msg(f,(*it)->getNumber()); |
240 | if (r!=MAILMBOX_NO_ERROR) { | 241 | if (r!=MAILMBOX_NO_ERROR) { |
241 | ; // << "error delete mail" << oendl; | 242 | ; // << "error delete mail" << oendl; |
242 | } | 243 | } |
243 | } | 244 | } |
244 | r = mailmbox_expunge(f); | 245 | r = mailmbox_expunge(f); |
245 | if (r != MAILMBOX_NO_ERROR) { | 246 | if (r != MAILMBOX_NO_ERROR) { |
246 | ; // << "error expunge mailbox" << oendl; | 247 | ; // << "error expunge mailbox" << oendl; |
247 | } | 248 | } |
248 | } | 249 | } |
249 | 250 | ||
250 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) | 251 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) |
251 | { | 252 | { |
252 | if (!tfolder) return 0; | 253 | if (!tfolder) return 0; |
253 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 254 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
254 | int res = 1; | 255 | int res = 1; |
255 | 256 | ||
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 90b5d23..982d7a6 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -3,256 +3,257 @@ | |||
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
10 | #include <klocale.h> | 10 | #include <klocale.h> |
11 | #include <kglobal.h> | 11 | #include <kglobal.h> |
12 | //#include <opie2/odebug.h> | 12 | //#include <opie2/odebug.h> |
13 | 13 | ||
14 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
15 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 15 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
16 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 16 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
17 | { | 17 | { |
18 | if (MHPath.length()>0) { | 18 | if (MHPath.length()>0) { |
19 | if (MHPath[MHPath.length()-1]=='/') { | 19 | if (MHPath[MHPath.length()-1]=='/') { |
20 | MHPath=MHPath.left(MHPath.length()-1); | 20 | MHPath=MHPath.left(MHPath.length()-1); |
21 | } | 21 | } |
22 | //odebug << MHPath << oendl; | 22 | //odebug << MHPath << oendl; |
23 | QDir dir(MHPath); | 23 | QDir dir(MHPath); |
24 | if (!dir.exists()) { | 24 | if (!dir.exists()) { |
25 | dir.mkdir(MHPath); | 25 | dir.mkdir(MHPath); |
26 | } | 26 | } |
27 | init_storage(); | 27 | init_storage(); |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | void MHwrapper::init_storage() | 31 | void MHwrapper::init_storage() |
32 | { | 32 | { |
33 | int r; | 33 | int r; |
34 | QString pre = MHPath; | 34 | QString pre = MHPath; |
35 | if (!m_storage) { | 35 | if (!m_storage) { |
36 | m_storage = mailstorage_new(NULL); | 36 | m_storage = mailstorage_new(NULL); |
37 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 37 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
38 | if (r != MAIL_NO_ERROR) { | 38 | if (r != MAIL_NO_ERROR) { |
39 | qDebug(" error init storage "); | 39 | qDebug(" error init storage "); |
40 | mailstorage_free(m_storage); | 40 | mailstorage_free(m_storage); |
41 | m_storage = 0; | 41 | m_storage = 0; |
42 | return; | 42 | return; |
43 | } | 43 | } |
44 | } | 44 | } |
45 | r = mailstorage_connect(m_storage); | 45 | r = mailstorage_connect(m_storage); |
46 | if (r!=MAIL_NO_ERROR) { | 46 | if (r!=MAIL_NO_ERROR) { |
47 | qDebug("error connecting storage "); | 47 | qDebug("error connecting storage "); |
48 | mailstorage_free(m_storage); | 48 | mailstorage_free(m_storage); |
49 | m_storage = 0; | 49 | m_storage = 0; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void MHwrapper::clean_storage() | 53 | void MHwrapper::clean_storage() |
54 | { | 54 | { |
55 | if (m_storage) { | 55 | if (m_storage) { |
56 | mailstorage_disconnect(m_storage); | 56 | mailstorage_disconnect(m_storage); |
57 | mailstorage_free(m_storage); | 57 | mailstorage_free(m_storage); |
58 | m_storage = 0; | 58 | m_storage = 0; |
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | MHwrapper::~MHwrapper() | 62 | MHwrapper::~MHwrapper() |
63 | { | 63 | { |
64 | clean_storage(); | 64 | clean_storage(); |
65 | } | 65 | } |
66 | 66 | ||
67 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 67 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
68 | { | 68 | { |
69 | init_storage(); | 69 | init_storage(); |
70 | if (!m_storage) { | 70 | if (!m_storage) { |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | QString f = buildPath(mailbox); | 73 | QString f = buildPath(mailbox); |
74 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 74 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
75 | if (r!=MAIL_NO_ERROR) { | 75 | if (r!=MAIL_NO_ERROR) { |
76 | qDebug("listMessages: error selecting folder! "); | 76 | qDebug("listMessages: error selecting folder! "); |
77 | return; | 77 | return; |
78 | } | 78 | } |
79 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); | 79 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); |
80 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); | 80 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); |
81 | } | 81 | } |
82 | 82 | ||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
84 | { | 84 | { |
85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
86 | /* this is needed! */ | 86 | /* this is needed! */ |
87 | if (m_storage) mailstorage_disconnect(m_storage); | 87 | if (m_storage) mailstorage_disconnect(m_storage); |
88 | init_storage(); | 88 | init_storage(); |
89 | if (!m_storage) { | 89 | if (!m_storage) { |
90 | return folders; | 90 | return folders; |
91 | } | 91 | } |
92 | mail_list*flist = 0; | 92 | mail_list*flist = 0; |
93 | clistcell*current=0; | 93 | clistcell*current=0; |
94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
95 | if (r != MAIL_NO_ERROR || !flist) { | 95 | if (r != MAIL_NO_ERROR || !flist) { |
96 | qDebug("error getting folder list "); | 96 | qDebug("error getting folder list "); |
97 | return folders; | 97 | return folders; |
98 | } | 98 | } |
99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
100 | QString t = (char*)current->data; | 100 | QString t = (char*)current->data; |
101 | t.replace(0,MHPath.length(),""); | 101 | t.replace(0,MHPath.length(),""); |
102 | folders->append(new MHFolder(t,MHPath)); | 102 | folders->append(new MHFolder(t,MHPath)); |
103 | } | 103 | } |
104 | mail_list_free(flist); | 104 | mail_list_free(flist); |
105 | return folders; | 105 | return folders; |
106 | } | 106 | } |
107 | 107 | ||
108 | void MHwrapper::deleteMail(const RecMailP&mail) | 108 | void MHwrapper::deleteMail(const RecMailP&mail) |
109 | { | 109 | { |
110 | init_storage(); | 110 | init_storage(); |
111 | if (!m_storage) { | 111 | if (!m_storage) { |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
115 | if (r!=MAIL_NO_ERROR) { | 115 | if (r!=MAIL_NO_ERROR) { |
116 | qDebug("error selecting folder! "); | 116 | qDebug("error selecting folder! "); |
117 | return; | 117 | return; |
118 | } | 118 | } |
119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | 119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); |
120 | if (r != MAIL_NO_ERROR) { | 120 | if (r != MAIL_NO_ERROR) { |
121 | qDebug("error deleting mail "); | 121 | qDebug("error deleting mail "); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | void MHwrapper::answeredMail(const RecMailP&) | 125 | void MHwrapper::answeredMail(const RecMailP&) |
126 | { | 126 | { |
127 | } | 127 | } |
128 | 128 | ||
129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | 129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) |
130 | { | 130 | { |
131 | qDebug("MHwrapper::fetchBody "); | ||
131 | RecBodyP body = new RecBody(); | 132 | RecBodyP body = new RecBody(); |
132 | init_storage(); | 133 | init_storage(); |
133 | if (!m_storage) { | 134 | if (!m_storage) { |
134 | return body; | 135 | return body; |
135 | } | 136 | } |
136 | mailmessage * msg; | 137 | mailmessage * msg; |
137 | char*data=0; | 138 | char*data=0; |
138 | 139 | ||
139 | /* mail should hold the complete path! */ | 140 | /* mail should hold the complete path! */ |
140 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 141 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
141 | if (r != MAIL_NO_ERROR) { | 142 | if (r != MAIL_NO_ERROR) { |
142 | return body; | 143 | return body; |
143 | } | 144 | } |
144 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 145 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
145 | if (r != MAIL_NO_ERROR) { | 146 | if (r != MAIL_NO_ERROR) { |
146 | qDebug("Error fetching mail "); | 147 | qDebug("Error fetching mail "); |
147 | 148 | ||
148 | return body; | 149 | return body; |
149 | } | 150 | } |
150 | body = parseMail(msg); | 151 | body = parseMail(msg); |
151 | mailmessage_fetch_result_free(msg,data); | 152 | mailmessage_fetch_result_free(msg,data); |
152 | return body; | 153 | return body; |
153 | } | 154 | } |
154 | 155 | ||
155 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 156 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
156 | { | 157 | { |
157 | qDebug("MBox Progress %d of %d",current,maximum ); | 158 | qDebug("MBox Progress %d of %d",current,maximum ); |
158 | //odebug << "MH " << current << " von " << maximum << "" << oendl; | 159 | //odebug << "MH " << current << " von " << maximum << "" << oendl; |
159 | } | 160 | } |
160 | 161 | ||
161 | QString MHwrapper::buildPath(const QString&p) | 162 | QString MHwrapper::buildPath(const QString&p) |
162 | { | 163 | { |
163 | QString f=""; | 164 | QString f=""; |
164 | if (p.length()==0||p=="/") | 165 | if (p.length()==0||p=="/") |
165 | return MHPath; | 166 | return MHPath; |
166 | if (!p.startsWith(MHPath)) { | 167 | if (!p.startsWith(MHPath)) { |
167 | f+=MHPath; | 168 | f+=MHPath; |
168 | } | 169 | } |
169 | if (!p.startsWith("/")) { | 170 | if (!p.startsWith("/")) { |
170 | f+="/"; | 171 | f+="/"; |
171 | } | 172 | } |
172 | f+=p; | 173 | f+=p; |
173 | return f; | 174 | return f; |
174 | } | 175 | } |
175 | 176 | ||
176 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | 177 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
177 | { | 178 | { |
178 | init_storage(); | 179 | init_storage(); |
179 | if (!m_storage) { | 180 | if (!m_storage) { |
180 | return 0; | 181 | return 0; |
181 | } | 182 | } |
182 | QString f; | 183 | QString f; |
183 | if (!pfolder) { | 184 | if (!pfolder) { |
184 | // toplevel folder | 185 | // toplevel folder |
185 | f = buildPath(folder); | 186 | f = buildPath(folder); |
186 | } else { | 187 | } else { |
187 | f = pfolder->getName(); | 188 | f = pfolder->getName(); |
188 | f+="/"; | 189 | f+="/"; |
189 | f+=folder; | 190 | f+=folder; |
190 | } | 191 | } |
191 | 192 | ||
192 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 193 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
193 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
194 | qDebug("error creating folder "); | 195 | qDebug("error creating folder "); |
195 | return 0; | 196 | return 0; |
196 | } | 197 | } |
197 | return 1; | 198 | return 1; |
198 | } | 199 | } |
199 | 200 | ||
200 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 201 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
201 | { | 202 | { |
202 | init_storage(); | 203 | init_storage(); |
203 | if (!m_storage) { | 204 | if (!m_storage) { |
204 | return; | 205 | return; |
205 | } | 206 | } |
206 | QString f = buildPath(Folder); | 207 | QString f = buildPath(Folder); |
207 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 208 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
208 | if (r!=MAIL_NO_ERROR) { | 209 | if (r!=MAIL_NO_ERROR) { |
209 | qDebug("error selecting folder! "); | 210 | qDebug("error selecting folder! "); |
210 | return; | 211 | return; |
211 | } | 212 | } |
212 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 213 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
213 | if (r!=MAIL_NO_ERROR) { | 214 | if (r!=MAIL_NO_ERROR) { |
214 | qDebug("error storing mail "); | 215 | qDebug("error storing mail "); |
215 | } | 216 | } |
216 | return; | 217 | return; |
217 | } | 218 | } |
218 | 219 | ||
219 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 220 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
220 | { | 221 | { |
221 | encodedString*result = 0; | 222 | encodedString*result = 0; |
222 | init_storage(); | 223 | init_storage(); |
223 | if (!m_storage) { | 224 | if (!m_storage) { |
224 | return result; | 225 | return result; |
225 | } | 226 | } |
226 | mailmessage * msg = 0; | 227 | mailmessage * msg = 0; |
227 | char*data=0; | 228 | char*data=0; |
228 | size_t size; | 229 | size_t size; |
229 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 230 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
230 | if (r!=MAIL_NO_ERROR) { | 231 | if (r!=MAIL_NO_ERROR) { |
231 | qDebug("error selecting folder! "); | 232 | qDebug("error selecting folder! "); |
232 | return result; | 233 | return result; |
233 | } | 234 | } |
234 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 235 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
235 | if (r != MAIL_NO_ERROR) { | 236 | if (r != MAIL_NO_ERROR) { |
236 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 237 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
237 | return 0; | 238 | return 0; |
238 | } | 239 | } |
239 | r = mailmessage_fetch(msg,&data,&size); | 240 | r = mailmessage_fetch(msg,&data,&size); |
240 | if (r != MAIL_NO_ERROR) { | 241 | if (r != MAIL_NO_ERROR) { |
241 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 242 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
242 | if (msg) mailmessage_free(msg); | 243 | if (msg) mailmessage_free(msg); |
243 | return 0; | 244 | return 0; |
244 | } | 245 | } |
245 | result = new encodedString(data,size); | 246 | result = new encodedString(data,size); |
246 | if (msg) mailmessage_free(msg); | 247 | if (msg) mailmessage_free(msg); |
247 | return result; | 248 | return result; |
248 | } | 249 | } |
249 | 250 | ||
250 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 251 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
251 | { | 252 | { |
252 | QString f = buildPath(mailbox); | 253 | QString f = buildPath(mailbox); |
253 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 254 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
254 | if (r!=MAIL_NO_ERROR) { | 255 | if (r!=MAIL_NO_ERROR) { |
255 | qDebug("deleteMails: error selecting folder! "); | 256 | qDebug("deleteMails: error selecting folder! "); |
256 | return; | 257 | return; |
257 | } | 258 | } |
258 | QValueList<RecMailP>::ConstIterator it; | 259 | QValueList<RecMailP>::ConstIterator it; |