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

kioslave/imap4

  • sources
  • kde-4.14
  • kdepimlibs
  • 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  }
92  goto out;
93  }
94 
95  // everything else is handled by mimeHeader
96  mimeHeader::addHdrLine( inLine );
97  delete addLine;
98  return;
99 
100  out:
101 // cout << label.data() << ": '" << value.data() << "'" << endl;
102 
103  //need only to add this line if not handled by mimeHeader
104  originalHdrLines.append( addLine );
105 }
106 
107 void
108 mailHeader::outputHeader (mimeIO & useIO)
109 {
110  static const QByteArray __returnPath( "Return-Path: " );
111  static const QByteArray __from ( "From: " );
112  static const QByteArray __sender ( "Sender: " );
113  static const QByteArray __replyTo ( "Reply-To: " );
114  static const QByteArray __to ( "To: " );
115  static const QByteArray __cc ( "CC: " );
116  static const QByteArray __bcc ( "BCC: " );
117  static const QByteArray __subject ( "Subject: " );
118  static const QByteArray __messageId ( "Message-ID: " );
119  static const QByteArray __inReplyTo ( "In-Reply-To: " );
120  static const QByteArray __references( "References: " );
121  static const QByteArray __date ( "Date: " );
122 
123  if ( !returnpathAdr.isEmpty() ) {
124  useIO.outputMimeLine( __returnPath + returnpathAdr.getStr() );
125  }
126  if ( !fromAdr.isEmpty() ) {
127  useIO.outputMimeLine( __from + fromAdr.getStr() );
128  }
129  if ( !senderAdr.isEmpty() ) {
130  useIO.outputMimeLine( __sender + senderAdr.getStr() );
131  }
132  if ( !replytoAdr.isEmpty() ) {
133  useIO.outputMimeLine( __replyTo + replytoAdr.getStr() );
134  }
135 
136  if ( toAdr.count() ) {
137  useIO.outputMimeLine( mimeHdrLine::truncateLine( __to +
138  mailHeader::getAddressStr( toAdr ) ) );
139  }
140  if ( ccAdr.count() ) {
141  useIO.outputMimeLine( mimeHdrLine::truncateLine( __cc +
142  mailHeader::getAddressStr( ccAdr ) ) );
143  }
144  if ( bccAdr.count() ) {
145  useIO.outputMimeLine( mimeHdrLine::truncateLine( __bcc +
146  mailHeader::getAddressStr( bccAdr ) ) );
147  }
148  if ( !_subject.isEmpty() ) {
149  useIO.outputMimeLine( mimeHdrLine::truncateLine( __subject + _subject ) );
150  }
151  if ( !messageID.isEmpty() ) {
152  useIO.outputMimeLine( mimeHdrLine::truncateLine( __messageId + messageID ) );
153  }
154  if ( !inReplyTo.isEmpty() ) {
155  useIO.outputMimeLine( mimeHdrLine::truncateLine( __inReplyTo + inReplyTo ) );
156  }
157  if ( !references.isEmpty() ) {
158  useIO.outputMimeLine( mimeHdrLine::truncateLine( __references + references ) );
159  }
160 
161  if ( !mDate.isEmpty() ) {
162  useIO.outputMimeLine( __date + mDate );
163  }
164  mimeHeader::outputHeader( useIO );
165 }
166 
167 int
168 mailHeader::parseAddressList (const char *inCStr,
169  QList < mailAddress *> &aList)
170 {
171  int advance = 0;
172  int skip = 1;
173  char *aCStr = (char *) inCStr;
174 
175  if ( !aCStr ) {
176  return 0;
177  }
178  while ( skip > 0 ) {
179  mailAddress *aAddress = new mailAddress;
180  skip = aAddress->parseAddress( aCStr );
181  if ( skip ) {
182  aCStr += skip;
183  if ( skip < 0 ) {
184  advance -= skip;
185  } else {
186  advance += skip;
187  }
188  aList.append( aAddress );
189  } else {
190  delete aAddress;
191  break;
192  }
193  }
194  return advance;
195 }
196 
197 QByteArray
198 mailHeader::getAddressStr (QList < mailAddress *> &aList)
199 {
200  QByteArray retVal;
201 
202  QListIterator < mailAddress *> it = QListIterator < mailAddress *>( aList );
203  mailAddress *addr;
204  while ( it.hasNext() ) {
205  addr = it.next();
206  retVal += addr->getStr();
207  if ( it.hasNext() ) {
208  retVal += ", ";
209  }
210  }
211  return retVal;
212 }
mimeHdrLine::getValue
const QByteArray & getValue()
return the value
Definition: mimehdrline.cpp:372
QListIterator::next
const T & next()
QByteArray
mimeIO
Definition: mimeio.h:28
QByteArray::lastIndexOf
int lastIndexOf(char ch, int from) const
QByteArray::isEmpty
bool isEmpty() const
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QList< mailAddress * >
QByteArray::mid
QByteArray mid(int pos, int len) const
mimeHdrLine::getLabel
const QByteArray & getLabel()
return the label
Definition: mimehdrline.cpp:366
mimeHdrLine
Definition: mimehdrline.h:28
QByteArray::simplified
QByteArray simplified() const
QListIterator
QListIterator::hasNext
bool hasNext() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:08 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



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