Testing Perl Support for Google SyntaxHighlighter

Note that this post is no longer formatted as it states below.

I've been enjoying playing with Google's SyntaxHighlighter. Another user came up with a Perl brush file, so I thought I'd give it a shot. One note from the author of the brush file is that -> gets converted to -> rather than being translated properly. It's definitely the highlighter that does it, too, because when you disable the brush it shows up properly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl

use strict;
use Mail::Box::Manager;

#################################
# User Variables
#
# Set $password to your password (encoded):
# . only the low four bits of each character count
# . character 0x3f gets split into 0x?3 and 0x?f,
# . fill in the ?'s with anything you like
# . man ascii =)
#

my $server = 'pop.server.name';
my $username = 'username';
my $password = 'tSvx6!f>v7V%d=fU'; # the word "ChangeMe" encoded

#################################
# Get em!
#

my $mgr = Mail::Box::Manager->new;
my $pop = $mgr->open(type => 'pop3',
username => $username,
password => decodePassword($password),
server_name => $server);

my @messages = $pop->messages;

print
"33[00;30;1m:33[00;36m:33[00;36;1m: ", scalar @messages, " messages in mailbox :33[00;36m:33[00;30;1m:33[mn";

foreach my $message (@messages) {
    my $fr = $message->get('From');
    $fr =~ s/s+< .*$//; $fr =~ s/"//g;

    printf "33#733[1m %-28.28s %-45.45s33[0mn", $fr, $message->get('Subject');
    my $lbls = $message->labels;
    while( my ($k, $v) = each %$lbls ) {
        print "key: $k, value: $v.n";
    }
}

$pop->close;

#################################
# methods
#

sub decodePassword($) {
    my ($password_split) = @_;
    my $password = "";
    my ($high, $low);

    $password_split = reverse($password_split);
    while (length($password_split) > 1) {
        $high = (ord(chop($password_split)) & 0xf) < < 4;
        $low = ord(chop($password_split)) & 0xf;
        $password .= chr($high|$low);
    }

    return $password;
}

About three years ago I was living in the shell. I had a script aliased to m that would run a perl script for each of my IMAP accounts and show me all of the unread messages. The script had been originally written by a fellow Help Desk supervisor at UB and then given colorization support by another fellow supervisor, Doug, who has since become a perl and python guru.

The trouble then was that, while this worked for my home email server, I had to change some of the socket code to work on all of the other IMAP servers I used. That wasn't too tough since IMAP is a relatively straightforward protocol. Getting POP support to work looked to be a lot harder, however. I couldn't find anyone that had written something similar for me to hack, so I wrote my own.

This script above uses the perl module Mail::Box which installs straight out of CPAN. It's probably been updated since this was written, and I don't even know if the script still works (who still uses POP??).

Jan 28th, 2008

Comments