Changeset 909
- Timestamp:
- 06/06/06 17:44:26
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Publish/Maildir.pm
r795 r909 11 11 use File::Find; 12 12 13 our $VERSION = '0.2'; 14 13 15 sub register { 14 16 my($self, $context) = @_; 15 $self->{version} = '0.1';16 17 $context->register_hook( 17 18 $self, … … 67 68 my $body = $self->templatize($context, $args); 68 69 my $from = 'plagger@localhost'; 70 my @enclosure_cb; 71 if ($self->conf->{attach_enclosures}) { 72 for my $entry ($args->{feed}->entries) { 73 push @enclosure_cb, $self->prepare_enclosures($entry); 74 } 75 } 69 76 my $now = Plagger::Date->now(timezone => $context->conf->{timezone}); 70 77 $msg = MIME::Lite->new( … … 81 88 Encoding => 'quoted-printable', 82 89 ); 90 for my $cb (@enclosure_cb) { 91 $cb->($msg); 92 } 83 93 $msg->add('X-Tags', encode('MIME-Header',join(' ',@{$entry->tags}))); 84 my $xmailer = "MIME::Lite (Publish::Maildir Ver.$self->{version} in plagger)";94 my $xmailer = "MIME::Lite (Publish::Maildir/$VERSION in Plagger/$Plagger::VERSION)"; 85 95 $msg->replace('X-Mailer',$xmailer); 86 96 my $filename = md5_hex($entry->id_safe); 87 97 store_maildir($self, $context,$msg->as_string(),$filename); 88 98 $self->{msg} += 1; 99 } 100 101 sub prepare_enclosures { 102 my($self, $entry) = @_; 103 104 if (grep $_->is_inline, $entry->enclosures) { 105 # replace inline enclosures to cid: entities 106 my %url2enclosure = map { $_->url => $_ } $entry->enclosures; 107 108 my $output; 109 my $p = HTML::Parser->new(api_version => 3); 110 $p->handler( default => sub { $output .= $_[0] }, "text" ); 111 $p->handler( start => sub { 112 my($tag, $attr, $attrseq, $text) = @_; 113 # TODO: use HTML::Tagset? 114 if (my $url = $attr->{src}) { 115 if (my $enclosure = $url2enclosure{$url}) { 116 $attr->{src} = "cid:" . $self->enclosure_id($enclosure); 117 } 118 $output .= $self->generate_tag($tag, $attr, $attrseq); 119 } else { 120 $output .= $text; 121 } 122 }, "tag, attr, attrseq, text"); 123 $p->parse($entry->body); 124 $p->eof; 125 126 $entry->body($output); 127 } 128 129 return sub { 130 my $msg = shift; 131 132 for my $enclosure (grep $_->local_path, $entry->enclosures) { 133 my %param = ( 134 Type => $enclosure->type, 135 Path => $enclosure->local_path, 136 Filename => $enclosure->filename, 137 ); 138 139 if ($enclosure->is_inline) { 140 $param{Id} = '<' . $self->enclosure_id($enclosure) . '>'; 141 $param{Disposition} = 'inline'; 142 } else { 143 $param{Disposition} = 'attachment'; 144 } 145 146 $msg->attach(%param); 147 } 148 } 149 } 150 151 sub generate_tag { 152 my($self, $tag, $attr, $attrseq) = @_; 153 154 return "<$tag " . 155 join(' ', map { $_ eq '/' ? '/' : sprintf qq(%s="%s"), $_, encode_entities($attr->{$_}, q(<>"')) } @$attrseq) . 156 '>'; 89 157 } 90 158 … … 98 166 }, \my $out ) or $context->error($tt->error); 99 167 $out; 168 } 169 170 sub enclosure_id { 171 my($self, $enclosure) = @_; 172 return Digest::MD5::md5_hex($enclosure->url->as_string) . '@Plagger'; 100 173 } 101 174 … … 130 203 maildir: /home/foo/Maildir 131 204 folder: plagger 205 attach_enclosures: 1 132 206 133 207 =head1 DESCRIPTION
