Esempio n. 1
0
QByteArray MBoxPrivate::mboxMessageSeparator( const QByteArray &msg )
{
  KMime::Message mail;
  QByteArray body, header;
  KMime::HeaderParsing::extractHeaderAndBody( KMime::CRLFtoLF( msg ), header, body );
  body.clear();
  mail.setHead( header );
  mail.parse();

  QByteArray separator = "From ";

  KMime::Headers::From *from = mail.from( false );
  if ( !from || from->addresses().isEmpty() ) {
    separator += "*****@*****.**";
  } else {
    separator += from->addresses().first() + ' ';
  }

  KMime::Headers::Date *date = mail.date( false );
  if ( !date || date->isEmpty() ) {
    separator += QDateTime::currentDateTime().toString( Qt::TextDate ).toUtf8() + '\n';
  } else {
    separator += date->as7BitString( false ) + '\n';
  }

  return separator;
}
Esempio n. 2
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 );
  }
}