tdeioslave/imap4

mailheader.cpp
1 /***************************************************************************
2  mailheader.cpp - description
3  -------------------
4  begin : Tue Oct 24 2000
5  copyright : (C) 2000 by Sven Carstens
6  email : s.carstens@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "mailheader.h"
19 #include "rfcdecoder.h"
20 
21 mailHeader::mailHeader ()
22 {
23  toAdr.setAutoDelete (true);
24  ccAdr.setAutoDelete (true);
25  bccAdr.setAutoDelete (true);
26  setType ("text/plain");
27  gmt_offset = 0;
28 }
29 
30 mailHeader::~mailHeader ()
31 {
32 }
33 
34 void
35 mailHeader::addHdrLine (mimeHdrLine * inLine)
36 {
37  mimeHdrLine *addLine = new mimeHdrLine (inLine);
38 
39  const TQCString label(addLine->getLabel());
40  TQCString value(addLine->getValue());
41 
42  if (!tqstricmp (label, "Return-Path")) {
43  returnpathAdr.parseAddress (value.data ());
44  goto out;
45  }
46  if (!tqstricmp (label, "Sender")) {
47  senderAdr.parseAddress (value.data ());
48  goto out;
49  }
50  if (!tqstricmp (label, "From")) {
51  fromAdr.parseAddress (value.data ());
52  goto out;
53  }
54  if (!tqstricmp (label, "Reply-To")) {
55  replytoAdr.parseAddress (value.data ());
56  goto out;
57  }
58  if (!tqstricmp (label, "To")) {
59  mailHeader::parseAddressList (value, &toAdr);
60  goto out;
61  }
62  if (!tqstricmp (label, "CC")) {
63  mailHeader::parseAddressList (value, &ccAdr);
64  goto out;
65  }
66  if (!tqstricmp (label, "BCC")) {
67  mailHeader::parseAddressList (value, &bccAdr);
68  goto out;
69  }
70  if (!tqstricmp (label, "Subject")) {
71  _subject = value.simplifyWhiteSpace();
72  goto out;
73  }
74  if (!tqstricmp (label.data (), "Date")) {
75  mDate = value;
76  goto out;
77  }
78  if (!tqstricmp (label.data (), "Message-ID")) {
79  int start = value.findRev ('<');
80  int end = value.findRev ('>');
81  if (start < end)
82  messageID = value.mid (start, end - start + 1);
83  else {
84  tqWarning("bad Message-ID");
85  /* messageID = value; */
86  }
87  goto out;
88  }
89  if (!tqstricmp (label.data (), "In-Reply-To")) {
90  int start = value.findRev ('<');
91  int end = value.findRev ('>');
92  if (start < end)
93  inReplyTo = value.mid (start, end - start + 1);
94  goto out;
95  }
96 
97  // everything else is handled by mimeHeader
98  mimeHeader::addHdrLine (inLine);
99  delete addLine;
100  return;
101 
102  out:
103 // cout << label.data() << ": '" << value.data() << "'" << endl;
104 
105  //need only to add this line if not handled by mimeHeader
106  originalHdrLines.append (addLine);
107 }
108 
109 void
110 mailHeader::outputHeader (mimeIO & useIO)
111 {
112  static const TQCString __returnPath("Return-Path: ", 14);
113  static const TQCString __from ("From: ", 7);
114  static const TQCString __sender ("Sender: ", 9);
115  static const TQCString __replyTo ("Reply-To: ", 11);
116  static const TQCString __to ("To: ", 5);
117  static const TQCString __cc ("CC: ", 5);
118  static const TQCString __bcc ("BCC: ", 6);
119  static const TQCString __subject ("Subject: ", 10);
120  static const TQCString __messageId ("Message-ID: ", 13);
121  static const TQCString __inReplyTo ("In-Reply-To: ", 14);
122  static const TQCString __references("References: ", 13);
123  static const TQCString __date ("Date: ", 7);
124 
125  if (!returnpathAdr.isEmpty())
126  useIO.outputMimeLine(__returnPath + returnpathAdr.getStr());
127  if (!fromAdr.isEmpty())
128  useIO.outputMimeLine(__from + fromAdr.getStr());
129  if (!senderAdr.isEmpty())
130  useIO.outputMimeLine(__sender + senderAdr.getStr());
131  if (!replytoAdr.isEmpty())
132  useIO.outputMimeLine(__replyTo + replytoAdr.getStr());
133 
134  if (toAdr.count())
135  useIO.outputMimeLine(mimeHdrLine::truncateLine(__to +
136  mailHeader::getAddressStr(&toAdr)));
137  if (ccAdr.count())
138  useIO.outputMimeLine(mimeHdrLine::truncateLine(__cc +
139  mailHeader::getAddressStr(&ccAdr)));
140  if (bccAdr.count())
141  useIO.outputMimeLine(mimeHdrLine::truncateLine(__bcc +
142  mailHeader::getAddressStr(&bccAdr)));
143  if (!_subject.isEmpty())
144  useIO.outputMimeLine(mimeHdrLine::truncateLine(__subject + _subject));
145  if (!messageID.isEmpty())
146  useIO.outputMimeLine(mimeHdrLine::truncateLine(__messageId + messageID));
147  if (!inReplyTo.isEmpty())
148  useIO.outputMimeLine(mimeHdrLine::truncateLine(__inReplyTo + inReplyTo));
149  if (!references.isEmpty())
150  useIO.outputMimeLine(mimeHdrLine::truncateLine(__references + references));
151 
152  if (!mDate.isEmpty())
153  useIO.outputMimeLine(__date + mDate);
154  mimeHeader::outputHeader(useIO);
155 }
156 
157 int
158 mailHeader::parseAddressList (const char *inCStr,
159  TQPtrList < mailAddress > *aList)
160 {
161  int advance = 0;
162  int skip = 1;
163  char *aCStr = (char *) inCStr;
164 
165  if (!aCStr || !aList)
166  return 0;
167  while (skip > 0)
168  {
169  mailAddress *aAddress = new mailAddress;
170  skip = aAddress->parseAddress (aCStr);
171  if (skip)
172  {
173  aCStr += skip;
174  if (skip < 0)
175  advance -= skip;
176  else
177  advance += skip;
178  aList->append (aAddress);
179  }
180  else
181  {
182  delete aAddress;
183  break;
184  }
185  }
186  return advance;
187 }
188 
189 TQCString
190 mailHeader::getAddressStr (TQPtrList < mailAddress > *aList)
191 {
192  TQCString retVal;
193 
194  TQPtrListIterator < mailAddress > it = TQPtrListIterator < mailAddress > (*aList);
195  while (it.current ())
196  {
197  retVal += it.current ()->getStr ();
198  ++it;
199  if (it.current ())
200  retVal += ", ";
201  }
202  return retVal;
203 }
const TQCString & getLabel()
return the label
const TQCString & getValue()
return the value
Definition: mimeio.h:29