1 # Blosxom Plugin: metamail
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
4 # Documentation: 'perldoc metamail'
12 #use Blosxom::Debug debug_level => 1;
14 # --- Configurable variables -----
16 # Headers to consider titles
17 my @title_headers = qw(Title Subject);
19 # Headers to keep in the body (required by later plugins, for instance)
20 my @keep_in_body_headers = qw(Tags);
22 # Whether to unfold (join) multi-line headers
23 my $unfold_headers = 1;
25 # --------------------------------
30 my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
33 my ($headers, $body) = split /\n\s*\n/, $$title_ref . "\n" . $$body_ref, 2;
35 my $meta = \%blosxom::meta;
38 for my $header ( split /\n(?=\S)/, $headers ) {
39 # Split header into key/value
40 my ($key, $key2, $value);
41 if ($header =~ m/:/) {
42 ($key, $value) = split /:\s*/, $header, 2;
44 # For backwards compatibility, assume a header without a : is a title
46 $key = @title_headers[0] || 'Title';
52 $value =~ s/\n //g if $unfold_headers;
55 $header{$key} = $value;
57 # Insert into meta namespace
58 $meta->{$key} = $value;
59 # debug(1, "metamail: $key: " . $meta->{$key} . "\n");
60 # Insert lowercase/underscored version as well
61 ($key2 = lc $key) =~ s/-/_/g;
63 $meta->{$key2} = $value;
64 # debug(1, "metamail: $key2: " . $meta->{$key2} . "\n");
68 # Update $$title_ref to the first title_header we can find
70 for (@title_headers) {
71 $$title_ref = $header{$_} and last if $header{$_};
75 if (my @keep_headers = grep { defined $header{$_} } @keep_in_body_headers) {
76 $$body_ref = join("\n", map { "$_: $header{$_}" } @keep_headers) . "\n" . $body;
91 metamail - an alternative to Rael's original L<meta> plugin, supporting
92 mail/RFC822-style headers in posts
96 metamail is a plugin for loading metadata from the 'headers' in a
97 blosxom post. Metadata is loaded into a %blosxom::meta hash (instead of
98 into package variables like L<meta>). metamail expects posts to look like
99 RFC822-style mails i.e. a bunch of headers, where a header is a key (no
100 whitespace) followed by a colon followed by a value; then an empty line
101 as a separator; and then the post body.
103 metamail loads all headers it finds as variables into the %blosxom::meta
104 hash. It typically creates two entries for each header: the first is named
105 exactly as the key is given in the header, and the second is the key
106 converted to lowercase, and with dashes converted to underscores.
108 So given the following headers:
112 URL: http://www.openfusion.net/
114 metamail will create the following %blosxom::meta entries:
116 $blosxom::meta{Title} = 'Test Post 1';
117 $blosxom::meta{title} = 'Test Post 1';
118 $blosxom::meta{Tags} = 'test, ignore';
119 $blosxom::meta{tags} = 'test, ignore';
120 $blosxom::meta{URL} = 'http://www.openfusion.net/';
121 $blosxom::meta{url} = 'http://www.openfusion.net/';
123 For backwards compatibility purposes, L<metamail> will treat any header
124 not containing a colon (which is typically the first line title) as the
125 'Title' of the post, and store it with the first key in @title_headers
126 (default is 'Title'). L<metamail> supports the title being anywhere in
127 the headers, and will report it properly to blosxom, but any plugins
128 that look directly at the post file may still expect the title
129 (without a key) to be there in the first line, so that is currently
130 still the recommended convention.
134 This plugin requires the L<metaclear> plugin to reset the %blosxom::meta
135 hash for each story, and should be loaded early, after L<metaclear>, but
136 typically before all other story plugins e.g. as 05metamail.
138 This is an *alternative* to the L<meta> plugin, so should usually be used
139 _instead_ of L<meta>, not as well.
143 L<metaclear>, L<metadir>, L<metafile>.
145 L<meta>, Rael Dornfest's original metadata plugin
147 Blosxom: http://blosxom.sourceforge.net/
151 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
155 Copyright 2007, Gavin Carr.
157 This plugin is licensed under the same terms as blosxom itself i.e.
159 Permission is hereby granted, free of charge, to any person obtaining a
160 copy of this software and associated documentation files (the "Software"),
161 to deal in the Software without restriction, including without limitation
162 the rights to use, copy, modify, merge, publish, distribute, sublicense,
163 and/or sell copies of the Software, and to permit persons to whom the
164 Software is furnished to do so, subject to the following conditions:
166 The above copyright notice and this permission notice shall be included
167 in all copies or substantial portions of the Software.
169 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
170 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
172 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
173 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
174 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
175 OTHER DEALINGS IN THE SOFTWARE.