Index: Dev/twitter/twitterbot.pl
===================================================================
--- Dev/twitter/twitterbot.pl	(revision 702399e09a32025f7dfed289735b064361263a6b)
+++ Dev/twitter/twitterbot.pl	(revision 45a20c35b7f63730b2bd6d7253d7b9aa07df68c2)
@@ -14,4 +14,6 @@
 use YAML::Tiny;
 use Date::Parse qw(str2time);
+use Mail::Sendmail;
+use Encode;
 
 my $_execmode = $ARGV[0] || 0;
@@ -52,8 +54,8 @@
     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) {
@@ -69,4 +71,36 @@
                 last;
             }
+        }
+    }
+    
+    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"
+            ;
         }
     }
@@ -91,4 +125,20 @@
     
     $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";
 }
 
