Bug 121844 - Retrieve message headers and content via DBUS interface
Summary: Retrieve message headers and content via DBUS interface
Status: CONFIRMED
Alias: None
Product: kmail2
Classification: Applications
Component: general (show other bugs)
Version: 5.5.1
Platform: Compiled Sources Linux
: HI wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-12 19:54 UTC by Kovid Goyal
Modified: 2017-09-05 03:54 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
A patch that adds a method unreadMessageHeaders() to FolderIface (1.16 KB, patch)
2006-02-23 00:37 UTC, Kovid Goyal
Details
An expanded DCOP interface that allows for the fetching of unread messages as well (4.23 KB, patch)
2006-02-24 00:33 UTC, Kovid Goyal
Details
BASH script demonstarting how to use the interface to get message body (262 bytes, application/x-shellscript)
2006-02-24 00:36 UTC, Kovid Goyal
Details
Patch against TRUNK (4.23 KB, patch)
2006-03-08 22:39 UTC, Kovid Goyal
Details
DCOP interface patch against KDE4 kmail (4.33 KB, patch)
2006-05-20 20:24 UTC, Kovid Goyal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kovid Goyal 2006-02-12 19:54:19 UTC
Version:            (using KDE KDE 3.5.1)
Installed from:    Compiled From Sources
OS:                Linux

I would like to be able to access the actual messages in KMail folders via the DCOP interface. There is a function to do this in FolderIface.cpp, but it is commented out, I think because the message references become invalid if the folder is changed. 

Thanks,

Kovid.
Comment 1 Kovid Goyal 2006-02-23 00:37:36 UTC
Created attachment 14817 [details]
A patch that adds a method unreadMessageHeaders() to FolderIface

unreadMessageHeaders() returns the From, Subject and Date fields (separated by
the # character) for each unread message in this folder. Since it uses
getMsgBase(), it should be fast.
Comment 2 Nicolas Dumoulin 2006-02-23 09:48:11 UTC
*** This bug has been confirmed by popular vote. ***
Comment 3 Teemu Rytilahti 2006-02-23 16:04:57 UTC
How about if the subject contains "#"? I think you should at least use another delimiter for this.
Comment 4 Kovid Goyal 2006-02-23 16:45:15 UTC
Well, since there are only 3 fields, the first and last are guaranteed to be From and Date, all the middle fields will then be subject. However, if you know of some printable character that is guaranteed to never be in the subject, I can easily make that change. The reason it needs to be a printable character is so that the output of the dcop commandline client also makes sense. 

Another alternative is to delimit the fields by substrings, rather than single characters, but that make parsing of the output in a script unnecessarily difficult IMO.  
Comment 5 Carl 2006-02-23 17:47:42 UTC
A few questions.  It doesn't look like it leaves out unread messages in the Trash folder.  It should if it does not.  Also, is it possible to get the body of the message given the parameters that this function returns?  Even more, is it possible to specify a certain folder and only display the unread messages of that folder?  That would be extremely helpful with scripting.
Comment 6 Kovid Goyal 2006-02-23 18:04:52 UTC
The way this works is, forex, with the commandline client
dcop $(dcop kmail KMailIface getFolder /Local/inbox) unreadMessageHeaders

This will return the headers for unread messages in /Local/inbox. If you don't want messages in Trash, just don't call it on the Trash folder. 

I could add a field that gives the message index, which could then be used with another (to be written dcop method) to fetch the body of the message, but the reason I wrote this patch, is that I am developing a mail ticker with SuperKaramba that lists unread mails in a user-specified set of folders. Fetching headers is fast as kmail stores them locally, however, for a remote (IMAP) mailbox, it would have to download the message body. 

I cansee, however, that in some situations getting the message body may be useful. I'll modify the patch to add the message index to the returned fields as well and upload it soon. I'll also have to add a function to get the message body by index.    
Comment 7 Carl 2006-02-23 19:06:08 UTC
Cool thanks.  Here's what I'm working on.  I'm writing a perl script that gets the  unread messages of a specific folder, Security in my case, and text messages my cell phone with that security message.  That way, if a security issue ever arises, I am immediately notified.  This dcop interface will be perfect for my script.  Thanks again.
Comment 8 Kovid Goyal 2006-02-24 00:33:25 UTC
Created attachment 14839 [details]
An expanded DCOP interface that allows for the fetching of unread messages as well

Changed unreadMessageHeaders to return fields in the format
index#from#date#subject.
Added 4 new functions:
1) touch( index): Marks message as read
2) requestMessageText( index ): Starts ASYNC loading of message body
3) isMessageTextAvailable( index ): ASYNC loading completed?
4) messageText( index ): return the body (text/plain, text/html) parts of the
email as plain text

There is some documentation on these functions in the patch. I will also upload
a test script demonstrating how to use them with the dcop commandline client.
Comment 9 Kovid Goyal 2006-02-24 00:36:03 UTC
Created attachment 14841 [details]
BASH script demonstarting how to use the interface to get message body

Edit the script and change the folder and message variables to suit your kmail.
Comment 10 Ismail Onur Filiz 2006-03-08 20:38:49 UTC
Thank you Kovid for your contribution. KDE is in feature freeze for the 3.5 branch, so this feature cannot be added to KDE 3.5.2, though. Would you like to port your patch to trunk ( future 4.0, trunk/KDE/kdepim/kmail in the SVN server ) so that it appears in the next major release?
Comment 11 Matthias Wieser 2006-03-08 21:03:52 UTC
> KDE is in feature freeze for the 3.5 branch,

Yes, but... :-)
KDE 4 is far away. Can this patch introduce any serious regressions?

Additionally KDE 3.5 is a very long living branch and many people would be happy to see this patch in KDE 3.5.2 or KDE 3.5.3
Comment 12 Ismail Onur Filiz 2006-03-08 21:30:34 UTC
> KDE 4 is far away. Can this patch introduce any serious regressions? 

It is a KDE-wide regulation. In any case, maintainers would be more authorized to comment about it.

Furthermore, you are always welcome to patch the software yourself, that way you can help the original author of the patch to improve/debug his patch through feedbacks too. Alternatively, you can ask your distribution's maintainers to incorporate this patch into their packages.
Comment 13 Kovid Goyal 2006-03-08 22:39:46 UTC
Created attachment 15015 [details]
Patch against TRUNK

Patched against trunk. I can't actually test the patch in KDE4 as I don't have
a working kde4 environment at the moment.
Comment 14 Kovid Goyal 2006-05-20 20:24:26 UTC
Created attachment 16187 [details]
DCOP interface patch against KDE4 kmail

I have migrated the patch to KDE4. It is tested against kmail from HEAD. Works
well for me. Can this be included now?

Thanks,

Kovid.
Comment 15 Anne-Marie Mahfouf 2011-11-30 15:02:26 UTC
Re-assigning to KMail2. Not sure this can be done rightnow with dbus which took over DCOP in KDE 4.
Comment 16 Denis Kurz 2017-05-19 10:43:48 UTC
Afaict, in PIM 5.5.1, retrieving messages via DBUS is still not implemented. Maybe I was just unable to find it. I searched the interfaces of kmail, Akonadi's NewMailNotifierAgent, and some Akonadi IMAP resources. It also seems that KFolderIFace didn't make the transition from DCOP to DBUS, and getting the number of (unread) messages in a folder is now impossible, too.