Diffstat (limited to 'noncore/net/mailit/emailhandler.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index f6c6d60..b180051 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -95,63 +95,59 @@ void EmailHandler::setAccount(MailAccount account) | |||
95 | } | 95 | } |
96 | 96 | ||
97 | void EmailHandler::getMail() | 97 | void EmailHandler::getMail() |
98 | { | 98 | { |
99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
100 | if (mailAccount.synchronize) { | 100 | if (mailAccount.synchronize) { |
101 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 101 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
102 | } else { | 102 | } else { |
103 | popClient->removeSynchronize(); | 103 | popClient->removeSynchronize(); |
104 | } | 104 | } |
105 | 105 | ||
106 | headers = FALSE; | 106 | headers = FALSE; |
107 | popClient->headersOnly(headers, 0); | 107 | //popClient->headersOnly(headers, 0); |
108 | popClient->newConnection(mailAccount.popServer, 110); | 108 | popClient->newConnection(mailAccount.popServer, 110); |
109 | } | 109 | } |
110 | 110 | ||
111 | void EmailHandler::getMailHeaders() | 111 | void EmailHandler::getMailHeaders() |
112 | { | 112 | { |
113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
114 | if (mailAccount.synchronize) { | 114 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); |
115 | popClient->setSynchronize(mailAccount.lastServerMailCount); | ||
116 | } else { | ||
117 | popClient->removeSynchronize(); | ||
118 | } | ||
119 | 115 | ||
120 | headers = TRUE; | 116 | headers = TRUE; |
121 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 117 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
122 | popClient->newConnection(mailAccount.popServer, 110); | 118 | popClient->newConnection(mailAccount.popServer, 110); |
123 | } | 119 | } |
124 | 120 | ||
125 | void EmailHandler::getMailByList(MailList *mailList) | 121 | void EmailHandler::getMailByList(MailList *mailList) |
126 | { | 122 | { |
127 | if (mailList->count() == 0) { //should not occur though | 123 | if (mailList->count() == 0) { //should not occur though |
128 | emit mailTransfered(0); | 124 | emit mailTransfered(0); |
129 | return; | 125 | return; |
130 | } | 126 | } |
131 | 127 | ||
132 | headers = FALSE; | 128 | headers = FALSE; |
133 | popClient->headersOnly(FALSE, 0); | 129 | popClient->headersOnly(FALSE, 0); |
134 | popClient->newConnection(mailAccount.popServer, 110); | 130 | popClient->newConnection(mailAccount.popServer, 110); |
135 | popClient->setSelectedMails(mailList); | 131 | popClient->setSelectedMails(mailList); |
136 | } | 132 | } |
137 | 133 | ||
138 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 134 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool incomplete) |
139 | { | 135 | { |
140 | Email mail; | 136 | Email mail; |
141 | 137 | ||
142 | mail.rawMail = message; | 138 | mail.rawMail = message; |
143 | mail.serverId = id; | 139 | mail.serverId = id; |
144 | mail.size = size; | 140 | mail.size = size; |
145 | mail.downloaded = complete; | 141 | mail.downloaded = incomplete; |
146 | 142 | ||
147 | emit mailArrived(mail, FALSE); | 143 | emit mailArrived(mail, FALSE); |
148 | } | 144 | } |
149 | 145 | ||
150 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 146 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
151 | { | 147 | { |
152 | QString temp, boundary; | 148 | QString temp, boundary; |
153 | int pos; | 149 | int pos; |
154 | QString delimiter, header, body, mimeHeader, mimeBody; | 150 | QString delimiter, header, body, mimeHeader, mimeBody; |
155 | QString content, contentType, contentAttribute, id, encoding; | 151 | QString content, contentType, contentAttribute, id, encoding; |
156 | QString fileName, storedName; | 152 | QString fileName, storedName; |
157 | int enclosureId = 0; | 153 | int enclosureId = 0; |
@@ -177,59 +173,79 @@ bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | |||
177 | TextParser p(header, lineShift); | 173 | TextParser p(header, lineShift); |
178 | 174 | ||
179 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 175 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
180 | pos++; | 176 | pos++; |
181 | if (p.separatorAt(pos) == ' ') { | 177 | if (p.separatorAt(pos) == ' ') { |
182 | mail->from = p.getString(&pos, '<', false); | 178 | mail->from = p.getString(&pos, '<', false); |
183 | mail->from = mail->from.stripWhiteSpace(); | 179 | mail->from = mail->from.stripWhiteSpace(); |
184 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 180 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
185 | mail->from = mail->from.left(mail->from.length() - 1); | 181 | mail->from = mail->from.left(mail->from.length() - 1); |
186 | mail->from = mail->from.right(mail->from.length() - 1); | 182 | mail->from = mail->from.right(mail->from.length() - 1); |
187 | } | 183 | } |
188 | pos++; | 184 | pos++; |
185 | |||
189 | mail->fromMail = p.getString(&pos, '>', false); | 186 | mail->fromMail = p.getString(&pos, '>', false); |
190 | } else { | 187 | } else { |
191 | if ((p.separatorAt(pos) == '<') | 188 | if ((p.separatorAt(pos) == '<') |
192 | || (p.separatorAt(pos) == ' ')) //No name.. nasty | 189 | || (p.separatorAt(pos) == ' ')) //No name.. nasty |
193 | pos++; | 190 | pos++; |
194 | pos++; | 191 | pos++; |
195 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 192 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 193 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
197 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 194 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
198 | mail->from=mail->fromMail; | 195 | mail->from=mail->fromMail; |
199 | } | 196 | } |
200 | } | 197 | } |
201 | 198 | ||
202 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: | 199 | pos=0; |
203 | if ((pos = p.find("TO",':', 0, TRUE)) != -1) | 200 | |
201 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | ||
202 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | ||
203 | { | ||
204 | QString rec; | ||
205 | |||
206 | if (p.separatorAt(pos-1)!='-') | ||
204 | { | 207 | { |
205 | pos++; | 208 | pos++; |
209 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | ||
210 | } | ||
211 | /*else { | ||
212 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty | ||
213 | pos++; | ||
214 | pos++; | ||
215 | mail->fromMail = p.getString(&pos, 'z', TRUE); | ||
216 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | ||
217 | mail->fromMail.truncate(mail->fromMail.length() - 1); | ||
218 | mail->from=mail->fromMail; | ||
219 | } | ||
206 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | 220 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); |
221 | }*/ | ||
207 | } | 222 | } |
223 | // | ||
224 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | ||
208 | 225 | ||
209 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: | ||
210 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 226 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
211 | { | 227 | { |
212 | pos++; | 228 | pos++; |
213 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 229 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
214 | } | 230 | } |
215 | 231 | ||
216 | |||
217 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 232 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
218 | pos++; | 233 | pos++; |
219 | mail->subject = p.getString(&pos, 'z', TRUE); | 234 | mail->subject = p.getString(&pos, 'z', TRUE); |
220 | } | 235 | } |
236 | |||
221 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 237 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
222 | pos++; | 238 | pos++; |
223 | mail->date = p.getString(&pos, 'z', true); | 239 | mail->date = p.getString(&pos, 'z', TRUE); |
224 | } | 240 | } |
225 | 241 | ||
226 | 242 | ||
227 | 243 | ||
228 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 244 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
229 | pos++; | 245 | pos++; |
230 | if ( (p.wordAt(pos).upper() == "ID") && | 246 | if ( (p.wordAt(pos).upper() == "ID") && |
231 | (p.separatorAt(pos) == ':') ) { | 247 | (p.separatorAt(pos) == ':') ) { |
232 | 248 | ||
233 | id = p.getString(&pos, 'z', TRUE); | 249 | id = p.getString(&pos, 'z', TRUE); |
234 | mail->id = id; | 250 | mail->id = id; |
235 | } | 251 | } |