diff -pubNr /opt/kde-stable/include/kmime/kmime_charfreq.h /opt/kde-trunk/include/kmime/kmime_charfreq.h
--- /opt/kde-stable/include/kmime/kmime_charfreq.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_charfreq.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_charfreq.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
 
     This library is free software; you can redistribute it and/or
@@ -30,22 +30,28 @@
   @authors Marc Mutz \<mutz@kde.org\>
 
   @glossary @anchor Eight-Bit @anchor eight-bit @b 8-bit:
-  Data that contains bytes with at least one value greater than 127.
+  Data that contains bytes with at least one value greater than 127, or at
+  least one NUL byte.
 
   @glossary @anchor Eight-Bit-Binary @anchor eight-bit-binary @b 8-bit-binary:
-  Eight-bit data that contains a high percentage of non-ascii values.
+  Eight-bit data that contains a high percentage of non-ascii values,
+  or lines longer than 998 characters, or stray CRs, or NULs.
 
   @glossary @anchor Eight-Bit-Text @anchor eight-bit-text @b 8-bit-text:
-  Eight-bit data that contains a high percentage of non-ascii values.
+  Eight-bit data that contains a high percentage of ascii values,
+  no lines longer than 998 characters, no NULs, and either only LFs or
+  only CRLFs.
 
   @glossary @anchor Seven-Bit @anchor seven-bit @b 7-Bit:
-  Data that contains bytes with all values less than 128.
+  Data that contains bytes with all values less than 128, and no NULs.
 
   @glossary @anchor Seven-Bit-Binary @anchor seven-bit-binary @b 7-bit-binary:
-  Seven-bit data that contains a high percentage of non-ascii values.
+  Seven-bit data that contains a high percentage of non-ascii values,
+  or lines longer than 998 characters, or stray CRs.
 
   @glossary @anchor Seven-Bit-Text @anchor seven-bit-text @b 7-bit-text:
-  Seven-bit data that contains a high percentage of ascii values.
+  Seven-bit data that contains a high percentage of ascii values,
+  no lines longer than 998 characters, and either only LFs, or only CRLFs.
 */
 
 #ifndef __KMIME_CHARFREQ_H__
diff -pubNr /opt/kde-stable/include/kmime/kmime_codecs.h /opt/kde-trunk/include/kmime/kmime_codecs.h
--- /opt/kde-stable/include/kmime/kmime_codecs.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_codecs.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,6 +1,6 @@
 /*  -*- c++ -*-
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
 
     This library is free software; you can redistribute it and/or
@@ -164,10 +164,10 @@ class KMIME_EXPORT Codec
       QByteArray::Iterator iit = in.begin();
       QByteArray::Iterator oit = out.begin();
       if ( !codec->encode( iit, in.end(), oit, out.end() ) ) {
-        kDebug(5320) << "output buffer too small";
+        kDebug() << "output buffer too small";
         return;
       }
-      kDebug(5320) << "Size of encoded data:" << oit - out.begin();
+      kDebug() << "Size of encoded data:" << oit - out.begin();
       </pre>
 
       @param scursor is a pointer to the start of the input buffer.
@@ -202,10 +202,10 @@ class KMIME_EXPORT Codec
       QByteArray::Iterator iit = in.begin();
       QByteArray::Iterator oit = out.begin();
       if ( !codec->decode( iit, in.end(), oit, out.end() ) ) {
-        kDebug(5320) << "output buffer too small";
+        kDebug() << "output buffer too small";
         return;
       }
-      kDebug(5320) << "Size of decoded data:" << oit - out.begin();
+      kDebug() << "Size of decoded data:" << oit - out.begin();
       </pre>
 
       @param scursor is a pointer to the start of the input buffer.
diff -pubNr /opt/kde-stable/include/kmime/kmime_content.h /opt/kde-trunk/include/kmime/kmime_content.h
--- /opt/kde-stable/include/kmime/kmime_content.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_content.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,10 +1,11 @@
 /*
     kmime_content.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001 the KMime authors.
     See file AUTHORS for details
     Copyright (c) 2006 Volker Krause <vkrause@kde.org>
+    Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -40,6 +41,8 @@ TODO: possible glossary terms:
  attachment
  charset
  article
+ string representation
+ broken-down object representation
 */
 
 #ifndef __KMIME_CONTENT_H__
@@ -62,13 +65,32 @@ class ContentPrivate;
   @brief
   A class that encapsulates @ref MIME encoded Content.
 
-  It parses the given data and creates a tree-like structure that
-  represents the structure of the message.
+  A Content object holds two representations of a content:
+  - the string representation: This is the content encoded as a string ready
+    for transport.  Accessible through the encodedContent() method.
+  - the broken-down representation: This is the tree of objects (headers,
+    sub-Contents) that this Content is made of.  Accessible through methods
+    like header() and contents().
+  The parse() function updates the broken-down representation of the Content
+  from its string representation.  Calling it is necessary to access the
+  headers or sub-Contents of this Content.
+  The assemble() function updates the string representation of the Content
+  from its broken-down representation.  Calling it is necessary for
+  encodedContent() to reflect any changes made to the Content.
+*/
+/*
+  KDE5:
+  * Do not convert singlepart <-> multipart automatically.
+  * A bunch of methods probably don't need to be virtual (since they're not needed
+    in either Message or NewsArticle).
 */
 class KMIME_EXPORT Content
 {
   public:
 
+    /**
+      Describes a list of Content objects.
+    */
     typedef QList<KMime::Content*> List;
 
     /**
@@ -81,7 +103,7 @@ class KMIME_EXPORT Content
       @param parent the parent Content object
       @since 4.3
     */
-    explicit Content( Content* parent ); //TODO: Merge with the above
+    explicit Content( Content* parent ); // KDE5: Merge with the above.
 
     /**
       Creates a Content object containing the given raw data.
@@ -99,7 +121,8 @@ class KMIME_EXPORT Content
       @param parent the parent Content object
       @since 4.3
     */
-    Content( const QByteArray &head, const QByteArray &body, Content *parent ); //TODO: merge with the above
+    // KDE5: Merge with the above.
+    Content( const QByteArray &head, const QByteArray &body, Content *parent );
 
     /**
       Destroys this Content object.
@@ -115,6 +138,9 @@ class KMIME_EXPORT Content
       Sets the Content to the given raw data, containing the Content head and
       body separated by two linefeeds.
 
+      This method operates on the string representation of the Content. Call
+      parse() if you want to access individual headers or sub-Contents.
+
       @param l is a line-splitted list of the raw Content data.
     */
     void setContent( const QList<QByteArray> &l );
@@ -123,26 +149,78 @@ class KMIME_EXPORT Content
       Sets the Content to the given raw data, containing the Content head and
       body separated by two linefeeds.
 
+      This method operates on the string representation of the Content. Call
+      parse() if you want to access individual headers or sub-Contents.
+
       @param s is a QByteArray containing the raw Content data.
     */
     void setContent( const QByteArray &s );
 
     /**
-      Parses the Contents, splitting into multiple sub-Contents.
+      Parses the Content.
+      This means the broken-down object representation of the Content is
+      updated from the string representation of the Content.
+      Call this if you want to access or change headers or sub-Contents.
     */
     virtual void parse();
 
     /**
-      Call to generate the MIME structure of the message.
+      Returns whether this Content is frozen.
+      A frozen content is immutable, i.e. calling assemble() will never modify
+      its head or body, and encodedContent() will return the same data before
+      and after parsing.
+
+      @since 4.4.
+      @see setFrozen().
+    */
+    bool isFrozen() const;
+
+    /**
+      Freezes this Content if @p frozen is true; otherwise unfreezes it.
+
+      @since 4.4
+      @see isFrozen().
+    */
+    void setFrozen( bool frozen = true );
+
+    /**
+      Generates the MIME content.
+      This means the string representation of this Content is updated from the
+      broken-down object representation.
+      Call this if you have made changes to the content, and want
+      encodedContent() to reflect those changes.
+
+      @note assemble() has no effect if the Content isFrozen().  You may want
+      to freeze, for instance, signed sub-Contents, to make sure they are kept
+      unmodified.
+
+      @warning assemble() may change the order of the headers, and other
+      details such as where folding occurs.  This may break things like
+      signature verification, so you should *ONLY* call assemble() when you
+      have actually modified the content.
     */
     virtual void assemble();
 
     /**
-      Clears the complete message and deletes all sub-Contents.
+      Clears the content, deleting all headers and sub-Contents.
     */
+    // KDE5: make non-virtual.
     virtual void clear();
 
     /**
+      Removes all sub-Contents from this content.  Deletes them if @p del is true.
+      This is different from calling removeContent() on each sub-Content, because
+      removeContent() will convert this to a single-part Content if only one
+      sub-Content is left.  Calling clearContents() does NOT make this Content
+      single-part.
+
+      @param del Whether to delete the sub-Contents.
+      @see removeContent()
+      @since 4.4
+    */
+    void clearContents( bool del = true );
+
+    /**
       Returns the Content header raw data.
 
       @see setHead().
@@ -152,6 +230,9 @@ class KMIME_EXPORT Content
     /**
       Sets the Content header raw data.
 
+      This method operates on the string representation of the Content. Call
+      parse() if you want to access individual headers.
+
       @param head is a QByteArray containing the header data.
 
       @see head().
@@ -165,81 +246,141 @@ class KMIME_EXPORT Content
       @deprecated Use nextHeader( QByteArray )
       @param head is a QByteArray containing the header data.
     */
-
     KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
 
     /**
       Extracts and removes the next header from @p head.
       The caller is responsible for deleting the returned header.
       @since 4.2
+      @deprecated Use KMime::extractFirstHeader().
       @param head is a QByteArray containing the header data.
     */
-    Headers::Generic *nextHeader( QByteArray &head );
+    // KDE5: Remove this. This method has nothing to do with *this object.
+    KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
 
     /**
-      Tries to find a @p type header in the message and returns it.
+      Tries to find a @p type header in the Content and returns it.
       @deprecated Use headerByType( const char * )
     */
+    // KDE5: Make non-virtual.
     KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
 
     /**
-      Tries to find a @p type header in the message and returns it.
+      Returns the first header of type @p type, if it exists.  Otherwise returns 0.
+      Note that the returned header may be empty.
       @since 4.2
     */
+    // KDE5: Make non-virtual.
     virtual Headers::Base *headerByType( const char *type );
 
     /**
-      Tries to find all the @p type headers in the message and returns it.
+      Returns the first header of type T, if it exists.
+      If the header does not exist and @p create is true, creates an empty header
+      and returns it. Otherwise returns 0.
+      Note that the returned header may be empty.
+      @param create Whether to create the header if it does not exist.
+      @since 4.4.
+    */
+    template <typename T> T *header( bool create = false );
+
+    /**
+      Returns all @p type headers in the Content.
       Take care that this result is not cached, so could be slow.
       @since 4.2
     */
     virtual QList<Headers::Base*> headersByType( const char *type );
 
+    /**
+      Sets the specified header to this Content.
+      Any previous header of the same type is removed.
+      If you need multiple headers of the same type, use appendHeader() or
+      prependHeader().
+
+      @param h The header to set.
+      @see appendHeader()
+      @see removeHeader()
+      @since 4.4
+    */
+    // KDE5: make non-virtual.
     virtual void setHeader( Headers::Base *h );
 
+    /**
+      Appends the specified header to the headers of this Content.
+      @param h The header to append.
+      @since 4.4
+    */
+    void appendHeader( Headers::Base *h );
+
+    /**
+      Prepends the specified header to the headers of this Content.
+      @param h The header to prepend.
+      @since 4.4
+    */
+    void prependHeader( Headers::Base *h );
+
+    /**
+      Searches for the first header of type @p type, and deletes it, removing
+      it from this Content.
+      @param type The type of the header to look for.
+      @return true if a header was found and removed.
+    */
+    // TODO probably provide removeHeader<T>() too.
+    // KDE5: make non-virtual.
     virtual bool removeHeader( const char *type );
 
+    /**
+      @return true if this Content has a header of type @p type.
+      @param type The type of the header to look for.
+    */
+    // TODO probably provide hasHeader<T>() too.
     bool hasHeader( const char *type );
 
     /**
-      Returns the Content type header.
+      Returns the Content-Type header.
 
-      @param create if true, create the header if it doesn't exist yet.
+      @param create If true, create the header if it doesn't exist yet.
     */
-    Headers::ContentType *contentType( bool create=true );
+    Headers::ContentType *contentType( bool create = true );
 
     /**
-      Returns the Content transfer encoding.
+      Returns the Content-Transfer-Encoding header.
 
-      @param create if true, create the header if it doesn't exist yet.
+      @param create If true, create the header if it doesn't exist yet.
     */
-    Headers::ContentTransferEncoding *contentTransferEncoding( bool create=true );
+    Headers::ContentTransferEncoding *contentTransferEncoding( bool create = true );
 
     /**
-      Returns the Content disposition.
+      Returns the Content-Disposition header.
 
-      @param create if true, create the header if it doesn't exist yet.
+      @param create If true, create the header if it doesn't exist yet.
     */
-    Headers::ContentDisposition *contentDisposition( bool create=true );
+    Headers::ContentDisposition *contentDisposition( bool create = true );
 
     /**
-      Returns the Content description.
+      Returns the Content-Description header.
 
-      @param create if true, create the header if it doesn't exist yet.
+      @param create If true, create the header if it doesn't exist yet.
     */
-    Headers::ContentDescription *contentDescription( bool create=true );
+    Headers::ContentDescription *contentDescription( bool create = true );
 
     /**
-      Returns the Content location.
+      Returns the Content-Location header.
 
-      @param create if true, create the header if it doesn't exist yet.
+      @param create If true, create the header if it doesn't exist yet.
       @since 4.2
     */
-    Headers::ContentLocation *contentLocation( bool create=true );
+    Headers::ContentLocation *contentLocation( bool create = true );
 
+    /**
+      Returns the Content-ID header.
+      @param create if true, create the header if it does not exist yet.
+      @since 4.4
+    */
+    Headers::ContentID *contentID( bool create = true );
 
     /**
       Returns the size of the Content body after encoding.
+      (If the encoding is quoted-printable, this is only an approximate size.)
     */
     int size();
 
@@ -263,6 +404,9 @@ class KMIME_EXPORT Content
     /**
       Sets the Content body raw data.
 
+      This method operates on the string representation of the Content. Call
+      parse() if you want to access individual sub-Contents.
+
       @param body is a QByteArray containing the body data.
 
       @see body().
@@ -273,7 +417,7 @@ class KMIME_EXPORT Content
       Returns a QByteArray containing the encoded Content, including the
       Content header and all sub-Contents.
 
-      @param useCrLf if true, use @ref CRLF instead of @ref LF for linefeeds.
+      @param useCrLf If true, use @ref CRLF instead of @ref LF for linefeeds.
     */
     QByteArray encodedContent( bool useCrLf = false );
 
@@ -287,9 +431,9 @@ class KMIME_EXPORT Content
       applies charset decoding. If this is not a text Content, decodedText()
       returns an empty QString.
 
-      @param trimText if true, then the decoded text will have all trailing
+      @param trimText If true, then the decoded text will have all trailing
       whitespace removed.
-      @param removeTrailingNewlines if true, then the decoded text will have
+      @param removeTrailingNewlines If true, then the decoded text will have
       all consecutive trailing newlines removed.
 
       The last trailing new line of the decoded text is always removed.
@@ -313,7 +457,7 @@ class KMIME_EXPORT Content
     /**
       Returns a list of attachments.
 
-      @param incAlternatives if true, include multipart/alternative parts.
+      @param incAlternatives If true, include multipart/alternative parts.
     */
     List attachments( bool incAlternatives = false );
 
@@ -323,41 +467,63 @@ class KMIME_EXPORT Content
     List contents() const;
 
     /**
-      Adds a new sub-Content, the current Content object is converted into a
-      multipart/mixed Content node if it has been a single-part Content. If the sub-Content
-      is already in another Content object, it is removed from there and its parent is
-      updated.
+      Adds a new sub-Content. If the sub-Content is already part of another
+      Content object, it is removed from there and its parent is updated.
+      If the current Content object is single-part, it is converted to
+      multipart/mixed first.
+
+      @warning If the single-part to multipart conversion happens, all
+      pointers you may have into this object (such as headers) will become
+      invalid!
 
-      @param c The new sub-Content.
-      @param prepend if true, prepend to the Content list; else append
+      @param content The new sub-Content.
+      @param prepend If true, prepend to the Content list; otherwise append.
       to the Content list.
 
       @see removeContent().
     */
-    void addContent( Content *c, bool prepend = false );
+    // KDE5: Do not convert single-part->multipart automatically.
+    void addContent( Content *content, bool prepend = false );
 
     /**
-      Removes the given sub-Content, the current Content object is converted
-      into a single-port Content if only one sub-Content is left.
+      Removes the given sub-Content. If only one sub-Content is left, the
+      current Content object is converted into a single-part Content.
+
+      @warning If the multipart to single-part conversion happens, the head
+      and body of the single remaining sub-Content are copied over, and the
+      sub-Content is deleted.  All pointers to it or into it (such as headers)
+      will become invalid!
 
-      @param c The Content to remove.
-      @param del if true, delete the removed Content object. Otherwise its parent is set to NULL.
+      @param content The Content to remove.
+      @param del If true, delete the removed Content object. Otherwise set its
+      parent to 0.
 
       @see addContent().
+      @see clearContents().
     */
-    void removeContent( Content *c, bool del = false );
+    // KDE5: Do not convert multipart->single-part automatically.
+    void removeContent( Content *content, bool del = false );
+
+    /**
+      Changes the encoding of this Content to @p e.  If the Content is binary,
+      this actually re-encodes the data to use the new encoding.
 
+      @param e The new encoding to use.
+    */
     void changeEncoding( Headers::contentEncoding e );
 
     /**
       Saves the encoded Content to the given textstream
 
       @param ts is the stream where the Content should be written to.
-      @param scrambleFromLines: if true, replace "\nFrom " with "\n>From "
+      @param scrambleFromLines: If true, replace "\nFrom " with "\n>From "
       in the stream. This is needed to avoid problem with mbox-files
     */
     void toStream( QTextStream &ts, bool scrambleFromLines = false );
 
+    // NOTE: The charset methods below are accessed by the headers which
+    // have this Content as a parent.
+
     /**
       Returns the charset that is used for all headers and the body
       if the charset is not declared explictly.
@@ -388,7 +554,7 @@ class KMIME_EXPORT Content
       works correctly only when the article is completely empty or
       completely loaded.
 
-      @param b if true, force the default charset to be used.
+      @param b If true, force the default charset to be used.
 
       @see forceDefaultCharset().
     */
@@ -396,23 +562,23 @@ class KMIME_EXPORT Content
 
     /**
       Returns the Content specified by the given index.
-      If the index doesn't point to a Content, 0 is returned, if the index
+      If the index does not point to a Content, 0 is returned. If the index
       is invalid (empty), this Content is returned.
 
-      @param index the Content index
+      @param index The Content index.
     */
     Content *content( const ContentIndex &index ) const;
 
     /**
-      Returns the ContentIndex for the given Content, an invalid index
-      if the Content is not found withing the hierarchy.
+      Returns the ContentIndex for the given Content, or an invalid index
+      if the Content is not found within the hierarchy.
       @param content the Content object to search.
     */
     ContentIndex indexForContent( Content *content ) const;
 
     /**
-      Returns true if this is the top-level node in the MIME tree, ie. if this
-      is actually a message or news article.
+      Returns true if this is the top-level node in the MIME tree, i.e. if this
+      is actually a Message or NewsArticle.
     */
     virtual bool isTopLevel() const;
 
@@ -425,13 +591,13 @@ class KMIME_EXPORT Content
     void setParent( Content *parent );
 
     /**
-     * Returns the parent content object, or NULL if the content doesn't have a parent.
+     * Returns the parent content object, or 0 if the content doesn't have a parent.
      * @since 4.3
      */
     Content* parent() const;
 
     /**
-     * Returns the toplevel content object, NULL if there is no such object.
+     * Returns the toplevel content object, 0 if there is no such object.
      * @since 4.3
      */
     Content* topLevel() const;
@@ -450,11 +616,35 @@ class KMIME_EXPORT Content
     */
     virtual QByteArray assembleHeaders();
 
-    QByteArray rawHeader( const char *name ) const;
-    QList<QByteArray> rawHeaders( const char *name ) const;
+    /**
+      Returns the raw string representing the header of type @p name.
+      @deprecated Use KMime::extractHeader() directly instead.
+    */
+    KDE_DEPRECATED QByteArray rawHeader( const char *name ) const;
+
+    /**
+      Returns a list of raw strings representing all header of type @p name.
+      @deprecated Use KMime::extractHeaders() directly instead.
+    */
+    KDE_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
+
+    /**
+      Returns whether this object holds text content.
+    */
+    // KDE5: Not needed outside. Move to Private class.
     bool decodeText();
-    template <class T> T *headerInstance( T *ptr, bool create );
 
+    /**
+      Returns the first header of type T, if it exists.
+      @deprecated Use header() instead.
+    */
+    template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create );
+
+    /**
+      The list of headers in this Content.
+      Do not use this directly.
+    */
+    // KDE5: Not needed outside. Move to Private class.
     Headers::Base::List h_eaders;
 
     //@cond PRIVATE
@@ -472,15 +662,21 @@ class KMIME_EXPORT Content
 
 template <class T> T *Content::headerInstance( T *ptr, bool create )
 {
-  T dummy; //needed to access virtual member T::type()
+  return header<T>( create );
+}
 
-  ptr=static_cast <T*> ( headerByType( dummy.type() ) );
-  if ( !ptr && create ) { //no such header found, but we need one => create it
-    ptr = new T( this );
-    h_eaders.append( ptr );
+template <typename T> T *Content::header( bool create )
+{
+  T dummy;
+  Headers::Base *h = headerByType( dummy.type() );
+  if( h ) {
+    // Make sure the header is actually of the right type.
+    Q_ASSERT( dynamic_cast<T*>( h ) );
+  } else if( create ) {
+    h = new T( this );
+    setHeader( h );
   }
-
-  return ptr;
+  return static_cast<T*>( h );
 }
 
 } // namespace KMime
diff -pubNr /opt/kde-stable/include/kmime/kmime_dateformatter.h /opt/kde-trunk/include/kmime/kmime_dateformatter.h
--- /opt/kde-stable/include/kmime/kmime_dateformatter.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_dateformatter.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_dateformatter.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001 the KMime authors.
     See file AUTHORS for details
 
diff -pubNr /opt/kde-stable/include/kmime/kmime_headerfactory.h /opt/kde-trunk/include/kmime/kmime_headerfactory.h
--- /opt/kde-stable/include/kmime/kmime_headerfactory.h	1970-01-01 01:00:00.000000000 +0100
+++ /opt/kde-trunk/include/kmime/kmime_headerfactory.h	2009-10-09 09:21:24.000000000 +0200
@@ -0,0 +1,95 @@
+/*
+    kmime_header_factory.h
+
+    KMime, the KDE Internet mail/usenet news message library.
+    Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+/**
+  @file
+  This file is part of the API for handling @ref MIME data and
+  defines the HeaderFactory class.
+
+  @brief
+  Defines the HeaderFactory class.
+
+  @authors Constantin Berzan \<exit3219@gmail.com\>
+*/
+
+#ifndef __KMIME_HEADERFACTORY_H__
+#define __KMIME_HEADERFACTORY_H__
+
+#include "kmime_export.h"
+
+#include <QtCore/QByteArray>
+
+namespace KMime {
+
+namespace Headers {
+  class Base;
+}
+
+class HeaderMakerBase
+{
+  public:
+    virtual ~HeaderMakerBase() {}
+    virtual Headers::Base *create() const = 0;
+};
+
+template <typename T>
+class HeaderMaker : public HeaderMakerBase
+{
+  public:
+    virtual Headers::Base *create() const
+    {
+      return new T;
+    }
+};
+
+class HeaderFactoryPrivate;
+
+/**
+  docu TODO
+*/
+class KMIME_EXPORT HeaderFactory
+{
+  public:
+    static HeaderFactory* self();
+
+    template<typename T> inline bool registerHeader()
+    {
+      T dummy;
+      return registerHeaderMaker( QByteArray( dummy.type() ), new HeaderMaker<T>() );
+    }
+
+    Headers::Base *createHeader( const QByteArray &type );
+
+  private:
+    HeaderFactory( HeaderFactoryPrivate *dd );
+    HeaderFactory( const HeaderFactory &other ); // undefined
+    HeaderFactory& operator=( const HeaderFactory &other ); // undefined
+    ~HeaderFactory();
+
+    bool registerHeaderMaker( const QByteArray &type, HeaderMakerBase *maker );
+
+    friend class HeaderFactoryPrivate;
+    HeaderFactoryPrivate *const d;
+};
+
+} // namespace KMime
+
+#endif /* __KMIME_HEADERFACTORY_H__ */
diff -pubNr /opt/kde-stable/include/kmime/kmime_header_parsing.h /opt/kde-trunk/include/kmime/kmime_header_parsing.h
--- /opt/kde-stable/include/kmime/kmime_header_parsing.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_header_parsing.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_header_parsing.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
 
     This library is free software; you can redistribute it and/or
@@ -35,6 +35,10 @@ class QStringList;
 
 namespace KMime {
 
+namespace Headers {
+  class Base;
+}
+
 namespace Types {
 
 // for when we can't make up our mind what to use...
@@ -327,6 +331,10 @@ KMIME_EXPORT bool parseTime( const char*
 KMIME_EXPORT bool parseDateTime( const char* &scursor, const char * const send,
                                  KDateTime &result, bool isCRLF=false );
 
+KMIME_EXPORT KMime::Headers::Base *extractFirstHeader( QByteArray &head );
+
+KMIME_EXPORT QList<KMime::Headers::Base*> parseHeaders( const QByteArray &head );
+
 } // namespace HeaderParsing
 
 } // namespace KMime
diff -pubNr /opt/kde-stable/include/kmime/kmime_headers.h /opt/kde-trunk/include/kmime/kmime_headers.h
--- /opt/kde-stable/include/kmime/kmime_headers.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_headers.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_headers.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001-2002 the KMime authors.
     See file AUTHORS for details
     Copyright (c) 2006 Volker Krause <vkrause@kde.org>
@@ -68,20 +68,26 @@ enum contentCategory {
   CCalternativePart
 };
 
+/**
+  Various possible values for the "Content-Transfer-Encoding" header.
+*/
 enum contentEncoding {
-  CE7Bit,
-  CE8Bit,
-  CEquPr,
-  CEbase64,
-  CEuuenc,
-  CEbinary
+  CE7Bit,              ///< 7bit
+  CE8Bit,              ///< 8bit
+  CEquPr,              ///< quoted-printable
+  CEbase64,            ///< base64
+  CEuuenc,             ///< uuencode
+  CEbinary             ///< binary
 };
 
+/**
+  Various possible values for the "Content-Disposition" header.
+*/
 enum contentDisposition {
-  CDInvalid,
-  CDinline,
-  CDattachment,
-  CDparallel
+  CDInvalid,           ///< Default, invalid value
+  CDinline,            ///< inline
+  CDattachment,        ///< attachment
+  CDparallel           ///< parallel (invalid, do not use)
 };
 
 //often used charset
@@ -894,10 +900,23 @@ class KMIME_EXPORT ContentTransferEncodi
     */
     void setEncoding( contentEncoding e );
 
+    /**
+      Returns whether the Content containing this header is already decoded.
+    */
+    // KDE5: rename to isDecoded().
     bool decoded() const;
 
+    /**
+      Set whether the Content containing this header is already decoded.
+      For instance, if you fill your Content with already-encoded base64 data,
+      you will want to setDecoded( false ).
+    */
     void setDecoded( bool decoded = true );
 
+    /**
+      Returns whether the Content containing this header needs to be encoded
+      (i.e., if decoded() is true and encoding() is base64 or quoted-printable).
+    */
     bool needToEncode() const;
 
   protected:
diff -pubNr /opt/kde-stable/include/kmime/kmime_mdn.h /opt/kde-trunk/include/kmime/kmime_mdn.h
--- /opt/kde-stable/include/kmime/kmime_mdn.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_mdn.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_mdn.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2002 Marc Mutz <mutz@kde.org>
 
     This library is free software; you can redistribute it and/or
diff -pubNr /opt/kde-stable/include/kmime/kmime_message.h /opt/kde-trunk/include/kmime/kmime_message.h
--- /opt/kde-stable/include/kmime/kmime_message.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_message.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*
     kmime_message.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001 the KMime authors.
     See file AUTHORS for details
 
@@ -52,39 +52,114 @@ class KMIME_EXPORT Message : public Cont
     */
     typedef boost::shared_ptr<Message> Ptr;
 
-    /** Constructor. Creates an empty message. */
+    /**
+      Creates an empty Message.
+    */
     Message();
+
+    /**
+      Destroys this Message.
+    */
     ~Message();
 
-    //content handling
+    /* reimpl */
     virtual void parse();
+
+    /* reimpl */
     virtual void clear();
 
-    //header access
-    /** @deprecated Use headerByType( const char * ) */
+    /* reimpl */
     virtual KDE_DEPRECATED KMime::Headers::Base *getHeaderByType( const char *type );
-    /** @since 4.2 */
+
+    /* reimpl */
     virtual KMime::Headers::Base *headerByType( const char *type );
+
+    /* reimpl */
     virtual void setHeader( KMime::Headers::Base *h );
+
+    /* reimpl */
     virtual bool removeHeader( const char *type );
 
+    // KDE5: Why are these virtual?
     /**
-      Returns the message MessageID
+      Returns the Message-ID header.
+      @param create If true, create the header if it doesn't exist yet.
     */
     virtual KMime::Headers::MessageID *messageID( bool create = true );
+
+    /**
+      Returns the Subject header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Subject *subject( bool create = true );
+
+    /**
+      Returns the Date header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Date *date( bool create = true );
+
+    /**
+      Returns the From header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::From *from( bool create = true );
+
+    /**
+      Returns the Organization header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Organization *organization( bool create = true );
+
+    /**
+      Returns the Reply-To header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::ReplyTo *replyTo( bool create = true );
+
+    /**
+      Returns the To header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::To *to( bool create = true );
+
+    /**
+      Returns the Cc header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Cc *cc( bool create = true );
+
+    /**
+      Returns the Bcc header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Bcc *bcc( bool create = true );
+
+    /**
+      Returns the References header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::References *references( bool create = true );
+
+    /**
+      Returns the User-Agent header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::UserAgent *userAgent( bool create = true );
+
+    /**
+      Returns the In-Reply-To header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::InReplyTo *inReplyTo( bool create = true );
+
+    /**
+      Returns the Sender header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Sender *sender( bool create = true );
 
+    /* reimpl */
     virtual bool isTopLevel() const;
 
     /**
@@ -99,6 +174,7 @@ class KMIME_EXPORT Message : public Cont
     Content* mainBodyPart( const QByteArray &type = QByteArray() );
 
   protected:
+    /* reimpl */
     virtual QByteArray assembleHeaders();
 
     // @cond PRIVATE
diff -pubNr /opt/kde-stable/include/kmime/kmime_newsarticle.h /opt/kde-trunk/include/kmime/kmime_newsarticle.h
--- /opt/kde-stable/include/kmime/kmime_newsarticle.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_newsarticle.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*
     kmime_newsarticle.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001 the KMime authors.
     See file AUTHORS for details
 
@@ -39,27 +39,72 @@ class KMIME_EXPORT NewsArticle : public 
     */
     typedef boost::shared_ptr<NewsArticle> Ptr;
 
+    /**
+      Creates a NewsArticle object.
+    */
     NewsArticle();
+
+    /**
+      Destroys this NewsArticle.
+    */
     ~NewsArticle();
 
+    /* reimpl */
     virtual void parse();
+
+    /* reimpl */
     virtual void clear();
 
-    /** @deprecated use headerByType( const char * ) */
+    /* reimpl */
     virtual KDE_DEPRECATED KMime::Headers::Base * getHeaderByType( const char *type );
-    /** @since 4.2 */
+
+    /* reimpl */
     virtual KMime::Headers::Base * headerByType( const char *type );
+
+    /* reimpl */
     virtual void setHeader( KMime::Headers::Base *h );
+
+    /* reimpl */
     virtual bool removeHeader( const char *type );
 
+    /**
+      Returns the Control header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Control *control( bool create = true );
+
+    /**
+      Returns the Supersedes header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Supersedes *supersedes( bool create = true );
+
+    /**
+      Returns the Mail-Copies-To header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::MailCopiesTo *mailCopiesTo( bool create = true );
+
+    /**
+      Returns the Newsgroups header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Newsgroups *newsgroups( bool create = true );
+
+    /**
+      Returns the Follow-Up-To header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::FollowUpTo *followUpTo( bool create = true );
+
+    /**
+      Returns the Lines header.
+      @param create If true, create the header if it doesn't exist yet.
+    */
     virtual KMime::Headers::Lines *lines( bool create = true );
 
   protected:
+    /* reimpl */
     virtual QByteArray assembleHeaders();
 
   private:
diff -pubNr /opt/kde-stable/include/kmime/kmime_util.h /opt/kde-trunk/include/kmime/kmime_util.h
--- /opt/kde-stable/include/kmime/kmime_util.h	2009-10-12 18:31:46.000000000 +0200
+++ /opt/kde-trunk/include/kmime/kmime_util.h	2009-10-09 09:21:24.000000000 +0200
@@ -1,7 +1,7 @@
 /*  -*- c++ -*-
     kmime_util.h
 
-    KMime, the KDE internet mail/usenet news message library.
+    KMime, the KDE Internet mail/usenet news message library.
     Copyright (c) 2001 the KMime authors.
     See file AUTHORS for details
 
@@ -25,6 +25,7 @@
 
 #include <QtCore/QString>
 #include "kmime_export.h"
+#include "kmime_headers.h"
 
 namespace KMime {
 
@@ -48,6 +49,19 @@ KMIME_EXPORT extern QByteArray cachedLan
 */
 KMIME_EXPORT extern bool isUsAscii( const QString &s );
 
+/**
+  Returns a user-visible string for a contentEncoding, for example
+  "quoted-printable" for CEquPr.
+  TODO should they be i18n'ed?
+*/
+KMIME_EXPORT extern QString nameForEncoding( KMime::Headers::contentEncoding enc );
+
+/**
+  Returns a list of encodings that can correctly encode the @p data.
+  @author Based on KMail code by Thomas McGuire <mcguire@kde.org>
+*/
+KMIME_EXPORT QList<KMime::Headers::contentEncoding> encodingsForData(
+                                                       const QByteArray &data );
 //@cond PRIVATE
 extern const uchar specialsMap[16];
 extern const uchar tSpecialsMap[16];
