You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
5.9 KiB
204 lines
5.9 KiB
15 years ago
|
/***************************************************************************
|
||
|
mailheader.cc - description
|
||
|
-------------------
|
||
|
begin : Tue Oct 24 2000
|
||
|
copyright : (C) 2000 by Sven Carstens
|
||
|
email : s.carstens@gmx.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include "mailheader.h"
|
||
|
#include "rfcdecoder.h"
|
||
|
|
||
|
mailHeader::mailHeader ()
|
||
|
{
|
||
|
toAdr.setAutoDelete (true);
|
||
|
ccAdr.setAutoDelete (true);
|
||
|
bccAdr.setAutoDelete (true);
|
||
|
setType ("text/plain");
|
||
|
gmt_offset = 0;
|
||
|
}
|
||
|
|
||
|
mailHeader::~mailHeader ()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void
|
||
|
mailHeader::addHdrLine (mimeHdrLine * inLine)
|
||
|
{
|
||
|
mimeHdrLine *addLine = new mimeHdrLine (inLine);
|
||
|
|
||
15 years ago
|
const TQCString label(addLine->getLabel());
|
||
14 years ago
|
TQCString value(addLine->getValue());
|
||
15 years ago
|
|
||
13 years ago
|
if (!tqstricmp (label, "Return-Path")) {
|
||
15 years ago
|
returnpathAdr.parseAddress (value.data ());
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "Sender")) {
|
||
15 years ago
|
senderAdr.parseAddress (value.data ());
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "From")) {
|
||
15 years ago
|
fromAdr.parseAddress (value.data ());
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "Reply-To")) {
|
||
15 years ago
|
replytoAdr.parseAddress (value.data ());
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "To")) {
|
||
15 years ago
|
mailHeader::parseAddressList (value, &toAdr);
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "CC")) {
|
||
15 years ago
|
mailHeader::parseAddressList (value, &ccAdr);
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "BCC")) {
|
||
15 years ago
|
mailHeader::parseAddressList (value, &bccAdr);
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label, "Subject")) {
|
||
15 years ago
|
_subject = value.simplifyWhiteSpace();
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label.data (), "Date")) {
|
||
15 years ago
|
mDate = value;
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label.data (), "Message-ID")) {
|
||
13 years ago
|
int start = value.findRev ('<');
|
||
|
int end = value.findRev ('>');
|
||
15 years ago
|
if (start < end)
|
||
|
messageID = value.mid (start, end - start + 1);
|
||
|
else {
|
||
13 years ago
|
tqWarning("bad Message-ID");
|
||
15 years ago
|
/* messageID = value; */
|
||
|
}
|
||
|
goto out;
|
||
|
}
|
||
13 years ago
|
if (!tqstricmp (label.data (), "In-Reply-To")) {
|
||
13 years ago
|
int start = value.findRev ('<');
|
||
|
int end = value.findRev ('>');
|
||
15 years ago
|
if (start < end)
|
||
|
inReplyTo = value.mid (start, end - start + 1);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
// everything else is handled by mimeHeader
|
||
|
mimeHeader::addHdrLine (inLine);
|
||
|
delete addLine;
|
||
|
return;
|
||
|
|
||
|
out:
|
||
|
// cout << label.data() << ": '" << value.data() << "'" << endl;
|
||
|
|
||
|
//need only to add this line if not handled by mimeHeader
|
||
|
originalHdrLines.append (addLine);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
mailHeader::outputHeader (mimeIO & useIO)
|
||
|
{
|
||
15 years ago
|
static const TQCString __returnPath("Return-Path: ", 14);
|
||
|
static const TQCString __from ("From: ", 7);
|
||
|
static const TQCString __sender ("Sender: ", 9);
|
||
|
static const TQCString __replyTo ("Reply-To: ", 11);
|
||
|
static const TQCString __to ("To: ", 5);
|
||
|
static const TQCString __cc ("CC: ", 5);
|
||
|
static const TQCString __bcc ("BCC: ", 6);
|
||
|
static const TQCString __subject ("Subject: ", 10);
|
||
|
static const TQCString __messageId ("Message-ID: ", 13);
|
||
|
static const TQCString __inReplyTo ("In-Reply-To: ", 14);
|
||
|
static const TQCString __references("References: ", 13);
|
||
|
static const TQCString __date ("Date: ", 7);
|
||
15 years ago
|
|
||
|
if (!returnpathAdr.isEmpty())
|
||
|
useIO.outputMimeLine(__returnPath + returnpathAdr.getStr());
|
||
|
if (!fromAdr.isEmpty())
|
||
|
useIO.outputMimeLine(__from + fromAdr.getStr());
|
||
|
if (!senderAdr.isEmpty())
|
||
|
useIO.outputMimeLine(__sender + senderAdr.getStr());
|
||
|
if (!replytoAdr.isEmpty())
|
||
|
useIO.outputMimeLine(__replyTo + replytoAdr.getStr());
|
||
|
|
||
|
if (toAdr.count())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__to +
|
||
|
mailHeader::getAddressStr(&toAdr)));
|
||
|
if (ccAdr.count())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__cc +
|
||
|
mailHeader::getAddressStr(&ccAdr)));
|
||
|
if (bccAdr.count())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__bcc +
|
||
|
mailHeader::getAddressStr(&bccAdr)));
|
||
|
if (!_subject.isEmpty())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__subject + _subject));
|
||
|
if (!messageID.isEmpty())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__messageId + messageID));
|
||
|
if (!inReplyTo.isEmpty())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__inReplyTo + inReplyTo));
|
||
|
if (!references.isEmpty())
|
||
|
useIO.outputMimeLine(mimeHdrLine::truncateLine(__references + references));
|
||
|
|
||
|
if (!mDate.isEmpty())
|
||
|
useIO.outputMimeLine(__date + mDate);
|
||
|
mimeHeader::outputHeader(useIO);
|
||
|
}
|
||
|
|
||
|
int
|
||
|
mailHeader::parseAddressList (const char *inCStr,
|
||
15 years ago
|
TQPtrList < mailAddress > *aList)
|
||
15 years ago
|
{
|
||
|
int advance = 0;
|
||
|
int skip = 1;
|
||
|
char *aCStr = (char *) inCStr;
|
||
|
|
||
|
if (!aCStr || !aList)
|
||
|
return 0;
|
||
|
while (skip > 0)
|
||
|
{
|
||
|
mailAddress *aAddress = new mailAddress;
|
||
|
skip = aAddress->parseAddress (aCStr);
|
||
|
if (skip)
|
||
|
{
|
||
|
aCStr += skip;
|
||
|
if (skip < 0)
|
||
|
advance -= skip;
|
||
|
else
|
||
|
advance += skip;
|
||
|
aList->append (aAddress);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
delete aAddress;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return advance;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQCString
|
||
15 years ago
|
mailHeader::getAddressStr (TQPtrList < mailAddress > *aList)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString retVal;
|
||
15 years ago
|
|
||
15 years ago
|
TQPtrListIterator < mailAddress > it = TQPtrListIterator < mailAddress > (*aList);
|
||
15 years ago
|
while (it.current ())
|
||
|
{
|
||
|
retVal += it.current ()->getStr ();
|
||
|
++it;
|
||
|
if (it.current ())
|
||
|
retVal += ", ";
|
||
|
}
|
||
|
return retVal;
|
||
|
}
|