use FindBin qw($Bin);
use YAML::Tiny;
use Date::Parse qw(str2time);
+use Mail::Sendmail;
+use Encode;
my $_execmode = $ARGV[0] || 0;
sub VERBOSE () { $_execmode eq 'verbose' };
my $skip;
if ($tweets->{$id}{type} eq 'retweet') {
DEBUG and warn "skipping $id that was already retweeted\n";
- $skip = $id;
+ $skip = 'retweet';
}
if (defined $conf->{allow}) {
- $skip = $id;
+ $skip = 'allow';
foreach my $screen_name ( @{ $conf->{allow}{screen_name} } ) {
if ($tweets->{$id}{screen_name} eq $screen_name) {
DEBUG and warn "$id was allowed by screen_name\n";
}
}
+ if (defined $conf->{mail}) {
+ my $send;
+ foreach my $pickup ( @{ $conf->{mail}{pickup} } ) {
+ if ($tweets->{$id}{type} eq $pickup) {
+ $send = 1;
+ last;
+ }
+ }
+ if ($conf->{mail}{ignore_allowed}) {
+ if (defined $conf->{allow} and ! defined $skip) {
+ # this tweet was allowed to retweet, so that be ignored on mail
+ undef $send;
+ }
+ }
+
+ if ($send) {
+ if (! exists($conf->{mail}{body}) ) {
+ $conf->{mail}{body} =
+ "[localtime(date)] http://twitter.com/<screen_name>/status/<status_id> text\n" .
+ "----------------------------------------\n"
+ ;
+ }
+ $conf->{mail}{body} .=
+ "[" . localtime($tweets->{$id}{date}) . "] " .
+ "http://twitter.com/" .
+ $tweets->{$id}{screen_name} . "/status/" .
+ $tweets->{$id}{status_id} . " " .
+ $tweets->{$id}{text} . "\n"
+ ;
+ }
+ }
+
if ($skip) {
next;
}
$stat->{$tweets->{$id}{type}} = $id;
}
+if ($conf->{mail}{body}) {
+ my $body = encode("iso-2022-jp", $conf->{mail}{body});
+
+ my %mail = (
+ Smtp => $conf->{mail}{server},
+ From => $conf->{mail}{from},
+ To => join(", ", @{ $conf->{mail}{to} }),
+ Subject => $conf->{mail}{subject},
+ "Content-Type" => $conf->{mail}{contenttype},
+ Body => $body,
+ );
+ DEBUG and warn "sending mail => ", Dumper(\%mail);
+
+ DEBUG or sendmail(%mail) or warn "Error sending mail: $Mail::Sendmail::error\n";
+}
+
if ($tweets) {
# save last status to yaml file
DEBUG or YAML::Tiny::DumpFile("$Bin/status.yml", $stat);