#!/usr/bin/perl -w # # treocentral_wmexperts_notification # # AUTHOR: # Dan Harkless # # COPYRIGHT: # This file is Copyright (C) 2008 by Dan Harkless, and is released under the # GNU General Public License . # # USAGE: # % treocentral_wmexperts_notification [-mobilize] [-treoize] # [-truncsubj []] [-wmize] # # DESCRIPTION: # Takes a treocentral.com or wmexperts.com "Reply to post" or "New Private # Message" email on stdin and filters it to contain just the new post / # private message URL, so that when an SMS notification of the email is sent # to you by my sms_biff script (or equivalent), you'll be able to browse to # the thread / private message directly from the SMS message on your Treo (or # equivalent). See the commandline options below for the details. # # For an example of how to call this from your .procmailrc (in conjunction # with sms_biff), see the treocentral_wmexperts_notification entry on my # Software page (first URL above). # # COMMANDLINE OPTIONS: # -mobilize # Normally the new post / PM URL we output points to the normal desktop # version of treocentral.com or wmexperts.com, but if this option is # specified, we'll output a link to the mobile site instead. # # -treoize # treocentral.com notifications randomly come from and point to # wmexperts.com sometimes, and vice-versa. And both of those sometimes show # up from smartphoneexperts.com. This option will rewrite the URL to be on # treocentral.com, so you'll have the correct site skin and links. # # -truncsubj [] # On "Reply to post" subjects, removes that text. In other words, the # subject becomes just the subject of the discussion board thread. # # Also, the Subject contents is truncated to characters, to prevent # overly long ones from causing the URL to be truncated in the SMS. If this # option is specified with no "" value, it defaults to 50. # # -wmize # The opposite of -treoize -- changes links to point to wmexperts.com. # # DATE MODIFICATION # ========== ================================================================== # 2008-09-02 "use English qw(-no_match_vars)": avoid regex performance penalty. # 2008-08-03 Support "digest"-type notifications in addition to instant. # 2008-07-31 Renamed to treocentral_wmexperts_notification, dropping support # for visorcentral.com, where new posts are no longer allowed, and # adding support for the new wmexperts.com. Some notifications # randomly have forum.smartphoneexperts.com URLs, so added support # for rewriting those. Updated to latest notification email format # (including preserving the newly present subjects of PMs). Changed # -truncsubj default to 50. # 2003-03-01 Original (TreoVisorCentral_notfication). ## Modules used ################################################################ use English qw(-no_match_vars); # allow use of names like @ARG rather than @_ use Getopt::Long; # for GetOptions() use File::Basename; # for basename() ## Main ######################################################################## $progname = basename($PROGRAM_NAME); # Eliminate "used only once" warnings: use vars qw($opt_mobilize $opt_treoize $opt_truncsubj $opt_wmize); if (!GetOptions("mobilize", "treoize", "truncsubj:i", "wmize")) { print STDERR "Usage: $progname [-mobilize] [-treoize]\n", " [-truncsubj []] [-wmize]", "\n"; exit 1; } if ($opt_treoize and $opt_wmize) { print STDERR "$progname: -treoize and -wmize are mutually exclusive.\n"; exit 1; } if (defined($opt_truncsubj) and $opt_truncsubj == 0) { $opt_truncsubj = 50; } $in_header = 1; $PM_subject = ""; while () { if ($in_header) { if ($opt_truncsubj and /^Subject: *(.*)$/) { $subject = $1; $subject =~ s/Reply to post '(.*)'/$1/; print "Subject: ", substr($subject, 0, $opt_truncsubj), "\n"; } else { print; if (/^$/) { $in_header = 0; } } } elsif (/entitled "(.*)"\.$/) { $PM_subject = $1; } elsif (/^(http:.+?(private\.php|showthread\.php.+?post).*)$/) { $URL = $1; if ($opt_treoize) { $URL =~ s/forum.smartphoneexperts/discussion.treocentral/; $URL =~ s/wmexperts/treocentral/; } elsif ($opt_wmize) { $URL =~ s/forum.smartphoneexperts/discussion.wmexperts/; $URL =~ s/treocentral/wmexperts/; } if ($opt_mobilize) { $URL =~ s/discussion\.treocentral/treo.discussion.treocentral/; $URL =~ s/discussion\.wmexperts/mobile.discussion.wmexperts/; } print "$URL\n"; # Ideally it'd be nice to relocate this to the email Subject, but we'd # have to change things around to not act as a just-in-time filter. # Instead, put it after the URL, so we at least get automatic truncation # of the PM subject rather than the URL. if ($URL =~ /private\.php/) { print "\n$PM_subject\n"; } # Don't try to include any subsequent URLs, as they'd get truncated. exit 0; } }