[Kde-pim] retrieving a resource from an akonadi:/ url

Kevin Krammer krammer at kde.org
Sun Jul 3 12:53:48 BST 2016


On Saturday, 2016-07-02, 18:55:25, Jos van den Oever wrote:
> On Saturday 02 July 2016 12:55:44 Kevin Krammer wrote:
> > On Tuesday, 2016-06-28, 15:14:51, Daniel Vrátil wrote:
> > > On Tuesday, June 28, 2016 10:54:15 AM CEST Jos van den Oever wrote:
> > > > Hi all,
> > > > 
> > > > I'm writing a simple application on which I'd like to drop emails.
> > > > Dropping
> > > > mails from kmail gives an akonadi:/ url. How can I talk to akonadi to
> > > > get
> > > > the actual raw mail? The mails are all in maildir, so getting the file
> > > > path
> > > > would be fine too.
> > > 
> > > Hi,
> > > 
> > > you have two options. You can use the Akonadi KIO slave that is part of
> > > kdepim-runtime to get the email - just pass the URL to KIO::get(), that
> > > should work. Alternatively you can use Akonadi directly. The URL is
> > > something like akonadi://?id=1234, so you use Akonadi::ItemFetchJob to
> > > retrieve an Akonadi::Item  with that ID.
> > 
> > Akonadi::Item can even be initialized with such an URL, i.e. no need to
> > parse this manually.
> > 
> > Item::fromUrl() if I remember correctly.
> 
> That's the one. It accepts a KUrl. I'm using it like this:
> 
> ```cpp
> void DropSite::handleAkonadiUrls(const QList<QUrl>& urls)
> {
>     Akonadi::Item::List list;
>     list.reserve(urls.size());
>     for (auto& url: urls) {
>         if (url.scheme() == QLatin1String("akonadi")) {
>             list.append(Akonadi::Item::fromUrl(KUrl(url)));

Alternatively to checking the scheme() you could also just pass the URL to 
fromUrl() and then check "Item::isValid", i.e. let Item decide if the URL is 
applicable.

> I've written function createMailDirPath (see attachment) to obtain the file
> path from the concatenated Akonadi::Item::remoteId() values.
> This works great. I'm doing this instead of using the raw data from akonadi
> because I noticed that the bytearray returned from akonadi is not exactly
> the same as the contents of the file in the maildir.

This is actually interesting, fetching the full payload should just fetch the 
mail.
Even if the parsing and serialization that happens in the resource somehow 
modifies the content, it should always be the same modification, i.e. fetching 
the same mail should always result in the same byte array.

Are those mails stored through Akonadi or is a different process creating the 
file inside the maildir tree?

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20160703/8b939a94/attachment.sig>
-------------- 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