procmail
[Top] [All Lists]

Re: "moblog" script

2005-05-18 15:35:49
At 01:04 PM 5/18/2005 -0800, ryan S. wrote:
Does anyone know of a script package using procmail and php/mysql which
would allow me to run a "moblog" (blog that gets updated via emails)? -ryan


I slapped a simple sql-based blogger together a few years ago, and for simplicity of use, I set it up to be maintained via a submission page. That meant that the blog retrieval (which was web-based) and blog updating could use the same shared codebase AND I didn't need to author a separate tool to post into the db (though I could if I wanted to).

For flexibility on my part, esp as it pertains to drafting journal entries, I use email to post - so I scrawled together a procmail script to take a plain text message and post it into the blog.

Caveat: I'm not posting the PHP code for the blogger itself. The explanation is below.


# If you have multiple addresses, specify this as the address which you
# send blog entries to.
BLOGID="addresss(_at_)host(_dot_)domain(_dot_)tld"

:0
* $ ^TO_$\BLOGID
{
        # copy to inbox (so I have a tangible email record of my own
        # submissions).  Optional.
        :0c:
        | formail -A"${XMBHEAD} BLOG" >> $DEFAULT

        # copy to archive file.  Optional.
        :0c:
        |gzip -9fc >> blog.gz

        # copy to blog
        :0
        {
                # set UMASK here.  yes, we're making created files WORLD
                # accessible.  This is so that the web process has free
                # access to the file.  YES, this poses a security issue if
                # you are publishing private data to the blog (say if the blog
                # were password protected and the public didn't have free
                # access to it) - this isn't an issue for my blogging.  More
                # an issue is that for the brief existance of the temp file,
                # the user blog password can be found in there...
                UMSAVE=$UMASK
                UMASK=000

                # copy to unique file for blogger.  We do this in /tmp
                # so that we don't have to diddle permissions in our home dir.
                # this gives us a unique filename.  We use the copy flag so
                # that we can perform multiple standalone commands after the
                # apparent delivery.
                :0cw
                /tmp

                TEMPFILE=$LASTFOLDER

                BOGUS=`lynx -dump http://webhost.domain.tld/blog.php?Upload
edBlog=$TEMPFILE > /dev/null`

                BOGUS=`rm $TEMPFILE`

                # restore the umask - not really necessary since we're going
                # to terminate when we deliver the excess copy to the ether,
                # but I like to be complete...
                UMASK=$UMSAVE
                UMSAVE

                :0
                /dev/null
        }
}

The blogging script takes the LOCAL file and provides the path of it to the blogger. This means the webserver needs to be on the same host as the mail host. I originally had intended to set it up to do POSTDATA (to mimic a web form posting), but couldn't sort out how to get lynx or any other readily available tool to do that - if I had to invest the additional time to deal with that, I'd have just written a Perl app to interract with the db itself.

The email has simple password and keyword 'headers' at the top of the body. The blogging script checks the password against what the user should have, otherwise the post isn't processed into the blog (note that there's no feedback mechanism for such a failure). The keywords are used to take my singular blog database and use it in multiple blogs - I have one for my son's development, automotive, beekeeping, general rants, some social stuff, a personal log, etc. Not all are intended for public consumption.

Message datestamp and the subject are grabbed and used by the blogger. Here's an example of the output:


<http://beekeeping.professional.org/>

The PHP for the blog is included into the site-specific blog, and then the non-interactive blog output is obtained thus:

<?PHP blog_fetch( "blog_db", "bloguser", "access_pw", "BLOG_KEYWORD", "sql_age_select", "colour_scheme", max_entries ); ?>


The blog script on the webserver uses a number of proprietary components (non-critical to blog operation, but quite basic to the scripts design), so I'm not in a position to post the PHP blogger code right now without spending some time genericizing it (besides, this isn't a PHP forum). The procmail code above though should provide you with a ready way to submit entries to a blog if you roll your own. I had intended to spend more time developing the blog capabilities (date range selection via a mini calendar, topical crosslinks, etc), but for me, having multiple keyword-based blogs and displaying the most recent 'x' or nothing older than 'x' days was sufficient for my immediate needs, and that is where it's been for a few years.

URLS in the message body - when bracketed like <http://www.procmail.org/> get converted to a link via a few regexp replacement operations in the blog script.


---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>