author | llornkcor <llornkcor> | 2003-06-09 01:37:23 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-06-09 01:37:23 (UTC) |
commit | 364e6e65b4c3b4ceec2b1b6688f2ca2b3dce4560 (patch) (unidiff) | |
tree | 1be5d3150c2bda4b3a55f9e7d2529d73fe6d72db /noncore/net/mailit/emailhandler.cpp | |
parent | 5ee1c7dff5679454d46e3c5bd5747c60ea63c959 (diff) | |
download | opie-364e6e65b4c3b4ceec2b1b6688f2ca2b3dce4560.zip opie-364e6e65b4c3b4ceec2b1b6688f2ca2b3dce4560.tar.gz opie-364e6e65b4c3b4ceec2b1b6688f2ca2b3dce4560.tar.bz2 |
patch from wim delvaux. fix from me
Diffstat (limited to 'noncore/net/mailit/emailhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index 39f693d..5b8bda1 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -1,102 +1,102 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qfileinfo.h> | 20 | #include <qfileinfo.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <qapplication.h> | 22 | #include <qapplication.h> |
23 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include "emailhandler.h" | 25 | #include "emailhandler.h" |
26 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
27 | #include <qpe/filemanager.h> | 27 | #include <qpe/filemanager.h> |
28 | 28 | ||
29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) | 29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) |
30 | { | 30 | { |
31 | return dupl( (Enclosure *) d); | 31 | return dupl( (Enclosure *) d); |
32 | } | 32 | } |
33 | 33 | ||
34 | Enclosure* EnclosureList::dupl(Enclosure *in) | 34 | Enclosure* EnclosureList::dupl(Enclosure *in) |
35 | { | 35 | { |
36 | ac = new Enclosure(*in); | 36 | ac = new Enclosure(*in); |
37 | return ac; | 37 | return ac; |
38 | } | 38 | } |
39 | 39 | ||
40 | EmailHandler::EmailHandler() | 40 | EmailHandler::EmailHandler() |
41 | { | 41 | { |
42 | qDebug("EMailHandler::EmailHandler"); | 42 | qDebug("EMailHandler::EmailHandler"); |
43 | 43 | ||
44 | smtpClient = new SmtpClient(); | 44 | smtpClient = new SmtpClient(); |
45 | popClient = new PopClient(); | 45 | popClient = new PopClient(); |
46 | 46 | ||
47 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 47 | connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this, |
48 | SIGNAL(smtpError(int)) ); | 48 | SIGNAL(smtpError(int, const QString &)) ); |
49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
51 | SIGNAL(updateSmtpStatus(const QString &)) ); | 51 | SIGNAL(updateSmtpStatus(const QString &)) ); |
52 | 52 | ||
53 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 53 | connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this, |
54 | SIGNAL(popError(int)) ); | 54 | SIGNAL(popError(int, const QString &)) ); |
55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
58 | SIGNAL(updatePopStatus(const QString &)) ); | 58 | SIGNAL(updatePopStatus(const QString &)) ); |
59 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 59 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
60 | SIGNAL(mailTransfered(int)) ); | 60 | SIGNAL(mailTransfered(int)) ); |
61 | 61 | ||
62 | 62 | ||
63 | //relaying size information | 63 | //relaying size information |
64 | connect(popClient, SIGNAL(currentMailSize(int)), | 64 | connect(popClient, SIGNAL(currentMailSize(int)), |
65 | this, SIGNAL(currentMailSize(int)) ); | 65 | this, SIGNAL(currentMailSize(int)) ); |
66 | connect(popClient, SIGNAL(downloadedSize(int)), | 66 | connect(popClient, SIGNAL(downloadedSize(int)), |
67 | this, SIGNAL(downloadedSize(int)) ); | 67 | this, SIGNAL(downloadedSize(int)) ); |
68 | } | 68 | } |
69 | 69 | ||
70 | void EmailHandler::sendMail(QList<Email> *mailList) | 70 | void EmailHandler::sendMail(QList<Email> *mailList) |
71 | { | 71 | { |
72 | Email *currentMail; | 72 | Email *currentMail; |
73 | QString temp; | 73 | QString temp; |
74 | QString userName = mailAccount.name; | 74 | QString userName = mailAccount.name; |
75 | userName += " <" + mailAccount.emailAddress + ">"; | 75 | userName += " <" + mailAccount.emailAddress + ">"; |
76 | 76 | ||
77 | for (currentMail = mailList->first(); currentMail != 0; | 77 | for (currentMail = mailList->first(); currentMail != 0; |
78 | currentMail = mailList->next()) { | 78 | currentMail = mailList->next()) { |
79 | 79 | ||
80 | if (encodeMime(currentMail) == 0) { | 80 | if (encodeMime(currentMail) == 0) { |
81 | smtpClient->addMail(userName, currentMail->subject, | 81 | smtpClient->addMail(userName, currentMail->subject, |
82 | currentMail->recipients, currentMail->rawMail); | 82 | currentMail->recipients, currentMail->rawMail); |
83 | } else { //error | 83 | } else { //error |
84 | temp = tr("Could not locate all files in \nmail with subject: ") + | 84 | temp = tr("Could not locate all files in \nmail with subject: ") + |
85 | currentMail->subject; | 85 | currentMail->subject; |
86 | temp += tr("\nMail has NOT been sent"); | 86 | temp += tr("\nMail has NOT been sent"); |
87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
88 | 88 | ||
89 | } | 89 | } |
90 | } | 90 | } |
91 | smtpClient->newConnection(mailAccount.smtpServer, 25); | 91 | smtpClient->newConnection(mailAccount.smtpServer, 25); |
92 | } | 92 | } |
93 | 93 | ||
94 | void EmailHandler::setAccount(MailAccount account) | 94 | void EmailHandler::setAccount(MailAccount account) |
95 | { | 95 | { |
96 | mailAccount = account; | 96 | mailAccount = account; |
97 | } | 97 | } |
98 | 98 | ||
99 | void EmailHandler::getMail() | 99 | void EmailHandler::getMail() |
100 | { | 100 | { |
101 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 101 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
102 | if (mailAccount.synchronize) { | 102 | if (mailAccount.synchronize) { |
@@ -117,97 +117,97 @@ void EmailHandler::getMailHeaders() | |||
117 | 117 | ||
118 | headers = TRUE; | 118 | headers = TRUE; |
119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
120 | qDebug("Initiating connection"); | 120 | qDebug("Initiating connection"); |
121 | popClient->newConnection(mailAccount.popServer, 110); | 121 | popClient->newConnection(mailAccount.popServer, 110); |
122 | } | 122 | } |
123 | 123 | ||
124 | void EmailHandler::getMailByList(MailList *mailList) | 124 | void EmailHandler::getMailByList(MailList *mailList) |
125 | { | 125 | { |
126 | if (mailList->count() == 0) { //should not occur though | 126 | if (mailList->count() == 0) { //should not occur though |
127 | emit mailTransfered(0); | 127 | emit mailTransfered(0); |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | 130 | ||
131 | headers = FALSE; | 131 | headers = FALSE; |
132 | popClient->headersOnly(FALSE, 0); | 132 | popClient->headersOnly(FALSE, 0); |
133 | 133 | ||
134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); | 134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); |
135 | popClient->setSelectedMails(mailList); | 135 | popClient->setSelectedMails(mailList); |
136 | popClient->newConnection(mailAccount.popServer, 110); | 136 | popClient->newConnection(mailAccount.popServer, 110); |
137 | } | 137 | } |
138 | 138 | ||
139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
140 | { | 140 | { |
141 | Email mail; | 141 | Email mail; |
142 | 142 | ||
143 | mail.rawMail = message; | 143 | mail.rawMail = message; |
144 | mail.serverId = id; | 144 | mail.serverId = id; |
145 | mail.size = size; | 145 | mail.size = size; |
146 | mail.downloaded = complete; | 146 | mail.downloaded = complete; |
147 | 147 | ||
148 | emit mailArrived(mail, FALSE); | 148 | emit mailArrived(mail, FALSE); |
149 | } | 149 | } |
150 | 150 | ||
151 | bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) | 151 | bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) |
152 | { | 152 | { |
153 | QString temp, boundary; | 153 | QString temp, boundary; |
154 | int pos; | 154 | int pos; |
155 | QString delimiter, header, body, mimeHeader, mimeBody; | 155 | QString delimiter, header, body, mimeHeader, mimeBody; |
156 | QString content, contentType, contentAttribute, id, encoding; | 156 | QString content, contentType, contentAttribute, id, encoding; |
157 | QString fileName, storedName; | 157 | QString fileName, storedName; |
158 | int enclosureId = 0; | 158 | int enclosureId = 0; |
159 | 159 | ||
160 | mail->rawMail = in; | 160 | mail->rawMail = in; |
161 | mail->received = TRUE; | 161 | mail->received = TRUE; |
162 | mail->files.setAutoDelete(TRUE); | 162 | mail->files.setAutoDelete(TRUE); |
163 | 163 | ||
164 | temp = lineShift + "." + lineShift; | 164 | temp = lineShift + "." + lineShift; |
165 | 165 | ||
166 | if (in.right(temp.length()) != temp) { | 166 | if (in.right(temp.length()) != temp) { |
167 | mail->rawMail += temp; | 167 | mail->rawMail += temp; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
172 | pos = in.find(delimiter, 0, FALSE); | 172 | pos = in.find(delimiter, 0, FALSE); |
173 | header = in.left(pos); | 173 | header = in.left(pos); |
174 | body = in.right(in.length() - pos - delimiter.length()); | 174 | body = in.right(in.length() - pos - delimiter.length()); |
175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
176 | body.truncate(body.length()-2); | 176 | body.truncate(body.length()-2); |
177 | 177 | ||
178 | // TextParser p(header, lineShift); | 178 | // TextParser p(header, lineShift); |
179 | TextParser * lp = new TextParser(header, lineShift); | 179 | TextParser * lp = new TextParser(header, lineShift); |
180 | #define p (*lp) | 180 | #define p (*lp) |
181 | 181 | ||
182 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 182 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
183 | pos++; | 183 | pos++; |
184 | if (p.separatorAt(pos) == ' ') { | 184 | if (p.separatorAt(pos) == ' ') { |
185 | mail->from = p.getString(&pos, '<', false); | 185 | mail->from = p.getString(&pos, '<', false); |
186 | mail->from = mail->from.stripWhiteSpace(); | 186 | mail->from = mail->from.stripWhiteSpace(); |
187 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 187 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
188 | mail->from = mail->from.left(mail->from.length() - 1); | 188 | mail->from = mail->from.left(mail->from.length() - 1); |
189 | mail->from = mail->from.right(mail->from.length() - 1); | 189 | mail->from = mail->from.right(mail->from.length() - 1); |
190 | } | 190 | } |
191 | pos++; | 191 | pos++; |
192 | mail->fromMail = p.getString(&pos, '>', false); | 192 | mail->fromMail = p.getString(&pos, '>', false); |
193 | } else { | 193 | } else { |
194 | if (p.separatorAt(pos) == '<') //No name.. nasty | 194 | if (p.separatorAt(pos) == '<') //No name.. nasty |
195 | pos++; | 195 | pos++; |
196 | //pos++; | 196 | //pos++; |
197 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 197 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
198 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 198 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
199 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 199 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
200 | mail->from=mail->fromMail; | 200 | mail->from=mail->fromMail; |
201 | } | 201 | } |
202 | } | 202 | } |
203 | 203 | ||
204 | pos=0; | 204 | pos=0; |
205 | 205 | ||
206 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 206 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
207 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 207 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
208 | { | 208 | { |
209 | QString rec; | 209 | QString rec; |
210 | 210 | ||
211 | if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: | 211 | if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: |
212 | { | 212 | { |
213 | pos++; | 213 | pos++; |