Author |
Message |
declanh
|
Posted: Thu Jan 19, 2006 5:30 pm |
|
Joined: Wed Aug 24, 2005 3:44 am
Posts: 210
|
I've knocked together a quick perl script to use mythtvosd to notify of new emails.
It's very raw, but it works so far.
Code: #!/usr/bin/perl
# Popcheck.pl - Declan Higgins # Version 0.1 Jan 2006
use Net::POP3;
sub do_account ()
{ my $unwanted = shift ; my $mail_server = shift ; my $username = shift ; my $password = shift ; my $maxmess = shift ;
$pop = Net::POP3->new($mail_server) or die "Can't open connection to $mail_server : $!\n"; defined ($pop->login($username, $password)) or die "Can't authenticate: $!\n"; $messages = $pop->list or die "Can't get list of undeleted messages: $!\n"; $mc = keys %$messages; return if $mc==0; $nmc="$username has $mc emails"; $x=`/usr/bin/mythtvosd --template=alert --alert_text="$nmc"`; sleep 3; foreach $msgid (keys %$messages) { $message = $pop->get($msgid); unless (defined $message) { warn "Couldn't fetch $msgid from server: $!\n"; next; } $messno++; $q=0; $t="[$messno"; foreach $z (@$message) { if ($z=~m/^From: (.*?)$/) {$t.=",f=$1";} if ($z=~m/^Subject: (.*?)$/) { $t.=",s=$1"; } if ($z=~m/^To: (.*?)$/) {$t.=",t=$1";} #last if $q++ > 18; } $t.="]"; $t=~s/<//g; $t=~s/>//g; $t=~s/\[//g; $t=~s/\]//g; $x=`/usr/bin/mythtvosd --template=alert --alert_text="$t"`; sleep 3; return if $messno >= $maxmess; # $message is a reference to an array of lines }
}
open CONFIG,"</popcheck/popcheck.rc"; while (<CONFIG>) { chomp; @b=split /,/; next unless $b[0] eq "account"; &do_account (@b); } 1
you also need a file in /popcheck/popcheck.rc with entries of the following form Code: account,popserver,mbox1,password,5 account,popserver,mbox2,password,5 account,popserver,mbox3,password,5
account is a literal - dont edit it ...
replace popserver with you pop server host
replace mbox1 with the mailbox you want polled
replace password with you mailbox
the last numeric field is used to limit the number of emails notified....
in this case it will only show the first 5 - useful if your mailbox has 500 emails.
I have this CRONed to run every 15 mins.
comments,thoughts,suggestions -
is there a better way to do this ?
|
|
Top |
|
![](images/spacer.gif) |
cesman
|
Posted: Thu Jan 19, 2006 10:04 pm |
|
Joined: Fri Sep 19, 2003 7:05 pm
Posts: 5088
Location:
Fontana, Ca
|
_________________ cesman
When the source is open, the possibilities are endless!
|
|
Top |
|
![](images/spacer.gif) |
shaamone
|
Posted: Mon Jan 23, 2006 1:39 pm |
|
Joined: Fri Sep 30, 2005 10:41 am
Posts: 17
|
Fantastic
I'm wondering what changes I'd need to make to have it check my Gmail account? That doesn't run on the std pop3 port.
|
|
Top |
|
![](images/spacer.gif) |
mad_paddler
|
Posted: Mon Jan 23, 2006 3:13 pm |
|
Joined: Sun Jun 12, 2005 2:39 pm
Posts: 464
Location:
UK
|
With some quick googling i think you could just change the line:
Code: $pop = Net::POP3->new($mail_server) to Code: $pop = Net::POP3->new($mail_server,<gmailport>)
Change <gmailport> to whatever port gmail uses for pop3. Would probably be better to make a variable and have it read the port from the same file as the accounts...
|
|
Top |
|
![](images/spacer.gif) |
declanh
|
Posted: Wed Feb 01, 2006 6:27 pm |
|
Joined: Wed Aug 24, 2005 3:44 am
Posts: 210
|
Here is a tiny update
a)fixed a typo with message counts
b)and added non reporting of messages if their subject contains the word SPAM
b) is useful if you use a spam filter (like spampal) which prefilters your emails - I run spampal on my main pc and have configured popcheck.rc to fetches from it ... doing this avoids spam emails disrupting my viewing...
Code: #!/usr/bin/perl
# Popcheck.pl - Declan Higgins # Version 0.1b Jan 2006
use Net::POP3;
sub do_account ()
{ my $unwanted = shift ; my $mail_server = shift ; my $username = shift ; my $password = shift ; my $maxmess = shift ;
my $messno = 0;
$pop = Net::POP3->new($mail_server) or die "Can't open connection to $mail_server : $!\n"; defined ($pop->login($username, $password)) or die "Can't authenticate: $!\n"; $messages = $pop->list or die "Can't get list of undeleted messages: $!\n"; $mc = keys %$messages; return if $mc==0; $nmc="$username has $mc emails"; $x=`/usr/bin/mythtvosd --template=alert --alert_text="$nmc"`; sleep 3; foreach $msgid (keys %$messages) { $message = $pop->get($msgid); unless (defined $message) { warn "Couldn't fetch $msgid from server: $!\n"; next; } $messno++; $q=0; $t="[$messno"; foreach $z (@$message) { if ($z=~m/^From: (.*?)$/) {$t.=",f=$1";} if ($z=~m/^Subject: (.*?)$/) { $t.=",s=$1"; next if $z=~m/SPAM/; } if ($z=~m/^To: (.*?)$/) {$t.=",t=$1";} #last if $q++ > 18; } $t.="]"; $t=~s/<//g; $t=~s/>//g; $t=~s/\[//g; $t=~s/\]//g; $x=`/usr/bin/mythtvosd --template=alert --alert_text="$t"`; sleep 3; return if $messno >= $maxmess; # $message is a reference to an array of lines }
}
open CONFIG,"</usr/declan/popcheck.rc"; while (<CONFIG>) { chomp; @b=split /,/; next unless $b[0] eq "account"; &do_account (@b); } 1
|
|
Top |
|
![](images/spacer.gif) |
victor97
|
Posted: Sun Jan 27, 2008 7:38 am |
|
Joined: Fri Feb 24, 2006 9:46 am
Posts: 65
|
Hi,
I tried to install this on my system, but I retrieve the following errors:
Code: root@mythtv:/myth/emailnotify# sh Popcheck.pl : command not found: : command not found: Popcheck.pl: line 6: use: command not found : command not found: : command not found: : command not found: Popcheck.pl: line 9: syntax error near unexpected token `(' 'opcheck.pl: line 9: `sub do_account () root@mythtv:/myth/emailnotify#
Do I need to install something else to make this script work?
Regards,
Victor
|
|
Top |
|
![](images/spacer.gif) |
slowtolearn
|
Posted: Sun Jan 27, 2008 8:00 am |
|
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location:
Farmington, MI USA
|
victor97 wrote: Hi, I tried to install this on my system, but I retrieve the following errors: Code: root@mythtv:/myth/emailnotify# sh Popcheck.pl : command not found: : command not found: Popcheck.pl: line 6: use: command not found : command not found: : command not found: : command not found: Popcheck.pl: line 9: syntax error near unexpected token `(' 'opcheck.pl: line 9: `sub do_account () root@mythtv:/myth/emailnotify#
Do I need to install something else to make this script work? Regards, Victor Remove the blank line at the top of your script - The very first line should be #!/usr/bin/perl.
|
|
Top |
|
![](images/spacer.gif) |
victor97
|
Posted: Sun Jan 27, 2008 8:54 am |
|
Joined: Fri Feb 24, 2006 9:46 am
Posts: 65
|
The first line is as mentioned in the script, no blank line. (I copied and past the script from the forum into a new file and checked if the first line is #!urs/bin/perl)
Still get the same errors.
Any ideas? Must be something small I think.
Victor
|
|
Top |
|
![](images/spacer.gif) |
slowtolearn
|
Posted: Sun Jan 27, 2008 9:22 am |
|
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location:
Farmington, MI USA
|
victor97 wrote: The first line is as mentioned in the script, no blank line. (I copied and past the script from the forum into a new file and checked if the first line is #!urs/bin/perl)
Still get the same errors.
Any ideas? Must be something small I think.
Victor Did you copy/paste from a Windoze machine? If so you'll need to run it through dos2unix - man dos2unix for details.
Just re-read your post, you need to make the file executable and call it directly (eg. ./Popcheck.pl or /path/to/Popcheck.pl). Perl should be the command interpreter, not bash (which is what your sh Popcheck.pl is using)
|
|
Top |
|
![](images/spacer.gif) |
mythedoff
|
Posted: Sun Jan 27, 2008 12:03 pm |
|
Joined: Mon Jul 31, 2006 10:41 pm
Posts: 149
|
If I understand this correctly, a message could pop up during a movie or during some other activity. Correct? That could be quite bothersome. Maybe assigning the script to a button on the remote is an alternative.
|
|
Top |
|
![](images/spacer.gif) |
declanh
|
Posted: Sun Jan 27, 2008 2:26 pm |
|
Joined: Wed Aug 24, 2005 3:44 am
Posts: 210
|
victor97 wrote: The first line is as mentioned in the script, no blank line. (I copied and past the script from the forum into a new file and checked if the first line is #!urs/bin/perl)
Still get the same errors.
Any ideas? Must be something small I think.
Victor
first line must be
Code: #!/usr/bin/perl
exactly as shown this only works if you have perl located in /usr/bin you can check this by typing Code: which perl
note that the exclamation mark is essential typing Code: sh popcheck.pl
will tell the session to run the script using /bin/sh which wont work. you should also be able to do Code: perl popcheck.pl
which should work
Last edited by declanh on Sun Jan 27, 2008 2:39 pm, edited 1 time in total.
|
|
Top |
|
![](images/spacer.gif) |
declanh
|
Posted: Sun Jan 27, 2008 2:28 pm |
|
Joined: Wed Aug 24, 2005 3:44 am
Posts: 210
|
mythedoff wrote: If I understand this correctly, a message could pop up during a movie or during some other activity. Correct? That could be quite bothersome. Maybe assigning the script to a button on the remote is an alternative.
depends on your needs - i have mine croned to run every 15 mins and the messages are not that intrusive to me - but then again i tend to read alot of emails as they come in
To me the advange is not having to remember to press a key on the remote.
|
|
Top |
|
![](images/spacer.gif) |
victor97
|
Posted: Sun Jan 27, 2008 3:39 pm |
|
Joined: Fri Feb 24, 2006 9:46 am
Posts: 65
|
Ok, I got it working. I had to give executable permission and after that I could run the script. I'm learning every day!
But it is not working perfect. For most of my e-mails it won't show the subject of the message. Not sure why.
Also my gmail account is not working. I tried what has been raised earlier by mad_paddler, but that is not working for me.
Do you guys have the same behaviour? Besides this, I really loving it! Great feature!
|
|
Top |
|
![](images/spacer.gif) |
mjl
|
Posted: Sun Jan 27, 2008 9:28 pm |
|
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location:
Warwick, RI
|
Hi,
Looks to be a rather cool "feature"
Only thing that may not have been clear is:
Code: open CONFIG,"</usr/declan/popcheck.rc";
needs to be set for the individuals setup
You did hint to put popcheck.rc into popcheck/ folder which is a good location for both the popcheck.pl & popcheck.rc
ie,
/home/mythtv/popcheck/popcheck.rc
I think it does need a test message available in case there isn't any mail when you first run it as it just exits gracefully if nothing has arrived so one can only assume all is well.
Thank you
Mike
I do see this error if I add the #!/usr/bin/perl -w
Name "main::q" used only once: possible typo at popcheck.pl line 40.
|
|
Top |
|
![](images/spacer.gif) |
mjl
|
Posted: Sun Jan 27, 2008 11:17 pm |
|
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location:
Warwick, RI
|
mjl wrote: Hi, Looks to be a rather cool "feature" ![Smile :)](./images/smilies/icon_smile.gif) Only thing that may not have been clear is: Code: open CONFIG,"</usr/declan/popcheck.rc"; needs to be set for the individuals setup You did hint to put popcheck.rc into popcheck/ folder which is a good location for both the popcheck.pl & popcheck.rc ie, /home/mythtv/popcheck/popcheck.rc I think it does need a test message available in case there isn't any mail when you first run it as it just exits gracefully if nothing has arrived so one can only assume all is well. Thank you ![Smile :)](./images/smilies/icon_smile.gif) Mike I do see this error if I add the #!/usr/bin/perl -w Name "main::q" used only once: possible typo at popcheck.pl line 40.
Seems to run, however I see no osd on the tv... what did I mis.....
|
|
Top |
|
![](images/spacer.gif) |