Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

PerlMonks pager

by ZZamboni (Curate)
on Sep 10, 2000 at 21:51 UTC ( [id://31805]=sourcecode: print w/replies, xml ) Need Help??
Category: Chatterbox Clients
Author/Contact Info Diego Zamboni (ZZamboni)
Description: I was thinking about this program during Friday, but it was a message from Adam that prompted me into action :-)

This program gets your personal messages from PerlMonks and displays or mails them to you. It can optionally check them off automatically. Typical use would be in a crontab entry like this:

0 * * * * $HOME/bin/ -m
To have it check every hour. It keeps a cache, so that every message is only displayed once. If you give it the -i option, it ignores the cache, and shows all the personal messages that you have. The -c option makes it automatically check off all the messages it displays.

This program is also part of the PerlMonksChat distribution.

eval 'exec perl -x $0 ${1+"$@"}' # -*-perl-*-
  if 0;
#!perl -w
# "Pager" for PerlMonks
# Gets personal messages and displays or mails them.
# Diego Zamboni, September 10, 2000
# $Id:,v 2000/09/10 17:44:20 zamboni Exp $

use strict;
use PerlMonks::Chat;
use Text::Wrap qw(wrap);
use Getopt::Long;
use Mail::Mailer;
use SDBM_File;
use Fcntl;

sub usage {
  return <<EOM;
Usage: $0 [options]
    --login user    -l user    User to login as. Only needed once, it
                               gets stored in a cookie
    --password pwd  -p pwd     Password to use (otherwise ask)
    --mailto addr   -m addr    Mail results (print to stdout by defaul
    --checkoff      -c         Check off new messages automatically
    --ignorecache   -i         Print all messages, even if they have
                               been seen before. By default it only sh
                   new messages
    --help          -h         This message

my $p=PerlMonks::Chat->new();

# Config options
my $user;
my $mailto;
my $passwd;
my $checkoff;
my $nocache;
my $help;

# Get command-line args
GetOptions('login|l=s' => \$user,
       'mailto|m=s' => \$mailto,
       'password|p=s' => \$passwd,
       'checkoff|c'   => \$checkoff,
       'ignorecache|i'  => \$nocache,
       'help|h'        => \$help,
  or die usage();

warn(usage()), exit if $help;

if ($user) {
  unless ($passwd) {
    print "Password? ";
  # Login
  $p->login($user, $passwd)
    or die "Login failure: $@\n";

# Open the cache.
my %cache;
tie(%cache, 'SDBM_File', "$ENV{HOME}/.pmpager", O_RDWR|O_CREAT,0640);

my $body="";
my @ids=();

# Get personal messages
my %msgs=$p->personal_messages;
foreach my $k (keys %msgs) {
  next if (!$nocache && exists($cache{$k}));
  $cache{$k}=1 unless $nocache;
  push @ids, $k;
  $body.=wrap("", "\t", $msgs{$k})."\n";
untie %cache;

# Print or send the messages
if ($mailto) {
  if ($body) {
    my $mailer=Mail::Mailer->new();
    $mailer->open({From    => $mailto,
           To      => $mailto,
           Subject => "Your new PerlMonks personal messages"
      or do {
    # This is so that if you execute this through crontab and
    # it fails, maybe you'll get your messages anyway.
    warn "Can't open Mail::Mailer object.\n";
    warn "Your new personal messages are:\n$body";
    die "Terminating.\n";
    print $mailer $body;
    if ($checkoff) {
      print $mailer "\nThese messages have been checked off.\n";
else {
  if ($body) {
    print "Your new PerlMonks personal messages:\n$body";
    if ($checkoff) {
      print "\nThese messages have been checked off.\n";
  else {
    print "No new personal messages.\n";

# Check off the messages if necessary. We do this last so that
# if anything fails, the messages are not checked off.
$p->checkoff(@ids) if @ids && $checkoff;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://31805]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-07-21 02:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.