I recently made a website for a local church. They wanted to be able to post new "blessings" to their web page, but didn't want to have to edit the web site or know any HTML. I asked if they knew how to send an email, and they said that this was a do able task.

Using a mail box on their server and a cron job I put in this script which gathers the "blessing" from the email box, and shooves it into a data base. From there the web page gets the informatin from the database (mysql in this case with a PHP page).

I' sure most of you do this type of thing all the time, but I thought it was such a cool little service to offer those who can't do more than send an email, a method of getting more out of their website and having a bit a fun at the same time.

Here's the script I used for the mail box. Any commet, as always, is welcome.
#! /usr/bin/perl -w use strict; use File::Spec; use Mail::MboxParser; use DBI; my $dbh = DBI->connect('DBI:mysql:blessing:webadept.net', 'yourusername', 'yourpassword', undef); chdir("/var/spool/mail"); my $mail = File::Spec->catfile('blessing'); my $mb = Mail::MboxParser->new($mail); my @a = $mb->get_messages; my $mailbox = 'blessing'; open(IN,">$mailbox"); close(IN); foreach my $msg(@a) {< my $subject = $msg->header->{subject}; my $from = $msg->header->{from}; my $body = $msg->body->as_string; $body=$dbh->quote($body); $from=$dbh->quote($from); $subject = $dbh->quote($subject); my $q = qq`insert into blessings values( '', $subject, $body, current_date, $from, 1, '') `; my $sth2 = $dbh->prepare($q); $sth2->execute() || die "Failed on update : \n$q\n\n"; } #foreach message loop ends $dbh->disconnect;
webadept

--if its not fun, its not worth it --

Edit kudra, 2002-02-26 Replaced BR with CODE

Replies are listed 'Best First'.
Re: Mail Poster For website pages
by shotgunefx (Parson) on Feb 26, 2002 at 10:33 UTC
    Code aside, what happens if someone sends a mail, "Priests seeking young men for long walks, companionship and fun." or the get spammed with "Ej**tulate 600% more today!" (Seriously, I get a spam with that product every damn day.)

    At the very least, check to make sure to check the sender address and possibly a password in the subject or body. This is still weak and easy to circumvent but is better than nothing. Not trying to be harsh, just would hate for you to find out the hard way.

    Just a thought.

    -Lee

    "To be civilized is to deny one's nature."
•Re: Mail Poster For website pages
by merlyn (Sage) on Feb 26, 2002 at 15:13 UTC
    If they know how to visit a web page to see the blessing, they almost certainly can visit a slightly different URL (password protected) to add a blessing. Make it a web form.

    Trying to go from email to web is asking for trouble, both from a security perspective, and from people hellbent on making it ugly. Not to mention decoding all the MIME-encrusted email that's out there, with 37 settings for it all.

    -- Randal L. Schwartz, Perl hacker

      Excellent advice from merlyn above.

      If you're concerned about people having to type HTML into a web form, consider using Text::WikiFormat (alt. link) by our own chromatic. It makes HTML out of "wiki format" text, which should be pretty easy for even Joe Average to figure out. It allows making paragraphs, lists, etc., just by plain-text formatting.

        updateThis was supposed to be a reply to merlyn's message
        I was going to suggest your column on authenticated updates but for the less than technically savvy, PGP is a pain.

        -Lee

        "To be civilized is to deny one's nature."
Re: Mail Poster For website pages
by webadept (Pilgrim) on Feb 26, 2002 at 16:34 UTC
    Thanks for the Hints and Tips on the security front. I left all the boring checking stuff out of the post.

    Guess I should have left a note or something in there saying "security checking here" :-) Ah well.. still learning.
Re: Mail Poster For website pages
by baku (Scribe) on Mar 08, 2002 at 18:09 UTC

    Re: using a cron job...

    Most mail-delivery-agents allow you to set up a "magic" mailbox to run a script as well. E.G. you might have johndoe-blessing@church.org directed to execute your script on delivery. Examples include QMail and Procmail.

    This is just a more general case that would allow "any time" changes. We used to use a QMail-triggered script to check replies to certain automatic eMails, something like the forms you send to hostmaster@internic.net

Re: Mail Poster For website pages
by hsweet (Pilgrim) on Mar 19, 2002 at 03:13 UTC

    I did something similar for my school district, but it works with a web form. It produces the announcements at http://ghs.gcsny.org, among other places.

    It should be a bit more resistant to getting weird stuff posted since the part of the tree the script resides in reqires authentication. Also posts show up immediatly.

    I'll try to get around to posting the code one day as soon as I get this one teensy little bug figured out. It hasen't stopped it from working though

    Ignorance with Confidence