Changeset 34

Show
Ignore:
Timestamp:
02/06/06 07:42:19
Author:
miyagawa
Message:

deprecated group-items option in Gmail for now. Refs #2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/config.yaml.sample

    r25 r34  
    4141      mailto:   miyagawa@example.com 
    4242      mailfrom: miyagawa@example.net 
    43       group_items: 1 
    4443      mailroute: 
    4544        via: smtp 
  • trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm

    r33 r34  
    2222    my($self, $context, $feed) = @_; 
    2323 
    24     my @items = $feed->entries; 
    25     if ($self->conf->{group_items}) { 
    26         $self->send_email_feed($context, $feed, \@items); 
    27     } else { 
    28         for my $item (@items) { 
    29             $self->send_email_item($context, $feed, $item); 
    30         } 
    31     } 
    32 } 
    33  
    34 sub send_email_feed { 
    35     my($self, $context, $feed, $items) = @_; 
    3624    my $subject = $feed->title || '(no-title)'; 
    37     my $body = join '<hr />', map $self->templatize($context, $feed, $_), @$items; 
    38     $self->do_send_mail($context, $feed, $subject, $body); 
    39 
    40  
    41 sub send_email_item { 
    42     my($self, $context, $feed, $item) = @_; 
    43     my $subject = $item->title || '(no-title)'; 
    44     my $body    = $self->templatize($context, $feed, $item); 
    45     $self->do_send_mail($context, $feed, $subject, $body); 
    46 
    47  
    48 sub do_send_mail { 
    49     my($self, $context, $feed, $subject, $body) = @_; 
    50  
    51     $body = $self->htmlize($body); 
     25    my $body = $self->templatize($context, $feed); 
    5226 
    5327    my $cfg = $self->conf; 
     
    6640        Type => 'multipart/related', 
    6741    ); 
     42 
    6843    $msg->attach( 
    6944        Type => 'text/html; charset=utf-8', 
     
    8459} 
    8560 
    86 sub htmlize { 
    87     my($self, $body) = @_; 
    88     return <<HTML; 
    89 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    90 <html> 
    91 <head> 
    92 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
    93 </head> 
    94 <body> 
    95 $body 
    96 </body> 
    97 </html> 
    98 HTML 
    99 } 
    100  
    10161sub templatize { 
    102     my($self, $context, $feed, $item) = @_; 
     62    my($self, $context, $feed) = @_; 
    10363    my $tt = $context->template(); 
    10464    $tt->process('gmail_notify.tt', { 
    10565        feed => $feed, 
    106         item => $item, 
    107         cfg  => $self->conf, 
    10866    }, \my $out) or $context->error($tt->error); 
    10967    $out; 
  • trunk/plagger/templates/plugins/gmail_notify.tt

    r10 r34  
     1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
     2<html> 
     3<head> 
     4<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
     5</head> 
     6<body> 
     7[% FOREACH entry = feed.entries -%] 
    18<div> 
    29<div> 
    310[% IF feed.image %]<a href="[% feed.image.link %]"><img style="border:0" align="right" src="[% feed.image.url | html %]" alt="[% feed.image.title | html %]" /></a>[% END %] 
    4 [% IF cfg.group_items %]<strong style="font-weight:bold;font-size:1.2em">[% item.title %]</strong><br />[% END %] 
    5 [% SET link = item.link || item.id -%] 
     11<strong style="font-weight:bold;font-size:1.2em">[% entry.title %]</strong><br /> 
     12[% SET link = entry.link || entry.id -%] 
    613Link: <a href="[% link | html %]">[% link | html %]</a><br /> 
    7 [% IF item.author %]by [% item.author | html %][% END %][% IF item.tags.size %] on [% item.tags.join(',') %][% END %]</div> 
    8 [% IF item.body -%] 
    9 [% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div style="padding: 1em 0">[% item.body %]</div>[% END %] 
     14[% IF entry.author %]by [% entry.author | html %][% END %][% IF entry.tags.size %] on [% entry.tags.join(',') %][% END %]</div> 
     15[% IF entry.body -%] 
     16[% IF entry.body.match('(?i)^<p[ >]') %][% entry.body %][% ELSE %]<div style="padding: 1em 0">[% entry.body %]</div>[% END %] 
    1017[% ELSE %]<br />[% END %] 
    11 <div style="font-size:0.8em">[% IF item.date %]Posted on [% item.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% feed.title | html %]</a>[% FOREACH widget = item.widgets %] | [% widget.html(item) %][% END %]<br clear="all" /></div> 
     18<div style="font-size:0.8em">[% IF entry.date %]Posted on [% entry.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% feed.title | html %]</a>[% FOREACH widget = entry.widgets %] | [% widget.html(entry) %][% END %]<br clear="all" /></div> 
    1219</div> 
     20[% UNLESS loop.last %]<hr />[% END %] 
     21[%- END %] 
     22</body> 
     23</html>