2011-09-02 12:20:33 +00:00
|
|
|
/*
|
2012-07-24 14:06:55 +00:00
|
|
|
Copyright (c) 2011-2012 - Tőkés Attila
|
2011-09-02 12:20:33 +00:00
|
|
|
|
|
|
|
This file is part of SmtpClient for Qt.
|
|
|
|
|
2012-07-24 14:06:55 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2011-09-02 12:20:33 +00:00
|
|
|
|
2012-07-24 14:06:55 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-09-02 12:20:33 +00:00
|
|
|
|
2011-09-02 15:24:39 +00:00
|
|
|
See the LICENSE file for more details.
|
2011-09-02 12:20:33 +00:00
|
|
|
*/
|
|
|
|
|
2011-08-30 18:59:16 +00:00
|
|
|
#include "mimepart.h"
|
2011-11-13 17:18:58 +00:00
|
|
|
#include "quotedprintable.h"
|
2011-08-30 18:59:16 +00:00
|
|
|
|
|
|
|
/* [1] Constructors and Destructors */
|
|
|
|
|
|
|
|
MimePart::MimePart()
|
|
|
|
{
|
2011-11-13 17:18:58 +00:00
|
|
|
cEncoding = _7Bit;
|
|
|
|
prepared = false;
|
2012-07-23 18:01:08 +00:00
|
|
|
cBoundary = "";
|
2011-08-30 18:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MimePart::~MimePart()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [1] --- */
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Getters and Setters */
|
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
void MimePart::setContent(const QByteArray & content)
|
2011-08-30 18:59:16 +00:00
|
|
|
{
|
|
|
|
this->content = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::setHeader(const QString & header)
|
|
|
|
{
|
|
|
|
this->header = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::addHeaderLine(const QString & line)
|
|
|
|
{
|
2012-07-23 18:01:08 +00:00
|
|
|
this->header += line + "\r\n";
|
2011-08-30 18:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString& MimePart::getHeader() const
|
|
|
|
{
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
const QByteArray& MimePart::getContent() const
|
2011-08-30 18:59:16 +00:00
|
|
|
{
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
void MimePart::setContentId(const QString & cId)
|
|
|
|
{
|
|
|
|
this->cId = cId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & MimePart::getContentId() const
|
|
|
|
{
|
|
|
|
return this->cId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::setContentName(const QString & cName)
|
|
|
|
{
|
|
|
|
this->cName = cName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & MimePart::getContentName() const
|
|
|
|
{
|
|
|
|
return this->cName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::setContentType(const QString & cType)
|
|
|
|
{
|
|
|
|
this->cType = cType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & MimePart::getContentType() const
|
|
|
|
{
|
|
|
|
return this->cType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::setCharset(const QString & charset)
|
|
|
|
{
|
|
|
|
this->cCharset = charset;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & MimePart::getCharset() const
|
|
|
|
{
|
|
|
|
return this->cCharset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimePart::setEncoding(Encoding enc)
|
|
|
|
{
|
|
|
|
this->cEncoding = enc;
|
|
|
|
}
|
|
|
|
|
|
|
|
MimePart::Encoding MimePart::getEncoding() const
|
|
|
|
{
|
|
|
|
return this->cEncoding;
|
|
|
|
}
|
|
|
|
|
2011-08-30 18:59:16 +00:00
|
|
|
/* [2] --- */
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Public methods */
|
|
|
|
|
|
|
|
QString MimePart::toString()
|
|
|
|
{
|
2011-11-13 17:18:58 +00:00
|
|
|
if (!prepared)
|
|
|
|
prepare();
|
2011-11-10 18:50:38 +00:00
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
return mimeString;
|
2011-08-30 18:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [3] --- */
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Protected methods */
|
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
void MimePart::prepare()
|
|
|
|
{
|
|
|
|
mimeString = QString();
|
|
|
|
|
|
|
|
/* === Header Prepare === */
|
|
|
|
|
|
|
|
/* Content-Type */
|
|
|
|
mimeString.append("Content-Type: ").append(cType);
|
|
|
|
|
|
|
|
if (cName != "")
|
|
|
|
mimeString.append("; name=\"").append(cName).append("\"");
|
|
|
|
|
|
|
|
if (cCharset != "")
|
|
|
|
mimeString.append("; charset=").append(cCharset);
|
|
|
|
|
2012-07-23 18:01:08 +00:00
|
|
|
if (cBoundary != "")
|
|
|
|
mimeString.append("; boundary=").append(cBoundary);
|
|
|
|
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
/* ------------ */
|
|
|
|
|
|
|
|
/* Content-Transfer-Encoding */
|
|
|
|
mimeString.append("Content-Transfer-Encoding: ");
|
|
|
|
switch (cEncoding)
|
|
|
|
{
|
|
|
|
case _7Bit:
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("7bit\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
case _8Bit:
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("8bit\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
case Base64:
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("base64\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
case QuotedPrintable:
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("quoted-printable\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* ------------------------ */
|
|
|
|
|
|
|
|
/* Content-Id */
|
|
|
|
if (cId != NULL)
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("Content-ID: <").append(cId).append(">\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
/* ---------- */
|
|
|
|
|
2012-07-23 18:01:08 +00:00
|
|
|
/* Addition header lines */
|
2011-11-13 17:18:58 +00:00
|
|
|
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append(header).append("\r\n");
|
2011-11-13 17:18:58 +00:00
|
|
|
|
2012-07-23 18:01:08 +00:00
|
|
|
/* ------------------------- */
|
|
|
|
|
2011-11-13 17:18:58 +00:00
|
|
|
/* === End of Header Prepare === */
|
|
|
|
|
2012-07-23 18:01:08 +00:00
|
|
|
/* === Content === */
|
2011-11-13 17:18:58 +00:00
|
|
|
switch (cEncoding)
|
|
|
|
{
|
|
|
|
case _7Bit:
|
|
|
|
mimeString.append(QString(content).toAscii());
|
|
|
|
break;
|
|
|
|
case _8Bit:
|
|
|
|
mimeString.append(content);
|
|
|
|
break;
|
|
|
|
case Base64:
|
2012-07-23 18:01:08 +00:00
|
|
|
mimeString.append(formatter.format(content.toBase64()));
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
case QuotedPrintable:
|
2012-07-23 18:01:08 +00:00
|
|
|
mimeString.append(formatter.format(QuotedPrintable::encode(content), true));
|
2011-11-13 17:18:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-16 12:42:26 +00:00
|
|
|
mimeString.append("\r\n");
|
2012-07-23 18:01:08 +00:00
|
|
|
/* === End of Content === */
|
2011-11-13 17:18:58 +00:00
|
|
|
|
|
|
|
prepared = true;
|
|
|
|
}
|
2011-08-30 18:59:16 +00:00
|
|
|
|
|
|
|
/* [4] --- */
|