Changeset 1638

Show
Ignore:
Timestamp:
08/31/05 07:34:27
Author:
miyagawa
Message:

Added 'group-items' option to group feed items in one email
- to decrease the volume of emails sent to avoid Gmail account lockdown, and
- to make browsing easy on Gmail thanks to conversation threading based on Subject
Added --verbose option for debug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bloglines2email/trunk/bloglines2email

    r1635 r1638  
    1212our $VERSION = '0.01'; 
    1313 
    14 GetOptions("test", \my $testmode); 
     14GetOptions(\our %opt, "test", "verbose"); 
    1515 
    1616my $conf = File::Spec->catfile($FindBin::Bin, "bloglines2email.conf"); 
     
    2222); 
    2323 
    24 my $mark_read = $testmode ? 0 : 1; 
     24my $mark_read = $opt{test} ? 0 : 1; 
    2525my @updates = $bws->getitems(0, $mark_read); 
     26debug(scalar(@updates) . " feeds updated."); 
    2627for my $update (@updates) { 
    2728    send_email($cfg, $update); 
     29} 
     30 
     31sub debug { 
     32    my $msg = "@_"; 
     33    chomp($msg); 
     34    print STDERR encode('utf-8', "$msg\n") if $opt{verbose}; 
    2835} 
    2936 
     
    3239    my $feed  = $update->feed; 
    3340    my @items = $update->items; 
    34     for my $item (@items) { 
    35         send_one_email($cfg, $feed, $item); 
     41    if ($cfg->{'group-items'}) { 
     42        send_email_feed($cfg, $feed, \@items); 
     43    } 
     44    else { 
     45        for my $item (@items) { 
     46            send_email_item($cfg, $feed, $item); 
     47        } 
    3648    } 
    3749} 
    3850 
    39 sub send_one_email { 
     51sub send_email_feed { 
     52    my($cfg, $feed, $items) = @_; 
     53    my $subject = $feed->{title} || '(no-title)'; 
     54    my $body = join '<hr />', map format_body($feed, $_, $cfg), @$items; 
     55    do_send_mail($cfg, $feed, $subject, $body); 
     56
     57 
     58sub send_email_item { 
    4059    my($cfg, $feed, $item) = @_; 
     60    my $subject = $item->{title} || '(no-title)'; 
     61    my $body    = format_body($feed, $item, $cfg); 
     62    do_send_email($cfg, $feed, $subject, $body); 
     63} 
     64 
     65sub do_send_mail { 
     66    my($cfg, $feed, $subject, $body) = @_; 
     67    debug("Sending $subject to $cfg->{mailto}"); 
    4168    my $feed_title = $feed->{title}; 
    42        $feed_title =~ tr/,/;/
     69       $feed_title =~ tr/,//d
    4370    my $msg = MIME::Lite->new( 
    4471        From => encode('MIME-Header', qq("$feed_title" <$cfg->{mailfrom}>)), 
    4572        To   => $cfg->{mailto}, 
    46         Subject => encode('MIME-Header', $item->{title}), 
     73        Subject => encode('MIME-Header', $subject), 
    4774        Type => 'multipart/related', 
    4875    ); 
    49     my $body  = format_body($feed, $item); 
    5076    $msg->attach( 
    5177        Type => 'text/html; charset=utf-8', 
     
    5682 
    5783sub format_body { 
    58     my($feed, $item) = @_; 
     84    my($feed, $item, $cfg) = @_; 
    5985    my $template = get_template(); 
    6086    my $tt = Template->new; 
     
    6288        feed => $feed, 
    6389        item => $item, 
     90        cfg  => $cfg, 
    6491    }, \my $out); 
    6592    $out; 
     
    6996    return <<'HTML'; 
    7097<div> 
     98[% var = 'group-items'; IF cfg.$var %]<h2 style="font-size: 1em">[% item.title | html %]</h2>[% END %] 
    7199[% IF feed.image %]<div style="float:right"><a href="[% feed.image.link %]"><img style="border:0" src="[% feed.image.url | html %]" alt="[% feed.image.title | html %]" /></a></div>[% END %] 
    72100<div>Link: <a href="[% item.link | html %]">[% item.link | html %]</a><br /> 
  • bloglines2email/trunk/bloglines2email.conf.sample

    r1629 r1638  
    33mailto: mail-address@example.com 
    44mailfrom: mail-address@exapmle.com 
     5group-items: 1