mailheader.cc
00001 /*************************************************************************** 00002 mailheader.cc - description 00003 ------------------- 00004 begin : Tue Oct 24 2000 00005 copyright : (C) 2000 by Sven Carstens 00006 email : s.carstens@gmx.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "mailheader.h" 00019 #include "rfcdecoder.h" 00020 00021 mailHeader::mailHeader () 00022 { 00023 toAdr.setAutoDelete (true); 00024 ccAdr.setAutoDelete (true); 00025 bccAdr.setAutoDelete (true); 00026 setType ("text/plain"); 00027 gmt_offset = 0; 00028 } 00029 00030 mailHeader::~mailHeader () 00031 { 00032 } 00033 00034 void 00035 mailHeader::addHdrLine (mimeHdrLine * inLine) 00036 { 00037 mimeHdrLine *addLine = new mimeHdrLine (inLine); 00038 00039 const TQCString label(addLine->getLabel()); 00040 TQCString value(addLine->getValue()); 00041 00042 if (!qstricmp (label, "Return-Path")) { 00043 returnpathAdr.parseAddress (value.data ()); 00044 goto out; 00045 } 00046 if (!qstricmp (label, "Sender")) { 00047 senderAdr.parseAddress (value.data ()); 00048 goto out; 00049 } 00050 if (!qstricmp (label, "From")) { 00051 fromAdr.parseAddress (value.data ()); 00052 goto out; 00053 } 00054 if (!qstricmp (label, "Reply-To")) { 00055 replytoAdr.parseAddress (value.data ()); 00056 goto out; 00057 } 00058 if (!qstricmp (label, "To")) { 00059 mailHeader::parseAddressList (value, &toAdr); 00060 goto out; 00061 } 00062 if (!qstricmp (label, "CC")) { 00063 mailHeader::parseAddressList (value, &ccAdr); 00064 goto out; 00065 } 00066 if (!qstricmp (label, "BCC")) { 00067 mailHeader::parseAddressList (value, &bccAdr); 00068 goto out; 00069 } 00070 if (!qstricmp (label, "Subject")) { 00071 _subject = value.simplifyWhiteSpace(); 00072 goto out; 00073 } 00074 if (!qstricmp (label.data (), "Date")) { 00075 mDate = value; 00076 goto out; 00077 } 00078 if (!qstricmp (label.data (), "Message-ID")) { 00079 int start = value.findRev ('<'); 00080 int end = value.findRev ('>'); 00081 if (start < end) 00082 messageID = value.mid (start, end - start + 1); 00083 else { 00084 qWarning("bad Message-ID"); 00085 /* messageID = value; */ 00086 } 00087 goto out; 00088 } 00089 if (!qstricmp (label.data (), "In-Reply-To")) { 00090 int start = value.findRev ('<'); 00091 int end = value.findRev ('>'); 00092 if (start < end) 00093 inReplyTo = value.mid (start, end - start + 1); 00094 goto out; 00095 } 00096 00097 // everything else is handled by mimeHeader 00098 mimeHeader::addHdrLine (inLine); 00099 delete addLine; 00100 return; 00101 00102 out: 00103 // cout << label.data() << ": '" << value.data() << "'" << endl; 00104 00105 //need only to add this line if not handled by mimeHeader 00106 originalHdrLines.append (addLine); 00107 } 00108 00109 void 00110 mailHeader::outputHeader (mimeIO & useIO) 00111 { 00112 static const TQCString __returnPath("Return-Path: ", 14); 00113 static const TQCString __from ("From: ", 7); 00114 static const TQCString __sender ("Sender: ", 9); 00115 static const TQCString __replyTo ("Reply-To: ", 11); 00116 static const TQCString __to ("To: ", 5); 00117 static const TQCString __cc ("CC: ", 5); 00118 static const TQCString __bcc ("BCC: ", 6); 00119 static const TQCString __subject ("Subject: ", 10); 00120 static const TQCString __messageId ("Message-ID: ", 13); 00121 static const TQCString __inReplyTo ("In-Reply-To: ", 14); 00122 static const TQCString __references("References: ", 13); 00123 static const TQCString __date ("Date: ", 7); 00124 00125 if (!returnpathAdr.isEmpty()) 00126 useIO.outputMimeLine(__returnPath + returnpathAdr.getStr()); 00127 if (!fromAdr.isEmpty()) 00128 useIO.outputMimeLine(__from + fromAdr.getStr()); 00129 if (!senderAdr.isEmpty()) 00130 useIO.outputMimeLine(__sender + senderAdr.getStr()); 00131 if (!replytoAdr.isEmpty()) 00132 useIO.outputMimeLine(__replyTo + replytoAdr.getStr()); 00133 00134 if (toAdr.count()) 00135 useIO.outputMimeLine(mimeHdrLine::truncateLine(__to + 00136 mailHeader::getAddressStr(&toAdr))); 00137 if (ccAdr.count()) 00138 useIO.outputMimeLine(mimeHdrLine::truncateLine(__cc + 00139 mailHeader::getAddressStr(&ccAdr))); 00140 if (bccAdr.count()) 00141 useIO.outputMimeLine(mimeHdrLine::truncateLine(__bcc + 00142 mailHeader::getAddressStr(&bccAdr))); 00143 if (!_subject.isEmpty()) 00144 useIO.outputMimeLine(mimeHdrLine::truncateLine(__subject + _subject)); 00145 if (!messageID.isEmpty()) 00146 useIO.outputMimeLine(mimeHdrLine::truncateLine(__messageId + messageID)); 00147 if (!inReplyTo.isEmpty()) 00148 useIO.outputMimeLine(mimeHdrLine::truncateLine(__inReplyTo + inReplyTo)); 00149 if (!references.isEmpty()) 00150 useIO.outputMimeLine(mimeHdrLine::truncateLine(__references + references)); 00151 00152 if (!mDate.isEmpty()) 00153 useIO.outputMimeLine(__date + mDate); 00154 mimeHeader::outputHeader(useIO); 00155 } 00156 00157 int 00158 mailHeader::parseAddressList (const char *inCStr, 00159 TQPtrList < mailAddress > *aList) 00160 { 00161 int advance = 0; 00162 int skip = 1; 00163 char *aCStr = (char *) inCStr; 00164 00165 if (!aCStr || !aList) 00166 return 0; 00167 while (skip > 0) 00168 { 00169 mailAddress *aAddress = new mailAddress; 00170 skip = aAddress->parseAddress (aCStr); 00171 if (skip) 00172 { 00173 aCStr += skip; 00174 if (skip < 0) 00175 advance -= skip; 00176 else 00177 advance += skip; 00178 aList->append (aAddress); 00179 } 00180 else 00181 { 00182 delete aAddress; 00183 break; 00184 } 00185 } 00186 return advance; 00187 } 00188 00189 TQCString 00190 mailHeader::getAddressStr (TQPtrList < mailAddress > *aList) 00191 { 00192 TQCString retVal; 00193 00194 TQPtrListIterator < mailAddress > it = TQPtrListIterator < mailAddress > (*aList); 00195 while (it.current ()) 00196 { 00197 retVal += it.current ()->getStr (); 00198 ++it; 00199 if (it.current ()) 00200 retVal += ", "; 00201 } 00202 return retVal; 00203 }