• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 API Reference
  • KDE Home
  • Contact Us
 

kioslave/imap4

  • kioslave
  • imap4
mailheader.cpp
1 /***************************************************************************
2  mailheader.cc - 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 <QList>
20 
21 mailHeader::mailHeader ()
22 {
23  setType ("text/plain");
24  gmt_offset = 0;
25 }
26 
27 mailHeader::~mailHeader ()
28 {
29 }
30 
31 void
32 mailHeader::addHdrLine (mimeHdrLine * inLine)
33 {
34  mimeHdrLine *addLine = new mimeHdrLine (inLine);
35 
36  const QByteArray label(addLine->getLabel());
37  const QByteArray value(addLine->getValue());
38 
39  if (!qstricmp (label, "Return-Path")) {
40  returnpathAdr.parseAddress (value.data ());
41  goto out;
42  }
43  if (!qstricmp (label, "Sender")) {
44  senderAdr.parseAddress (value.data ());
45  goto out;
46  }
47  if (!qstricmp (label, "From")) {
48  fromAdr.parseAddress (value.data ());
49  goto out;
50  }
51  if (!qstricmp (label, "Reply-To")) {
52  replytoAdr.parseAddress (value.data ());
53  goto out;
54  }
55  if (!qstricmp (label, "To")) {
56  mailHeader::parseAddressList (value, toAdr);
57  goto out;
58  }
59  if (!qstricmp (label, "CC")) {
60  mailHeader::parseAddressList (value, ccAdr);
61  goto out;
62  }
63  if (!qstricmp (label, "BCC")) {
64  mailHeader::parseAddressList (value, bccAdr);
65  goto out;
66  }
67  if (!qstricmp (label, "Subject")) {
68  _subject = value.simplified();
69  goto out;
70  }
71  if (!qstricmp (label.data (), "Date")) {
72  mDate = value;
73  goto out;
74  }
75  if (!qstricmp (label.data (), "Message-ID")) {
76  int start = value.lastIndexOf ('<');
77  int end = value.lastIndexOf ('>');
78  if (start < end)
79  messageID = value.mid (start, end - start + 1);
80  else {
81  qWarning("bad Message-ID");
82  /* messageID = value; */
83  }
84  goto out;
85  }
86  if (!qstricmp (label.data (), "In-Reply-To")) {
87  int start = value.lastIndexOf ('<');
88  int end = value.lastIndexOf ('>');
89  if (start < end)
90  inReplyTo = value.mid (start, end - start + 1);
91  goto out;
92  }
93 
94  // everything else is handled by mimeHeader
95  mimeHeader::addHdrLine (inLine);
96  delete addLine;
97  return;
98 
99  out:
100 // cout << label.data() << ": '" << value.data() << "'" << endl;
101 
102  //need only to add this line if not handled by mimeHeader
103  originalHdrLines.append (addLine);
104 }
105 
106 void
107 mailHeader::outputHeader (mimeIO & useIO)
108 {
109  static const QByteArray __returnPath("Return-Path: ");
110  static const QByteArray __from ("From: ");
111  static const QByteArray __sender ("Sender: ");
112  static const QByteArray __replyTo ("Reply-To: ");
113  static const QByteArray __to ("To: ");
114  static const QByteArray __cc ("CC: ");
115  static const QByteArray __bcc ("BCC: ");
116  static const QByteArray __subject ("Subject: ");
117  static const QByteArray __messageId ("Message-ID: ");
118  static const QByteArray __inReplyTo ("In-Reply-To: ");
119  static const QByteArray __references("References: ");
120  static const QByteArray __date ("Date: ");
121 
122  if (!returnpathAdr.isEmpty())
123  useIO.outputMimeLine(__returnPath + returnpathAdr.getStr());
124  if (!fromAdr.isEmpty())
125  useIO.outputMimeLine(__from + fromAdr.getStr());
126  if (!senderAdr.isEmpty())
127  useIO.outputMimeLine(__sender + senderAdr.getStr());
128  if (!replytoAdr.isEmpty())
129  useIO.outputMimeLine(__replyTo + replytoAdr.getStr());
130 
131  if (toAdr.count())
132  useIO.outputMimeLine(mimeHdrLine::truncateLine(__to +
133  mailHeader::getAddressStr(toAdr)));
134  if (ccAdr.count())
135  useIO.outputMimeLine(mimeHdrLine::truncateLine(__cc +
136  mailHeader::getAddressStr(ccAdr)));
137  if (bccAdr.count())
138  useIO.outputMimeLine(mimeHdrLine::truncateLine(__bcc +
139  mailHeader::getAddressStr(bccAdr)));
140  if (!_subject.isEmpty())
141  useIO.outputMimeLine(mimeHdrLine::truncateLine(__subject + _subject));
142  if (!messageID.isEmpty())
143  useIO.outputMimeLine(mimeHdrLine::truncateLine(__messageId + messageID));
144  if (!inReplyTo.isEmpty())
145  useIO.outputMimeLine(mimeHdrLine::truncateLine(__inReplyTo + inReplyTo));
146  if (!references.isEmpty())
147  useIO.outputMimeLine(mimeHdrLine::truncateLine(__references + references));
148 
149  if (!mDate.isEmpty())
150  useIO.outputMimeLine(__date + mDate);
151  mimeHeader::outputHeader(useIO);
152 }
153 
154 int
155 mailHeader::parseAddressList (const char *inCStr,
156  QList < mailAddress *> &aList)
157 {
158  int advance = 0;
159  int skip = 1;
160  char *aCStr = (char *) inCStr;
161 
162  if (!aCStr)
163  return 0;
164  while (skip > 0)
165  {
166  mailAddress *aAddress = new mailAddress;
167  skip = aAddress->parseAddress (aCStr);
168  if (skip)
169  {
170  aCStr += skip;
171  if (skip < 0)
172  advance -= skip;
173  else
174  advance += skip;
175  aList.append (aAddress);
176  }
177  else
178  {
179  delete aAddress;
180  break;
181  }
182  }
183  return advance;
184 }
185 
186 QByteArray
187 mailHeader::getAddressStr (QList < mailAddress *> &aList)
188 {
189  QByteArray retVal;
190 
191  QListIterator < mailAddress *> it = QListIterator < mailAddress *>(aList);
192  mailAddress *addr;
193  while (it.hasNext())
194  {
195  addr = it.next();
196  retVal += addr->getStr ();
197  if (it.hasNext() )
198  retVal += ", ";
199  }
200 
201 
202  return retVal;
203 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 4 2012 14:35:12 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kioslave/imap4

Skip menu "kioslave/imap4"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal