kioslave/imap4
mailheader.cpp
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 <QList> 00020 00021 mailHeader::mailHeader () 00022 { 00023 setType ("text/plain"); 00024 gmt_offset = 0; 00025 } 00026 00027 mailHeader::~mailHeader () 00028 { 00029 } 00030 00031 void 00032 mailHeader::addHdrLine (mimeHdrLine * inLine) 00033 { 00034 mimeHdrLine *addLine = new mimeHdrLine (inLine); 00035 00036 const QByteArray label(addLine->getLabel()); 00037 const QByteArray value(addLine->getValue()); 00038 00039 if (!qstricmp (label, "Return-Path")) { 00040 returnpathAdr.parseAddress (value.data ()); 00041 goto out; 00042 } 00043 if (!qstricmp (label, "Sender")) { 00044 senderAdr.parseAddress (value.data ()); 00045 goto out; 00046 } 00047 if (!qstricmp (label, "From")) { 00048 fromAdr.parseAddress (value.data ()); 00049 goto out; 00050 } 00051 if (!qstricmp (label, "Reply-To")) { 00052 replytoAdr.parseAddress (value.data ()); 00053 goto out; 00054 } 00055 if (!qstricmp (label, "To")) { 00056 mailHeader::parseAddressList (value, toAdr); 00057 goto out; 00058 } 00059 if (!qstricmp (label, "CC")) { 00060 mailHeader::parseAddressList (value, ccAdr); 00061 goto out; 00062 } 00063 if (!qstricmp (label, "BCC")) { 00064 mailHeader::parseAddressList (value, bccAdr); 00065 goto out; 00066 } 00067 if (!qstricmp (label, "Subject")) { 00068 _subject = value.simplified(); 00069 goto out; 00070 } 00071 if (!qstricmp (label.data (), "Date")) { 00072 mDate = value; 00073 goto out; 00074 } 00075 if (!qstricmp (label.data (), "Message-ID")) { 00076 int start = value.lastIndexOf ('<'); 00077 int end = value.lastIndexOf ('>'); 00078 if (start < end) 00079 messageID = value.mid (start, end - start + 1); 00080 else { 00081 qWarning("bad Message-ID"); 00082 /* messageID = value; */ 00083 } 00084 goto out; 00085 } 00086 if (!qstricmp (label.data (), "In-Reply-To")) { 00087 int start = value.lastIndexOf ('<'); 00088 int end = value.lastIndexOf ('>'); 00089 if (start < end) 00090 inReplyTo = value.mid (start, end - start + 1); 00091 goto out; 00092 } 00093 00094 // everything else is handled by mimeHeader 00095 mimeHeader::addHdrLine (inLine); 00096 delete addLine; 00097 return; 00098 00099 out: 00100 // cout << label.data() << ": '" << value.data() << "'" << endl; 00101 00102 //need only to add this line if not handled by mimeHeader 00103 originalHdrLines.append (addLine); 00104 } 00105 00106 void 00107 mailHeader::outputHeader (mimeIO & useIO) 00108 { 00109 static const QByteArray __returnPath("Return-Path: "); 00110 static const QByteArray __from ("From: "); 00111 static const QByteArray __sender ("Sender: "); 00112 static const QByteArray __replyTo ("Reply-To: "); 00113 static const QByteArray __to ("To: "); 00114 static const QByteArray __cc ("CC: "); 00115 static const QByteArray __bcc ("BCC: "); 00116 static const QByteArray __subject ("Subject: "); 00117 static const QByteArray __messageId ("Message-ID: "); 00118 static const QByteArray __inReplyTo ("In-Reply-To: "); 00119 static const QByteArray __references("References: "); 00120 static const QByteArray __date ("Date: "); 00121 00122 if (!returnpathAdr.isEmpty()) 00123 useIO.outputMimeLine(__returnPath + returnpathAdr.getStr()); 00124 if (!fromAdr.isEmpty()) 00125 useIO.outputMimeLine(__from + fromAdr.getStr()); 00126 if (!senderAdr.isEmpty()) 00127 useIO.outputMimeLine(__sender + senderAdr.getStr()); 00128 if (!replytoAdr.isEmpty()) 00129 useIO.outputMimeLine(__replyTo + replytoAdr.getStr()); 00130 00131 if (toAdr.count()) 00132 useIO.outputMimeLine(mimeHdrLine::truncateLine(__to + 00133 mailHeader::getAddressStr(toAdr))); 00134 if (ccAdr.count()) 00135 useIO.outputMimeLine(mimeHdrLine::truncateLine(__cc + 00136 mailHeader::getAddressStr(ccAdr))); 00137 if (bccAdr.count()) 00138 useIO.outputMimeLine(mimeHdrLine::truncateLine(__bcc + 00139 mailHeader::getAddressStr(bccAdr))); 00140 if (!_subject.isEmpty()) 00141 useIO.outputMimeLine(mimeHdrLine::truncateLine(__subject + _subject)); 00142 if (!messageID.isEmpty()) 00143 useIO.outputMimeLine(mimeHdrLine::truncateLine(__messageId + messageID)); 00144 if (!inReplyTo.isEmpty()) 00145 useIO.outputMimeLine(mimeHdrLine::truncateLine(__inReplyTo + inReplyTo)); 00146 if (!references.isEmpty()) 00147 useIO.outputMimeLine(mimeHdrLine::truncateLine(__references + references)); 00148 00149 if (!mDate.isEmpty()) 00150 useIO.outputMimeLine(__date + mDate); 00151 mimeHeader::outputHeader(useIO); 00152 } 00153 00154 int 00155 mailHeader::parseAddressList (const char *inCStr, 00156 QList < mailAddress *> &aList) 00157 { 00158 int advance = 0; 00159 int skip = 1; 00160 char *aCStr = (char *) inCStr; 00161 00162 if (!aCStr) 00163 return 0; 00164 while (skip > 0) 00165 { 00166 mailAddress *aAddress = new mailAddress; 00167 skip = aAddress->parseAddress (aCStr); 00168 if (skip) 00169 { 00170 aCStr += skip; 00171 if (skip < 0) 00172 advance -= skip; 00173 else 00174 advance += skip; 00175 aList.append (aAddress); 00176 } 00177 else 00178 { 00179 delete aAddress; 00180 break; 00181 } 00182 } 00183 return advance; 00184 } 00185 00186 QByteArray 00187 mailHeader::getAddressStr (QList < mailAddress *> &aList) 00188 { 00189 QByteArray retVal; 00190 00191 QListIterator < mailAddress *> it = QListIterator < mailAddress *>(aList); 00192 mailAddress *addr; 00193 while (it.hasNext()) 00194 { 00195 addr = it.next(); 00196 retVal += addr->getStr (); 00197 if (it.hasNext() ) 00198 retVal += ", "; 00199 } 00200 00201 00202 return retVal; 00203 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.