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

KMIME Library

kmime_message.cpp
00001 /*
00002     kmime_message.cpp
00003 
00004     KMime, the KDE Internet mail/usenet news message library.
00005     Copyright (c) 2001 the KMime authors.
00006     See file AUTHORS for details
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "kmime_message.h"
00025 #include "kmime_message_p.h"
00026 #include "kmime_util_p.h"
00027 
00028 #include <KGlobal>
00029 
00030 using namespace KMime;
00031 
00032 namespace KMime {
00033 
00034 Message::Message()
00035   : Content( new MessagePrivate( this ) )
00036 {
00037 }
00038 
00039 Message::Message(MessagePrivate * d)
00040   : Content( d )
00041 {
00042 }
00043 
00044 Message::~Message()
00045 {
00046 }
00047 
00048 void Message::parse()
00049 {
00050   // KDE5: remove this virtual reimplementation.
00051   Content::parse();
00052 }
00053 
00054 QByteArray Message::assembleHeaders()
00055 {
00056   // Create the mandatory fields (RFC5322) if they do not exist already.
00057   date( true );
00058   from( true );
00059 
00060   // Make sure the mandatory MIME-Version field (RFC2045) is present and valid.
00061   Headers::MIMEVersion *mimeVersion = header<Headers::MIMEVersion>( true );
00062   mimeVersion->from7BitString( "1.0" );
00063 
00064   // Assemble all header fields.
00065   return Content::assembleHeaders();
00066 }
00067 
00068 void Message::clear()
00069 {
00070   // KDE5: remove this virtual reimplementation.
00071   Content::clear();
00072 }
00073 
00074 Headers::Base *Message::getHeaderByType( const char *type )
00075 {
00076   // KDE5: remove this virtual reimplementation.
00077   return headerByType( type );
00078 }
00079 
00080 Headers::Base *Message::headerByType( const char *type )
00081 {
00082   // KDE5: remove this virtual reimplementation.
00083   return Content::headerByType( type );
00084 }
00085 
00086 void Message::setHeader( Headers::Base *h )
00087 {
00088   // KDE5: remove this virtual reimplementation.
00089   Content::setHeader( h );
00090 }
00091 
00092 bool Message::removeHeader( const char *type )
00093 {
00094   // KDE5: remove this virtual reimplementation.
00095   return Content::removeHeader( type );
00096 }
00097 
00098 bool Message::isTopLevel() const
00099 {
00100   return Content::isTopLevel();
00101 }
00102 
00103 Content *Message::mainBodyPart( const QByteArray &type )
00104 {
00105   KMime::Content *c = this;
00106   while ( c ) {
00107     // not a multipart message
00108     const KMime::Headers::ContentType * const contentType = c->contentType();
00109     if ( !contentType->isMultipart() ) {
00110       if ( contentType->mimeType() == type || type.isEmpty() ) {
00111         return c;
00112       }
00113       return 0;
00114     }
00115 
00116     // empty multipart
00117     if ( c->contents().count() == 0 ) {
00118       return 0;
00119     }
00120 
00121     // multipart/alternative
00122     if ( contentType->subType() == "alternative" ) {
00123       if ( type.isEmpty() ) {
00124         return c->contents().first();
00125       }
00126       foreach ( Content *c1, c->contents() ) {
00127         if ( c1->contentType()->mimeType() == type ) {
00128           return c1;
00129         }
00130       }
00131       return 0;
00132     }
00133 
00134     c = c->contents().first();
00135   }
00136 
00137   return 0;
00138 }
00139 
00140 QString Message::mimeType()
00141 {
00142   static const QString &message_rfc822 = KGlobal::staticQString( QLatin1String( "message/rfc822" ) );
00143   return message_rfc822;
00144 }
00145 
00146 
00147 // @cond PRIVATE
00148 #define kmime_mk_header_accessor( type, method ) \
00149 Headers::type *Message::method( bool create ) { \
00150   return header<Headers::type>( create ); \
00151 }
00152 
00153 kmime_mk_header_accessor( MessageID, messageID )
00154 kmime_mk_header_accessor( Subject, subject )
00155 kmime_mk_header_accessor( Date, date )
00156 kmime_mk_header_accessor( Organization, organization )
00157 kmime_mk_header_accessor( From, from )
00158 kmime_mk_header_accessor( ReplyTo, replyTo )
00159 kmime_mk_header_accessor( To, to )
00160 kmime_mk_header_accessor( Cc, cc )
00161 kmime_mk_header_accessor( Bcc, bcc )
00162 kmime_mk_header_accessor( References, references )
00163 kmime_mk_header_accessor( UserAgent, userAgent )
00164 kmime_mk_header_accessor( InReplyTo, inReplyTo )
00165 kmime_mk_header_accessor( Sender, sender )
00166 
00167 #undef kmime_mk_header_accessor
00168 // @endcond
00169 
00170 }
00171 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:24:34 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KMIME Library

Skip menu "KMIME Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 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