I3/mutt/offlineimap with decent mail notifications

Today I’ll show you my last trick to get decent email notifications on my I3 environment, without using anything else than offlineimap and mutt. Ok, there’s something else, a couple of scripts but nothing scary.

Before going further, I’d like to ensure you’re using i3blocks. If not, then please configure it then come back and read on.

Until today I was using the classical offlineimap configuration which polled my IMAP server every several minutes directed from a crontab. However, that method has several drawbacks:
– lack of instant mail delivery
– offlineimap would occasionally get stuck upon wifi issues.

Investigating these problems, I found this: https://blog.mister-muffin.de/archive/2013/06/1/

That script was a very good starting point for what follows. So here is the setup:

  • the script ~/bin/mail-check.sh is launched upon I3 session start
    • it calls mail-idle.py which would either return a timeout or a string containing the name of the offlineimap account name that has mail, and the folder name
    • it handles the timeouts itself so if mail-idle.py or offlineimap gets stuck for some reason, they get killed
    • when new mail is found, it uses notify-send,  then calls offlineimap to retrieve the mail from the specified folder and it updates i3blocks
    • finally, it calls notmuch to get the new mail indexed

Put this script in ~/bin/mail-check.sh.
chmod +x ~/bin/mail-check.sh

Then save this script as ~/bin/mail-idle.py. Modify lines 25..27 to suit your configuration. Beware that you should use the same values as in your ~/.offlineimaprc file, if not the scripts will not correctly invoke offlineimap.
chmod +x ~/bin/mail-idle.py

Get the i3blocks blocklet command from here and save it to ~/.config/i3blocks/mail_status.sh. Then adjust it on line 2 to get it inspect your local mailboxes. Also, adjust line 6 if the directory containing your mails is not ~/Mail.
chmod +x ~/.config/i3blocks/mail_status.sh

Activate the blocklet into ~/.config/i3blocks/config:

command= ~/.config/i3blocks/mail_status.sh

As you may have noticed, the blocklet will be updated by the other parts of the system using this command:
pkill -SIGRTMIN+12 i3blocks

Hang-on, we’re almost done! 😉

Get the tool activated upon I3 session start by adding this to ~/.config/i3/config:
exec --no-startup-id ~/bin/mail-check.sh &

Stop your current mail retrieval scripts and then restart your I3 session. You should now start having notifications upon new mail arrival. That is, when some of the IMAP folders supervised by mail-idle.py get mail, then you should see a dunst (or whatever you use) notification, and the i3blocket should become red, displaying the offlineimap account name containing new mails, with their count.

Last step is getting mutt update the i3blocket upon mail reading. Just add this macro somewhere in your ~/.muttrc:
macro index <F5> "<sync-mailbox>:set wait_key=no\n!pkill -SIGRTMIN+12 i3blocks^M"

Restart mutt and use F5 to sync your maildir and eventually clear the i3blocklet when no unread mail is left.

Posted in i3

KWallet needs a serious face-lift ; enter KSecret Service

Users are often confused by the current KWallet system behavior. When their computers start, they enter the KDE session password but just after logging-in, they are prompted yet another password, for something named KWallet. Sometimes, they even see several password prompts from KWallet, depending on their precise desktop configuration.

Some users find that annoying and they file bug reports or, even worse, simply uncheck the “Enable the KDE wallet subsystem” in an attempt to deactivate it as a whole and switch to using some other external tools. Well, these tools are OK, but the KDE experience is affected, as the applications are no longer able to correctly store and retrieve their secrets. And that raises the barrier to entry for some of our potential users, adding negative points against KDE.

The remaining users have now several devices and would like to have their passwords synchronized all over these devices. They won’t find this kind of function and they’ll start using some other external tools, providing cross-device synchronization. That’s another bad point for the KDE experience.

Finally, more advanced users would like to know where their wallet data is stored and they would like to be able to put their wallets in some places of their choice, perhaps in an owncloud synchronized directory.

Enter KSecret Service!

The KDE Wallet system has some design flaws (I’ll write more on that in the future, but right now my post risk to get too long) affecting the security and should be replaced ASAP. Back in 2008 and until or 2011 an initiative was taken by the former KDE Wallet maintainer Michael Leupold and Stef Walter from GNOME to create a Freedesktop.org interface aiming to replace it. It’s called “Secret Service” and the draft may be found here: http://standards.freedesktop.org/secret-service/

This interface is already implemented by GNOME keyring and AFAICT KDE should also implement this interface if it wanted to enhance users experience.

All these points will be addressed by a new system, aiming to replace KWallet. It’s name is already known – KSecret Service.

I’m in the process of (re)defining it’s architecture and I’ll post it, for feedback, on the KDE developer mailing list as soon as I’ll get something stable enough. I cannot tell more right now – the post is already long enough – but it’s an ambitious plan! And I’m sure you’ll like it!

Scripting addicts, check the new kwallet-query tool!

This weekend I created a new kwallet tool, named kwallet-query. It now lives in playground/utils for you to try it up. Just issue “kwallet-query –help” after building it to see the available options.

qwallet-query sports two modes: list mode and read value mode. You should specify the mode when invoking the tool, along with the wallet name you want the tool to read. I’d also be glad to hear back from you as to what this tool should provide in addition to this. This initial version will work on KF5-based systems. Should I also add support for the legacy KDE4 wallet?

You may find this tool handy when reading the wallet from other places. For instance, I wanted to create this tool in order to get my passwords from my wallet by using dmenu on my I3WM-enabled KDE session.

For those interested about the dmenu integration thing, have a look at this: https://github.com/valir/kwallet-dmenu. It’s a little script that uses the new kwallet-query tool in two phases. First, it’ll send the list of folders you have in the Passwords section of the wallet. It’ll feed the list to dmenu who’ll invite you to select the folder you want to read. A second invocation will read the folder you choose from the wallet and once again will feed dmenu to let you choose one entry, corresponding to one line in the password stored in the kwallet. The selected entry will be pu into the clipboard, so you’ll only have to press Shift+Insert into the application where you where, without further workflow break. No more kwalletmanager visiting to copy/paste your secrets items!

Once again, I’m looking forward for your feeback (bug reports or even comments here). I plan to get this tool through the kdereview process about one month from now.

Connecting mutt to corporate MS Exchange

Last year I finally had the opportunity to install and use Linux at my work. The background of this change is out of the scope of this posting, I can only tell you that I was waiting for it since the very beginning. So I’m a happy Fedora user since a little more than an year, at my work (at home I’m using Linux since 2003 I think – ArchLinux currently).

Working with Linux is quite interesting and productive if you one uses the right tools. That’s why I also configured http://i3wm.org/ and a whole bunch of text mode tools, mainly vim plugins (know YouCompleteMe?), but also the Ranger file manager. However, our company uses MS Exchange *without* the IMAP connector and that’s quite a problem, because it interfaces only with MS Outlook or Evolution. MS Outlook has to run under Windows, so I used a virtual machine for this, eating 1 GB of RAM. Evolution runs natively, but it also eats more than 1GB only to present me the mails or some reminders. That’s a serious problem when one uses other very memory-intensive tools like Eclipse, IntelliJ or Oracle SQL Developer, not to mention Maven or DB Solo. So I really needed a solution to reduce my working session’s footprint, to get the most out of my workstation’s 8 Gb of RAM. Some coworkers are using Citrix sessions for that, but that has the mail/workstation integration problem.

Enter davmail. This awesome little project solved a problem several of us have at work: interface an IMAP client with our corporate server. DavMail need a very minimalist configuration. It almost worked out of the box, not considering the need to enter the company’s OWA URL. Once started, I instantly got IMAP and CalDAV. It also provides iCal and CardDAV but I don’t use these so I don’t know how it works. So, I’m now using mutt to handle corporate mails, interface it with lbdb and our LDAP server. \o/

The calendar is handled with khal but I also use remind. This part needs some more work, as I still need to figure out how to create appointments on my machine, then get them synchronized to the corporate server.

Should I write a tutorial with the steps I done so far? Let me know and I’ll do it if you’re interested.

I was in Brno!

This year Akademy’s timing was just perfectly adjusted with my annual vacation timing. For personal reasons, I only could go vacationing in September. Brno is right on the way from Lyon to Romania, so I decided to take my car and make a stop there. My girl-friend was kind enough to accept spending some time alone in Brno, while I was attending the second day. I’d like to thank her really much for accepting this. Sure enough, I would have liked to attend the first day also, but I used that full day to drive from Lyon to Brno. And BTW, speaking about driving in Europe, I’m now writing this in Cluj-Napoca. So I have behind me highways from France, Germany, Czech Republic, Slovakia, Hungary and Romania. Sygic GPS navigation software allowed me a smooth ride along this long road, as it features offline maps. And where I had data connection, I used WAZE for it’s social features.

This second Akademy day was the moment for me to catch up a little with several KDE great people I know, and with whom I’d really like to spend some more time. The location in Brno is outstanding, and the event was perfectly setup. Second day presentations brought my attention to several things:
– The Jungle project,
– KDE & Android,
– Accessibility.

The Jungle project, brilliantly presented by Alex Fiestas, it’s quite impressive. It aims unifying several multimedia services like youtube and your local media library. The promise is great, as you’ll be able to start watching your favourite videos on your Android device, then continue it on your KDE Desktop, and forth. I’ll really keep an eye on this project and hope it’ll add support for Facebook and Google+ sharing in a future release.

KDE & Android was featured in two presentations. The first one was about the KDE Connect project. I already use this project and I’m already working on an MPRIS widget for the Android device. Hopefully I’ll get enough time to take into account the feedback I got from the review request I already submitted. I also plan to add some kind of KWallet or secrets support. Alex told me that it’ll be nice if we could send passwords from the KDE Desktop to the Android device. However, that’ll not answer to my personal need, as I’d like to have a real sync between my device and my wallet.

The second KDE & Android topic was launched by Aleix Pol Gonzalez. It’s about an attempt to bring some KDE applications to the Android world. That’s an awesome project and I’ll take a closer look to this and keep you posted.

Finally, Frederik Gladhorn brought-up the accessibility topic and showed as the current progress of the accessibility features in Qt and so KDE. This is a very important topic, and I really hope people with disabilities would benefit this technology. I remember that around 10 years ago I’ve met someone who lost his view after an accident. He needed a braille display and at that time I understood the accessibility is really inaccessible (pun intended) to these people, mainly for material reasons. The price tag of accessible computers is really high and hopefully free desktops like KDE will help these people in their day to day activities.

So, KDE will bring us plenty of new and exciting features!

KWallet for Plasma 5 now automatically migrates KDE4 wallets!

Next time you’ll start your updated Plasma 5 session’s KDE Wallet system, it’ll eventually start migrating your wallets. The precondition is that you’re doing that on a system that also has KDE4 and that you previously used that installation’s KDE Wallet system. If your system doesn’t have a KDE4 wallet daemon, then nothing will happen.

Simply follow the instructions of the wizard that’ll popup. If you accept the migration option, then for each of your existing KDE4 wallet you’ll be :
– prompted with a new Plasma 5 wallet creation wizard – that’ll eventually be the moment to switch to GPG wallets 😉
– eventually prompted for the old wallet’s password, it the old daemon didn’t had it already opened by some other KDE4 program.
The migration assistant will preserve wallet names and wallet internal structure.

As usual, do not hesitate to file bug reports if you encounter any problem!

A final note about those who installed KDE4 in a prefix that’s not /usr. Please ‘ln -s [your kwalletd location] /usr/bin/kwalletd’ in order to let the migration agent correctly find and start the KDE4 daemon. Without that, it’ll not trigger the migration. (yes, that’s a quick hack, but it works).

Starting KF5 using the I3 window manager

Lately I started experimenting several tiling window managers, and I settled on I3 (see its Official site and the corresponding ArchLinux wiki page)

I now plan to return hacking KF5 and I’d like to use this tiling manager. In KDE4 I simply used the “Default Applications” control module from “System Settings” to choose i3, after adding the right i3.desktop file. However, with KF5 that will not be enough. For some reason kwin will still be loaded. (And BTW, the new kwin looks really great. I also like the new plasma desktop very much, but it won’t fit my workflow, as I prefer tiling WMs paradigm) Today I started searching a quick way to workaround that and here it is what I did.

Firstly, create the $KF5/share/ksmserver/windowmanagers/i3.desktop file with this contents:

[Desktop Entry]
Comment=Highly configurable framework window manager

Then edit the file ~/.config/ksmserverrc and modify the windowManager line from the [General] section:

# other lines ommited

Alternatively, you can use the “Default Applications” control module from KF5 System Settings to change the window manager to i3.

Finally, here is the little bit that made it. Modify the KF5 startup script to define the KDEWM environment variable. It should read like this:
export KDEWM=/usr/bin/i3

Here is how:
On my system, I’m using kdm. For it to start a KF5 session, I created /usr/share/config/kdm/sessions/kf5.desktop with this contents:

[Desktop Entry]

As you can see, my KF5 is installed in /home/kde5 (others may have it in /opt/kf5). The start-up script, named ‘start-kde’ simply sets the righ environment variables, calls ssh-agent and gpg-agent, then calls startkde from KF5. I added the export KDEWM=/usr/bin/i3 line into this script.

Quit your current session, choose the KF5 session in KDM and enjoy I3 with KF5!

I’ll now return to tinkering it, as some adjustments still need to be done 🙂

Oldies but goodies! Welcome back to VRCOM!

Yesterday I just created a new repository on github and pushed a new awesome library 😉 This library is an LGPL alternative to MS ATL Library. Yes, you read that correctly! I just pushed a library implementing a technology that’s more that 14 years old. I’m talking about Microsoft’s COM technology. I used to be an expert of that technology, back in 1999, and this library was my two cents about COM objects implementation in C++. See the readme file for more details of my motivations for writing this library. Please note that this library was successfully used in a production environment.

What pushed me to publish this? Well, it appears that Microsoft is slowly returning to COM. In my opinion WinRT is purely a new version of COM. That alone would not push me to create that repository. The trigger was someone on Google+ “C++ – Libraries & Frameworks” group asking if someone knew about an ATL alternative. And that started me. Why not help and share what I wrote at that time?

I managed to get on old CD with the sources, created the repo and directly pushed them. So, please expect them not to compile using modern MSVC. At that time I was a big fan of the templates (well, I still like them alot), a very new feature of the C++ language at that time. They were not clearly specified and the syntax varied heavily from one compiler to another. At that time I stick with MSVC compiler syntax. But I think that’ll be not so hard to adjust them for the current technology. I cannot do that myself, because I no longer use Windows nor I have MSVC on my computer. I only tried Visual C++ Express Edition in a virtual machine, but please accept I don’t plan to maintain this library. I published it only to help and lower the entry barrier for those who want an ATL alternative. And it would be awesome if someone there would update this library and maintain it. Just drop me a line and we’ll arrange for the commit rights on the github repository.

Here is the repository link for the VRCOM library : https://github.com/valir/vrcom

svnmerge2.py – A tool for SVN merge operations

Well, SVN is not yet dead. Enterprise world still uses it, or at least it’s still used at my workplace 🙂

When it comes to merging, one has the choice of TortoiseSVN or svnmerge from Orcaware. Each of these has their drawbacks. For example, TortoiseSVN is very mouse-intensive, so it’s click-error prone (yes, yes). The script from Orcaware is somewhat strict, and it even requires one to use it from the very beginning of the project. But what if you didn’t use it at that time? So, how to get a small improvement to this situation? Enter svnmerge2.py. I put the sources on, well, GitHub! 😉

There are instructions in both French and English. However, the script only shows French strings. I plan to add English translation later, when I’ll have some spare time. Meanwhile, if you need it, feel free to translate it and add a pull request on GitHub. I’d be glad to integrate it.