[Kde-pim] Attachments
Tom Albers
tomalbers at kde.nl
Sat Jun 28 11:50:18 BST 2008
Op zaterdag 28 juni 2008 03:26 schreef u:
> Hello list,
>
> I'm the GSoC student currently working on the openchange resource for
> akonadi. I've been reading kdepim api docs in search for the best way to attach
> file attachments to a KMIME::Message without any success. I was wondering if
> anyone here could point me to the right direction.
Sure,
Rougly you can do it like this:
Message *newMessage = new Message();
newMessage->contentType()->setMimeType( "multipart/mixed" );
newMessage->contentType()->setBoundary( KMime::multiPartBoundary() );
KUrl url( "/etc/passwd" );
QFile file( url.path() );
if ( file.open( QIODevice::ReadOnly ) ) {
QByteArray data = file.readAll();
file.close();
// convert to base64
QByteArray final = KCodecs::base64Encode( data, true );
// Add this part
Content* c = new Content();
c->setBody( final+"\n\n" ); // yeah the \n\n is a bug, so don't forget it.
// Add a content type / find mime-type
KMimeType::Ptr type = KMimeType::findByUrl( url );
KMime::Headers::ContentType *ctt= new KMime::Headers::ContentType( c );
ctt->fromUnicodeString( type->name(),encoding( type->name() ) );
ctt->setName( "AllYourPasswords.txt", "" );
c->setHeader( ctt );
// Set the encoding.
KMime::Headers::ContentTransferEncoding *cte=
new KMime::Headers::ContentTransferEncoding( c );
cte->setEncoding( KMime::Headers::CEbase64 );
cte->setDecoded( false );
c->setHeader( cte );
c->assemble();
newMessage->addContent( c );
}
If you need more code, just steal it from:
http://websvn.kde.org/trunk/extragear/pim/mailody/src/sendmessage.cpp?revision=815864&view=markup
Toma
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list