Example #1
0
KMime::Message::Ptr readMimeFile( const QString &fileName )
{
    QFile file( fileName );
    file.open( QFile::ReadOnly );
    const QByteArray data = file.readAll();
    Q_ASSERT( !data.isEmpty() );
    
    KMime::Message *msg = new KMime::Message;
    msg->setContent( data );
    msg->parse();
    return KMime::Message::Ptr(msg);
}
void KOEditorAttachments::addDataAttachment( const QByteArray &data,
                                             const QString &mimeType,
                                             const QString &label )
{
  AttachmentIconItem *item = new AttachmentIconItem( 0, mAttachments );

  QString nlabel = label;
  if ( mimeType == "message/rfc822" ) {
    // mail message. try to set the label from the mail Subject:
    KMime::Message msg;
    msg.setContent( data );
    msg.parse();
    nlabel = msg.subject()->asUnicodeString();
  }

  item->setData( data );
  item->setLabel( nlabel );
  if ( mimeType.isEmpty() ) {
    item->setMimeType( KMimeType::findByContent( data )->name() );
  } else {
    item->setMimeType( mimeType );
  }
}