Aby ten skryp był wyświetlany prawidłowo w moim conky postanowiłem troszkę powyrzucać dla mnie zbędnych rzeczy z tego skryptu (np data jest dla mnie całkowicie zbędna). Obecnie skrypt wygląda następująco:
#!/usr/bin/perl -w
#
# gmail.pl v1.0
#
# Checks a GMail account's atom feed (via SSL) and formats the
# results nicely in a console window
# * usage: gmail.pl <username> <password>
#
# Required Perl modules:
# * LWP::UserAgent (for fetching the atom feed)
# * XML::Parser (for parsing the atom feed)
#
# If you only want to check one account, you can put the username
# and password below (between the ""), and run without arguments.
$username = (defined($ARGV[0])) ? $ARGV[0] : "login";
$password = (defined($ARGV[1])) ? $ARGV[1] : "haslo";
########################################################################
if ($username eq "" || $password eq "") {
die("Usage: gmail.pl <username> <password>
(or you can edit the script to use one account automatically)\n");
}
require LWP::UserAgent;
require XML::Parser;
# fetch atom feed
my $browser = LWP::UserAgent->new;
$browser->agent("gmail.pl/1.0");
$browser->credentials(
'mail.google.com:443',
'New mail feed',
$username."\@gmail.com",
$password
);
unless (defined($xmlresponse = $browser->get('https://mail.google.com/mail/feed/atom')))
{ die($xmlresponse->status_line, "\n"); }
$xml = $xmlresponse->content;
$xml =~ s/\…/.../g;
my $p = new XML::Parser(Style => 'Subs');
$p->setHandlers(Char => \&char);
$line = ('-' x 50) . "\n";
$p->parse($xml);
# procedures to deal with various elements
sub char { my (undef, $str) = @_; $char = $str;}
sub title_ {
my ($el) = @_;
my $parent = ($el->current_element);
if ($parent eq "feed") { print "" . $char };
if ($parent eq "entry") { $subj = "S: " . $char };
}
sub name_ { $auth = $char;}
sub email_ { $auth = $auth . " [" . $char . "]";}
sub entry_ {
print "F: $auth \n" .
$subj . "\n" .
$line;
}
sub fullcount_ {
$ct = $char;
if ($ct==0) {
print "\n0 messages.\n\n";
exit;
} elsif ($ct==1) {
print "\n" . (1) . (" new message.\n") . $line;
} elsif ($ct>1) {
print "\n" . ($ct) . (" new messages.\n") . $line;
}
}
Chciałem aby mi nie wyświetlało "Gmail - Inbox for" lecz niestety nie wiem w jakiej zmiennej jest ten text przechowywany.
PS, Jakoś nie wyobrażam sobie jak ten skrypt wyglądałby dla poczty o2. Więc pozostaje tylko w Gmail ustawić aby pobierało maile z innych skrzynek