summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/emailhandler.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/mailit/emailhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/emailhandler.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index 62fa64f..59ccd90 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -18,49 +18,49 @@
**
**********************************************************************/
#include <qfileinfo.h>
#include <stdlib.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qcstring.h>
#include "emailhandler.h"
#include <qpe/applnk.h>
#include <qpe/filemanager.h>
QCollection::Item EnclosureList::newItem(QCollection::Item d)
{
return dupl( (Enclosure *) d);
}
Enclosure* EnclosureList::dupl(Enclosure *in)
{
ac = new Enclosure(*in);
return ac;
}
EmailHandler::EmailHandler()
{
- qDebug("EMailHandler::EmailHandler");
+ qDebug("EMailHandler::EmailHandler");
smtpClient = new SmtpClient();
popClient = new PopClient();
connect(smtpClient, SIGNAL(errorOccurred(int)), this,
SIGNAL(smtpError(int)) );
connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
SIGNAL(updateSmtpStatus(const QString &)) );
connect(popClient, SIGNAL(errorOccurred(int)), this,
SIGNAL(popError(int)) );
connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
this, SLOT(messageArrived(const QString &, int, uint, bool)) );
connect(popClient, SIGNAL(updateStatus(const QString &)), this,
SIGNAL(updatePopStatus(const QString &)) );
connect(popClient, SIGNAL(mailTransfered(int)), this,
SIGNAL(mailTransfered(int)) );
//relaying size information
connect(popClient, SIGNAL(currentMailSize(int)),
this, SIGNAL(currentMailSize(int)) );
connect(popClient, SIGNAL(downloadedSize(int)),
@@ -127,49 +127,49 @@ void EmailHandler::getMailByList(MailList *mailList)
emit mailTransfered(0);
return;
}
headers = FALSE;
popClient->headersOnly(FALSE, 0);
popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
popClient->setSelectedMails(mailList);
popClient->newConnection(mailAccount.popServer, 110);
}
void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
{
Email mail;
mail.rawMail = message;
mail.serverId = id;
mail.size = size;
mail.downloaded = complete;
emit mailArrived(mail, FALSE);
}
-bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
+bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail)
{
QString temp, boundary;
int pos;
QString delimiter, header, body, mimeHeader, mimeBody;
QString content, contentType, contentAttribute, id, encoding;
QString fileName, storedName;
int enclosureId = 0;
mail->rawMail = in;
mail->received = TRUE;
mail->files.setAutoDelete(TRUE);
temp = lineShift + "." + lineShift;
if (in.right(temp.length()) != temp) {
mail->rawMail += temp;
}
delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
pos = in.find(delimiter, 0, FALSE);
header = in.left(pos);
body = in.right(in.length() - pos - delimiter.length());
if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
@@ -183,63 +183,63 @@ bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
mail->from = p.getString(&pos, '<', false);
mail->from = mail->from.stripWhiteSpace();
if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
mail->from = mail->from.left(mail->from.length() - 1);
mail->from = mail->from.right(mail->from.length() - 1);
}
pos++;
mail->fromMail = p.getString(&pos, '>', false);
} else {
if (p.separatorAt(pos) == '<') //No name.. nasty
pos++;
//pos++;
mail->fromMail = p.getString(&pos, 'z', TRUE);
if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
mail->fromMail.truncate(mail->fromMail.length() - 1);
mail->from=mail->fromMail;
}
}
pos=0;
//Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
{
- QString rec;
-
- if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
- {
- pos++;
- mail->recipients.append(p.getString(&pos, '\r', TRUE));
- }
+ QString rec;
+
+ if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
+ {
+ pos++;
+ mail->recipients.append(p.getString(&pos, '\r', TRUE));
+ }
}
//
//if (pos==-1) mail->recipients.append (tr("undisclosed recipients") );
if ((pos = p.find("CC",':', 0, TRUE)) != -1)
{
- pos++;
- mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
+ pos++;
+ mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
}
if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
pos++;
mail->subject = p.getString(&pos, 'z', TRUE);
}
if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
pos++;
mail->date = p.getString(&pos, 'z', TRUE);
}
if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
pos++;
if ( (p.wordAt(pos).upper() == "ID") &&
(p.separatorAt(pos) == ':') ) {
id = p.getString(&pos, 'z', TRUE);
mail->id = id;
}
}
@@ -419,50 +419,50 @@ int EmailHandler::parse64base(char *src, char *bufOut) {
bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
bufOut[1] <<= 4;
z = li[2] >> 2;
bufOut[1] = bufOut[1] | z; //second byte retrived
processed++;
if (src[3] != '=') {
bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
bufOut[2] <<= 6;
z = li[3];
bufOut[2] = bufOut[2] | z; //third byte retrieved
processed++;
}
}
return processed;
}
int EmailHandler::encodeMime(Email *mail)
{
QString fileName, fileType, contentType, newBody, boundary;
Enclosure *ePtr;
QString userName = mailAccount.name;
- if (userName.length()>0) //only embrace it if there is a user name
- userName += " <" + mailAccount.emailAddress + ">";
+ if (userName.length()>0) //only embrace it if there is a user name
+ userName += " <" + mailAccount.emailAddress + ">";
//add standard headers
newBody = "From: " + userName + "\r\nTo: ";
for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
newBody += *it + " ";
}
newBody += "\r\nCC: ";
for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
newBody += *it + " ";
}
newBody += "\r\nSubject: " + mail->subject + "\r\n";
if (mail->files.count() == 0) { //just a simple mail
newBody += "\r\n" + mail->body;
mail->rawMail = newBody;
return 0;
}
//Build mime encoded mail
boundary = "-----4345=next_bound=0495----";
@@ -489,49 +489,49 @@ int EmailHandler::encodeMime(Email *mail)
contentType = "audio/x-wav";
} else if (fileType == "Movie") {
contentType = "video/mpeg";
} else {
contentType = "application/octet-stream";
}
newBody += "\r\n\r\n--" + boundary + "\r\n";
newBody += "Content-Type: " + contentType + "; name=\"" +
fi.fileName() + "\"\r\n";
newBody += "Content-Transfer-Encoding: base64\r\n";
newBody += "Content-Disposition: inline; filename=\"" +
fi.fileName() + "\"\r\n\r\n";
if (encodeFile(fileName, &newBody) == -1) //file not found?
return -1;
}
newBody += "\r\n\r\n--" + boundary + "--";
mail->rawMail = newBody;
return 0;
}
-int EmailHandler::encodeFile(QString fileName, QString *toBody)
+int EmailHandler::encodeFile(const QString &fileName, QString *toBody)
{
char *fileData;
char *dataPtr;
QString temp;
uint dataSize, count;
QFile f(fileName);
if (! f.open(IO_ReadOnly) ) {
qWarning("could not open file: " + fileName);
return -1;
}
QTextStream s(&f);
dataSize = f.size();
fileData = (char *) malloc(dataSize + 3);
s.readRawBytes(fileData, dataSize);
temp = "";
dataPtr = fileData;
count = 0;
while (dataSize > 0) {
if (dataSize < 3) {
encode64base(dataPtr, &temp, dataSize);
dataSize = 0;
} else {