Page 1 of 3

Prowl Gmail Python Script

Posted: Sun Sep 20, 2009 6:24 pm
by chriscannon
Hello all,

I know their are current solutions to this problem, but from what I have seen they are either unstable or over complicated.

I'm a developer and I've just created a python script that only requires a server that is constantly running and OpenSSL installed. It is one file, stable, simple and well commented.

Check out the SourceForge project for it here: https://sourceforge.net/projects/gprowl/

Thanks,
Chris

Re: Prowl Gmail Python Script

Posted: Tue Sep 22, 2009 5:41 am
by Miko
Edited: Problem Fixed

Re: Prowl Gmail Python Script

Posted: Wed Sep 23, 2009 12:42 am
by fubaya
Works perfectly for me on Slackware Linux and running it in a shell.

Google actually released push mail and contacts/calendar sync today http://www.google.com/support/mobile/bi ... wer=138740

But using google's push email doesn't give you a notification popup, it's just a sound and badge, plus by using prowl, a jailbroken user can kill the mail app for the extra RAM, so there may still be a use for prowl/gmail

Re: Prowl Gmail Python Script

Posted: Wed Sep 23, 2009 6:51 am
by -DJ-
Hi, I was wondering if somebody can help me troubleshoot a problem I'm having.

The script runs perfectly fine on my Linux server and I've tested several e-mails with success. However, when there is no activity in my Gmail account for more than 5 or 10 minutes, the script stops responding. I believe the issue has something to do with Gmail's IMAP IDLE service timing out earlier than it is supposed to. Is there a way to configure openssl to keep the connection alive?

Re: Prowl Gmail Python Script

Posted: Thu Sep 24, 2009 2:42 am
by Miko
Latest version is great, no more crashes on Snow Leopard, thank you!

Re: Prowl Gmail Python Script

Posted: Sat Sep 26, 2009 9:18 pm
by chriscannon
@fubaya Gmail push is out, but as you stated, there's no way to be notified that a new e-mail has arrived on the locked screen. I currently use Gmail push and my Gprowl script so that I can quickly glance at my iPhone to see a summary of the message and then not have to wait for the iPhone to poll the server.

@-DJ- You may be the same person I talked to over e-mail, but I will post our solution so that others can benefit. The problem that we discovered was not with OpenSSL, but rather with the router that is connected to the server that the script is running on. We found out that the router was killing idle connections that lasted longer than some specified time. To resolve this problem, one must ensure that their router or system is not killing idle connections or has a very long timeout for killing idle connections.

Re: Prowl Gmail Python Script

Posted: Sun Sep 27, 2009 1:42 am
by fubaya
I've been using the other gmail script. The only problem I've had with it is the first 3 letters of the sender's name is cut off. I like this script better as it produces a cleaner notification and even throws in the date and time, but haven't switched to this one because it doesn't send the body of the email to Prowl. Any plans to add that?

Re: Prowl Gmail Python Script

Posted: Sun Sep 27, 2009 4:20 am
by chriscannon
@fubaya I'm surprised it is stable enough for you to use it. When I tried it, less than a day would go by and it would crash.

I've thought about adding that, and will do so once I figure out these issues:
1. How much of the text in the email's body should I include?
2. For HTML e-mails, how do I extract just the text and not the HTML code?

- Chris

Re: Prowl Gmail Python Script

Posted: Sun Sep 27, 2009 2:24 pm
by fubaya
Maybe it does crash, I dunno. I put it in a while true loop to restart itself if it does. I wouldn't run any "always on" script without looping, so I may be missing any instability. I'll add a line to log restarts for curiosity.

My thoughts on the email body
1. I would prefer the prowl limit which is 10000 bytes or characters. The other script has a line "body = msginfo[1][1][:1000]" which I realized (I know zero python) I could change to 10000 and get most entire emails. Now I get all my email through prowl and keep the iphone mail app killed unless I need to reply. Most people probably wouldn't want the whole thing, maybe it should be selectable?

2. Looks like python can handle html to text but I don't know how much work it would be. I personally don't care about html emails. If I get gibberish html mail in prowl, I can always open the mail app to read it.

Anyway, that's just my 2 cents, but maybe no one else would agree with me.

Re: Prowl Gmail Python Script

Posted: Sun Sep 27, 2009 5:10 pm
by chriscannon
@fubaya Ah I see, I did not have it in a loop. There still exists the problem that if it crashes when an e-mail arrives, then restarts, it will not send out a Prowl notification about the new e-mail. I do not find this acceptable.

Looks like he's using 100 as opposed to 1000. Also Prowl can only support 10000 characters in the entire message, so the body text would have to be less than 10000 because that would include the FROM, DATE and SUBJECT fields. Personally, I like a clean notification and putting the entire message on the screen I think would just look horrible.

- Chris

Re: Prowl Gmail Python Script

Posted: Sun Sep 27, 2009 11:38 pm
by fubaya
Only the first line or so shows up in the notification, the rest of the 10000 characters can be viewed in the Prowl app. 10000 should be enough for most mail. Before this post, this entire thread including names, dates and subjects is just 9918. If an email was more than 10k and got cut off, I'd just use the mail app. But again, maybe I'm the only person using Prowl this way. The other script is working for me so I'll just stick with it.

Re: Prowl Gmail Python Script

Posted: Mon Sep 28, 2009 12:01 am
by chriscannon
@fubaya I've added this functionality and put it in SVN under the SourceForge project. I'm not confident enough to actually release it, but if you want to check it out go ahead.

By default I include 100 letters, but you can easily edit the script to show as many as you want. I'll probably add a command line argument for that later.

- Chris

Re: Prowl Gmail Python Script

Posted: Mon Sep 28, 2009 2:14 am
by Miko
Hi Chris,

So far so good, no crashes and body is showing well in the prowl app.
I like how you have kept the notification clean by only showing 1 line of the body!

Re: Prowl Gmail Python Script

Posted: Mon Sep 28, 2009 1:15 pm
by Miko
Spoke to soon...
I know that you are not officially supporting the version with the email body but i thought it might help you in debugging it.

I had it run all day on a old imac g4 with osx 10.5.8

had a few crashes....

last one that i actually saved for you:

Code: Select all

Traceback (most recent call last):
  File "/Users/air/Desktop/gprowl.py", line 285, in <module>
    main(sys.argv[1:])
  File "/Users/air/Desktop/gprowl.py", line 282, in main
    GmailIdleNotifier().start()
  File "/Users/air/Desktop/gprowl.py", line 164, in start
    self.fetchEmail(emailId)
  File "/Users/air/Desktop/gprowl.py", line 194, in fetchEmail
    date = self.formatDate(emailInfo).strip()
  File "/Users/air/Desktop/gprowl.py", line 226, in formatDate
    t = time.strptime(str(date[6:end]).strip(),"%d %b %Y %H:%M:%S")
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/_strptime.py", line 331, in strptime
ValueError: time data did not match format:  data=n: 8.5.409 / Virus Database: 270.13.113/2399 - Release Date: =  fmt=%d %b %Y %H:%M:%S



Take care,
Miko

Re: Prowl Gmail Python Script

Posted: Mon Sep 28, 2009 7:36 pm
by fubaya
I noticed problems with large emails. I didn't have anything to email as a test, so I copied some text and edited it down to 10k characters and emailed it to myself but never got a notification. I edited it down to 5k and got that notification, then tried 8 or 9k and didn't get it, so there's a secret email length that is causing problems. On the command line, the script did say "A new mail has arrived" but I never got the notification. I changed the text and subject on all of them in case it was treating the email as a duplicate.

It made me curious if the other script was cutting off long emails or just not sending them, so I sent a 15k mail and the other script sent a notification which was cut off to 10k characters.

But anyway, don't worry about this on my account. I don't get any email that is a full 10k, but there seems to be something that causes it not to sent a notification.

Re: Prowl Gmail Python Script

Posted: Mon Sep 28, 2009 10:37 pm
by chriscannon
@Miko I've just stumbled across this error myself. The problem was that it was still searching for "Date:" when the body of the e-mail was being read. I've fixed it and checked it into SVN.

@fubaya Interesting, are you using the SVN version? If so, it may be the same problem that Miko reported. I just tried sending a very large e-mail (over 50k lines) and it went through. Try out the latest version in SVN. Also, it may be impossible for me to figure out why you're having this problem if you edited the code yourself.

Re: Prowl Gmail Python Script

Posted: Tue Sep 29, 2009 4:40 am
by chriscannon
@fubaya I think I've figured out what's going on, if you edited the script to allow for 10,000 characters to be sent in the body. The Prowl API allows for a maximum of 10,000 characters, that includes the date, from, subject and body fields. By sending an e-mail that has 10,000 characters in the body, you are exceeding the limit of the Prowl API and it is probably throwing back an exception that the description of the Prowl notification is too long. This exception does not show up on screen since I do not check for this when I send the notification.

Re: Prowl Gmail Python Script

Posted: Tue Sep 29, 2009 9:35 pm
by thebasa
okay i have it running on appengine. edited prowl key, username, password in gprowl.py. Left openssl path as "/usr/bin/openssl" Upon running it I get:

Code: Select all

<type 'exceptions.AttributeError'>: 'module' object has no attribute 'Popen'
Traceback (most recent call last):
  File "/base/data/home/apps/gprowl-prowlgmailnotify/1.336688350264182693/gprowl.py", line 278, in <module>
    main(sys.argv[1:])
  File "/base/data/home/apps/gprowl-prowlgmailnotify/1.336688350264182693/gprowl.py", line 275, in main
    GmailIdleNotifier().start()
  File "/base/data/home/apps/gprowl-prowlgmailnotify/1.336688350264182693/gprowl.py", line 133, in start
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Thoughts?

Re: Prowl Gmail Python Script

Posted: Wed Sep 30, 2009 7:06 pm
by chriscannon
@thebasa Initially it looks like openssl is not where Gprowl expects it to be. Can you type "which openssl" on the machine that you are running the script on and post the output here?

Re: Prowl Gmail Python Script

Posted: Wed Sep 30, 2009 7:48 pm
by thebasa
I suspected that but I can't find info on app engine openssl path. I'm running it on google app engine infrastructure, not my own pc. I've been trying to find a solution that eliminates the need to use my less reliable hardware at home, just like gvmax does for google voice notifications. I can't figure out how to run command line for ae or work that command into a script to run it. Probably be a this weekend project. In the mean time if anyone deploys it to ae, let me know how it works out.