Keitai Blogging - the gory details

The implementation was based on the usual sources; the man pages, the net, and the O'Reilly Perl books. Thanks to the ever competent and helpful sysadmins over at Speakeasy who helped me realize that the incoming mail handler had changed when stuff suddenly stopped working.

These files and approach do not take security into account - this was not for general use.

Relevant Files

.qmail

|preline procmail

.procmailrc
(there's an implicit filter here for mail from "ian" - we just edited to change...)

MONTHFOLDER=`date +%y-%m`
DUMMY=`test -d $MONTHFOLDER || mkdir $MONTHFOLDER`
:0:
* ian
| mhstore -file -:0 c
backup

.mh_profile

nmh-storage: mail_in
mhstore-store-text: | ../mail_scripts/save_txt %m%P.txt ; sleep 1
mhstore-store-text: +mail_in
mhstore-store-image/jpeg: | ../mail_scripts/save_jpg %m%P.jpg ; sleep 1
mhstore-store-image/jpeg: +website

save_txt

#!/bin/sh
# want to save the stuff from stdin to to a file with a name based on time
DATE_NAME=`date +%Y_%m_%d_%H_%M_%S_`
FILE_NAME="$DATE_NAME$1"
cat - > "$FILE_NAME"
chmod a+r "$FILE_NAME"

save_jpg

#!/bin/sh -x
# want to save the stuff from stdin to to a file with a name based on time
DATE_NAME=`date +%Y_%m_%d_%H_%M_%S_`
FILE_NAME="../website/mail_images/$DATE_NAME$1"
THUM_NAME="../website/mail_images/thumbnails/$DATE_NAME$1"
cat - > $1
# then make a scale copy of
convert -bordercolor black -border 2x2 $1 bk"$1"
convert -bordercolor white -border 1x1 bk"$1" "$FILE_NAME"
convert -geometry 100x100 -quality 9 -bordercolor black -border 2x2 "$FILE_NAME"
"$THUM_NAME"
# make so can read from web server
rm $1 bk"$1"
chmod a+r "$FILE_NAME" "$THUM_NAME"

CGI Script that Creates the Blogg Page from the stored messages
(Formatting is not ideal here - appologies...)

#!/usr/bin/perl -wT
# #!/usr/bin/perl -wT

use strict;
use CGI qw( :standard );
use CGI::Pretty;
use CGI::Carp qw( fatalsToBrowser );
my $DOC_ROOT = $ENV{DOCUMENT_ROOT};

my $q = new CGI;

print $q->header ( -type => "text/html", -expires => "+15s" );
print $q->start_html("Welcome");
print $q->h1 ( $q->img( {-align => "middle", -src => "./ian.jpg" }, "Ian test page" )) ;
print $q->hr;

use DirHandle;
use FileHandle;
my $msg_dir = "../mail_in";
my $img_dir = "./mail_images";

# Get a list of all the files that are in the messages directory
# print $q->p( "$msg_dir" );
my $dh = DirHandle->new($msg_dir);
my @mhmsgs = sort grep { /^\./ && -f } map { "$msg_dir/$_"} readdir $dh;
closedir $dh;
# print $q->p( "@mhmsgs" );

# Now get a list of all the images we have
# print $q->p( "$img_dir" );
my $di = DirHandle->new($img_dir);
my @imagelist = sort grep { /^\./ && -f } map { "$img_dir/$_"} readdir $di;
# my @imagelist = readdir $di;
closedir $di;
# print $q->p( "@imagelist" );

# use File::stat;
# my @filetimes = map { (stat($_))->mtime } @mhmsgs;
# print $q->p( "@filetimes" );

print $q->hr;

my $name = "none";
my $pict = "none";
my $mhkey = "none";
my $images = "none";
my $cur_date = "none";
foreach $name (@mhmsgs) {
# if date has changed...
# if (( $cur_date =~ "^none$" ) || ( $cur_date != substr($name,11,19) ) {
# HR and then show the date
# put in a marker and href to go to the next or prior date
# now go through the mail messages and see what to do with them
if ($name =~ /txt$/) {
# print $q->p( "Try to open $name" );
# This displays the text of this email message
open FILE, "$name" or die "Couldnot open $name" ;
# print $q->p( "$name" );
# print <FILE>;
# close FILE;
#
# see if this text has an image file associated with it
$mhkey = substr($name,31); # lenght of ../mail_in/date...
$mhkey = substr($mhkey,0,-6); # cuts of 3.txt (won't work >9)
# print $q->p( "Try to find image called $mhkey" );
$pict = "none";
foreach $images (@imagelist) {
# print $q->p( "test $images");
if ($images =~ /jpg$/) {
# print $q->p( "jpg $images");
if ($images =~ /$mhkey/) {
# $images =~ s/mail_images/mail_images\/thumbnails/;
# print $q->p( "there is it's $images");
print $q->br( {-clear => "all"} );
print $q->h2( $q->img( {-align => "left", -src => "$images" }, <FILE> ) );
}
}
}
if ($pict =~ /^none$/ ) {
print $q->br( {-clear => "all"} );
print <FILE>;
}
close FILE;
}
# if ($name =~ /jpg$/) {
# $pict = $name;
# $pict =~ s/\.\.\/mail_in\/// ;
# print $q->p( "Try to image $pict" );
# print $q->img( {-align => "middle", -src => "$pict" }, "testimag
e" );
# }
}

#
$q->end_html;