You are not logged in.

#1 2009-07-01 21:49:09

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

[solved] awesome - Get subject of new messages or number in tasklist

Hi,

anrxc has a nice widget that shows the subject of new mails in the tasklist.

Unfortunately this only works if one saves his mails in ~/mails.

So, I checked the awesome wiki and adjusted this widget to my needs - I hope I made the correct changes.

Here's what I have now in rc.lua:

mymail = widget({ type = "textbox", align = "right"})
mymail.text = "<b><small> mail </small></b>"

and

awful.hooks.timer.register(10, function ()
    local f = io.open("/home/thomas/tmp/gmx") 
    local l = f:read() -- read output of command
    f:close()

    mymail.text = l
    os.execute("~/.config/awesome/unread.py > ~/tmp/gmx &")
end)

and the python script: ~/.config/awesome/unread.py

#!/usr/bin/python

import imaplib

#first field is imap server, second - port (993 for gmail SSL IMAP)
M=imaplib.IMAP4("imap.gmx.net", 143 )
#first field is imap login (gmail uses login with domain and '@' character), second - password
M.login("myusername","mypassword")

status, counts = M.status("Inbox","(MESSAGES UNSEEN)")

unread = counts[0].split()[4][:-1]
if unread == "0":
    print " no mail "
else:
#red bg color when you have unseen mail
    print "<bg color=\"red\" style='font-size: 25px;'>  <b>"+unread+"</b>  </bg>"

M.logout()

The problem: it doesn't work. sad

When I switch to tty1 I see the following message:

draw_text_context_init:177:cannot parse pango markup: unknown tag 'bg' on line 1 char 50

Any advice?

TIA

barghest

/edit: what would also be nice is the number of new messages (and for multiple accounts, but that's the next step)

Last edited by Barghest (2009-07-06 19:34:32)

Offline

#2 2009-07-05 10:01:47

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: [solved] awesome - Get subject of new messages or number in tasklist

So, no idea anyone?

Offline

#3 2009-07-05 11:47:53

WhiteMagic
Member
Registered: 2007-03-01
Posts: 85

Re: [solved] awesome - Get subject of new messages or number in tasklist

It seems that the formatting you're using is not correct. I never played with the font formatting in awesome so I can't say what you'd have to change but maybe start by removing all formatting and just write plain text and add the formatting back when the simple displaying stuff works correctly.

Offline

#4 2009-07-05 13:16:20

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: [solved] awesome - Get subject of new messages or number in tasklist

Ok, removing any all formatting worked (things can be that easy ;b )

I know see the number of unread messages for my account. I'll now see if I can also fetch the subject of a mail....

Thanks for giving me the broad hint smile

\edit: Any Idea how to ask for the number of mails with from 2 accounts? Or should I create another widget for the additional one?

Last edited by Barghest (2009-07-05 13:38:56)

Offline

#5 2009-07-05 14:10:54

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [solved] awesome - Get subject of new messages or number in tasklist

Barghest wrote:

anrxc has a nice widget that shows the subject of new mails in the tasklist. Unfortunately this only works if one saves his mails in ~/mails.

It doesn't matter where you save your mail, the difference is the format. I am using mbox and you maildirs.

I personally use heirloom mailx implementation, which served me great for a while on that widget, but mailx-heirloom can also work with maildirs.


You need to install an RTFM interface.

Offline

#6 2009-07-05 17:32:12

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: [solved] awesome - Get subject of new messages or number in tasklist

Hi anrxc,

thanks for the information. For my poor skills this sounds too complicated sad

So, I think showing the number of unread messages is enough for me. I then can invoke alpine and read the mails (for that I'll have a look at your config smile ).

What I'm interested in is if I can combine multiple accounts so that I see e.g. "3 new mails", no matter on what account they are.

Offline

#7 2009-07-05 17:59:06

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [solved] awesome - Get subject of new messages or number in tasklist

Barghest wrote:

For my poor skills this sounds too complicated sad

You can replace arch standard mailx package with mailx-heirloom from AUR. Then just read the manual. If you were also refering to the mbox - maildir difference, see these; mbox, maildir.

Barghest wrote:

What I'm interested in is if I can combine multiple accounts so that I see e.g. "3 new mails", no matter on what account they are.

Of course you can. You need to expand your python script either to:
a) hard code all your accounts, let it grab information for all of them and then return the joined output
    - you register your widget in rc.lua only once
b) transform your code, in the script, that checks an account into a function to which you can pass an account and login as arguments
    - you register your widget multiple times in awesome, for each wanted account, and then present results separate or join them

Last edited by anrxc (2009-07-05 17:59:33)


You need to install an RTFM interface.

Offline

#8 2009-07-06 09:51:19

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: [solved] awesome - Get subject of new messages or number in tasklist

anrcx, you overburden me ;b

With poor skills I mean anything like scripting or programming languages.

So, I tried to extend the script (pls don't laugh). I defined the other account as N according to the M account.

#!/usr/bin/python

import imaplib

#first field is imap server, second - port (993 for gmail SSL IMAP)
M=imaplib.IMAP4("imap.gmx.net", 143 )
#first field is imap login (gmail uses login with domain and '@' character), second - password
M.login("myusername","mypassword")

N=imaplib.IMAP4_SSL("mail.staff.uni-marburg.de", 993 )
N.login("myusername","mypassword")

status, countm = M.status("Inbox","(MESSAGES UNSEEN)")
status, countn = N.status("Inbox","(MESSAGES UNSEEN)")

unread = counts[0].split()[4][:-1]
if unread == "0":
    print " no mail "
else:
    print ""+unread+""

M.logout()
N.logout()

What I didn't find out is how to sum the mails up. In the python command list I found sum() but this isn't for string (and countm and counts are strings, aren't they).

So, I guess I need an additional step, in that the both values are given out in integers before they can be summed up.

Thanks for helping an incapable but eager to learn person smile

Offline

#9 2009-07-06 15:18:39

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [solved] awesome - Get subject of new messages or number in tasklist

Barghest wrote:

What I didn't find out is how to sum the mails up. In the python command list I found sum() but this isn't for string (and countm and counts are strings, aren't they). So, I guess I need an additional step, in that the both values are given out in integers before they can be summed up.

It is very simple, with '+' you can join strings, but also do arithmetic. So if your number of e-mail is (of type) string (even though it's a number) you can do int(string) + integer:

# We are no trying to win any awards for best code, OK
status_one, count_one = M.status("Inbox","(MESSAGES UNSEEN)")
status_two, count_two = N.status("Inbox","(MESSAGES UNSEEN)")

unread_one = count_one[0].split()[4][:-1]
unread_two = count_two[0].split()[4][:-1]

unread = int(unread_one) + int(unread_two)

By the way, since you are already working with imaplib you should just grab a list of messages (or only last message ;^)) with it, no need for any mailx complications (don't forget to check the example at the end).

Edit: to cut down on the number of future messages, I should already warn you that you should cover exceptions in your script, so if one connection fails your whole widget doesn't break, see errors and exceptions.

To finish this discussion I also recommend you to read (do your self a favour and do read) A byte of Python, it will teach you Py in just one day - guaranteed, you won't be writing new operating systems, but you will know python.

Last edited by anrxc (2009-07-06 15:26:02)


You need to install an RTFM interface.

Offline

#10 2009-07-06 19:33:53

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: [solved] awesome - Get subject of new messages or number in tasklist

Thanks anrxc!

And thanks to the Byte of Python I was able to adjust the following part correctly. (We have intergers now and no more strings smile

if unread == 0:
    print " no mail "
else:
    print unread, 'new mails'

About your warning with the failing connection I already thought about it.

Oh, and I'm reading a lot (it's part of my job, but this isn't technical literature ^^) and I'm always happy when someone points me to a good source whit that I can learn things by my own. Just according to your signature smile

Offline

Board footer

Powered by FluxBB