[mew-int 01042] "To" field in scan listing?

d.gonzalez at example.com d.gonzalez at example.com
Sat Aug 3 05:50:29 JST 2002


Hello,
	I just upgraded from Mew version 1.94.2 to version 2.2.  I love the new
version, but I'm missing three things that I used to get with 1.94.

	I had created an IM scan.sbr Perl file to allow me to see who the
message is to, the day of the week of the message, and to allow me to see just
the username part of the To: and From: email addresses.  For example, here is a
sample of output from imls:

    1 Fri 2002/08/02 15:00   1K   mail-alias   my-boss     RE: New VT100 systems
    2 Fri 2002/08/02 15:28   1K   d.gonzalez   my-friend   imls output

      ^^^                         ^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
      Day of the week             To           From        Subject

But the closest I can get with the current Mew is

    1  2002/08/03 03:56   7k emailharvest at example.com [mew-dist 21392] ADV: Harvest lots
 o  o <200208021957.OAA20940 at example.com> <>    of 

So the differences are that I can't get the day of the week, nor who the
message is from, and I can't clean up the To and From addresses.

	I've attached the scan.sbr file that gives me these capabilities.  I'm
an OK Perl programmer, but don't know much Lisp or ELisp.  Can someone help by
coding or giving me pointers on coding this kind of stuff up into ELisp.  I'd
love to contribute these additions to the main Mew distributions, but don't
know enough to do it myself.  Thanks.

===============================================================================
 Daniel C. Gonzalez                              University of Texas at Austin
 Information Technology Services                                (512) 475-9360
 d.gonzalez at example.com                 http://uts.cc.utexas.edu/~gonzalez/
-------------- next part --------------
# -*-Perl-*-

#
# My 1st attempt to extend the imls output to give me fields that don't exist
# by default.  This file is written in Perl.
#

use Mail::Address;		# from the Perl Mail::Tools modules.  I want to
                                # use the user() method.

###############################################################################
# First I define the new header-types that I want to be able to use in my scan
# Form (defined in my ~/.im/Config).  I create my own custom '%{from_user}',
# '%{to_user}', '%{scaled_size}', and '%{week_day}' header-types.
#

# Define the %{from_user} header-type, which is the simple username for the
# sender. To use it, you should use %{from_user} (%W) in your scan Form instead
# of %f, %a, %P, etc.

$symbol_table{'{from_user}'} = 'from_user:';
$symbol_table{'W'} = 'from_user:';

# Define the %{to_user} header-type, which is the simple username for the
# recipient.  To use it, you should use %{to_user} (%X) in your scan Form
# instead of %t, %A, %g, etc.

$symbol_table{'{to_user}'} = 'to_user:';
$symbol_table{'X'} = 'to_user:';

# Define the %{scaled_size} header-type, which is the size of the message, but
# scaled so that it fits in a 4 character width field, and has K/M/G (for
# Kilobytes, Megabytes or Gigabytes) appended to the output. To use it, you
# should use %{scaled_size} (%Y) in your scan Form instead of %B, %K, %g, etc.
# Note that we round to the nearest K, or tenth of a Meg/Gig when we scale...

$symbol_table{'{scaled_size}'} = 'scaled_size:';
$symbol_table{'Y'} = 'scaled_size:';

# Define the %{week_day} header-type, which is the day of the week from the
# Date: header.  To use it, you should use %{week_day} (%Z) in your scan Form.

$symbol_table{'{week_day}'} = 'week_day:';
$symbol_table{'Z'} = 'week_day:';

###############################################################################
#
# Now I declare the routine that creates the header-types.  The order in which
# the headers are created doesn't matter, because this routine is just adding
# entries to associative arrays that are used later...
#

sub scan_sub {
    local ($href) = shift;
    my($temp_header, $temp_obj, $num_bytes);
    my(@from_list) = (		# Order is important here
		      'from',
		      'sender',
		      'return-path',
		     );
    my(@to_list) =   (		# Order is important here
		      'to',
		      'apparently-to',
		      'x-envelope-to',
		      'newsgroups',
		     );

    # Create the from_user header.

    foreach $temp_header (@from_list ) {
	next unless defined($href->{$temp_header});
	$temp_obj = (Mail::Address->parse($href->{$temp_header}))[0];
	next unless defined($temp_obj);
	$href->{'from_user:'} = $temp_obj->user;
	last;
    }
    $href->{'from_user:'} = 'From?'
	if ( ! defined($href->{'from_user:'})
	     || $href->{'from_user:'} =~ m/^\s*$/ );
    $href->{'from_user'} = $href->{'from_user:'};
    $href->{'Da'} = $href->{'from_user:'};

    # Create the to_user header.

    foreach $temp_header (@to_list ) {
	next unless defined($href->{$temp_header});
	$temp_obj = (Mail::Address->parse($href->{$temp_header}))[0];
	next unless defined($temp_obj);
	$href->{'to_user:'} = $temp_obj->user;
	last;
    }
    $href->{'to_user:'} = 'To?'
	if ( ! defined($href->{'to_user:'})
	     || $href->{'to_user:'} =~ m/^\s*$/ );
    $href->{'to_user'} = $href->{'to_user:'};
    $href->{'Db'} = $href->{'to_user:'};

    # Create the scaled_size header.

    if (! defined($href->{'path'})) { # We need a path for Perl's stat()...

	if ( defined($href->{'folder'}) && defined($href->{'number'}) ) {

	    # Assume we are being called from imget, which doesn't create an
	    # $href->{'path'}.  So we cheat and define an $href->{'path'}.

	    eval('use IM::Folder') unless defined(&get_message_paths);

	    $href->{'path'} = (get_message_paths($href->{'folder'},
						$href->{'number'} ))[0];

	} else {		# Give up, print diagnostics, and return

	    my($header);
	    print(STDERR "\n Can't figure out path to message for stat.\n");
	    print(STDERR "\n The keys of the hash contains:\n");
	    foreach $header (keys(%$href)) {
		print(STDERR $header, ' -> ', $href->{$header}, "\n");
	    }
	    print(STDERR "\n");
	    return;
	}
    }

    $num_bytes = -s $href->{'path'}; # NOTICE: No colon in header name

    if ($num_bytes !~ m/^\s*\d+\s*$/) {
	print(STDERR "\n Couldn't stat $href->{'path'}.\n");
	return;
    }

    if ($num_bytes < 1024) {	# If less than 1K, show size in bytes

	# do no conversion, append no suffix to the byte count

    } elsif ($num_bytes < 1048576) { # If less than 1M, show size as nK

	$num_bytes = sprintf("%3dK", ($num_bytes + 512) / 1024);

    } elsif ($num_bytes < 1073741824) { # If less than 1G, show size as nM

	$num_bytes = sprintf("%4.1fM", ($num_bytes) / 1048576);

    } else {			# Show size as nG

	$num_bytes = sprintf("%4.1G", ($num_bytes) / 1073741824);
    }
    $num_bytes =~ s/^\s*//;
    $href->{'scaled_size:'} = $num_bytes;
    $href->{'scaled_size'} = $num_bytes;
    $href->{'Dc'} = $num_bytes;

    # Create the from_user header.

    unless ( defined($href->{'week_day:'}) ) {

	# $href->{'date:'} is just the numeric MM/DD

	# $href->{'date'} is the entire date string from the Date: header.  It
	# should contain a 3 character day of the week.  I match against the 3
	# character string anywhere on the line to guard against Date: lines
	# with mutant strings.  I don't care *where* on the line the week day
	# string is, I just care *what* it is.  ('We have some days of the
	# week' -- Dogbert)

	( $href->{'week_day:'} )
	    = ($href->{'date'} =~ m/(Sun|Mon|Tue|Wed|Thu|Fri|Sat)/i);
	$href->{'week_day'} = $href->{'week_day:'};
	$href->{'Dd'} = $href->{'week_day:'};

    }

# Debugging print statements.  Will print once for every line of scan input
#    print(STDERR "\nMy scan_sub ran. From=$href->{'from_user:'},",
#	  " To=$href->{'to_user:'}, Size=$href->{'scaled_size:'},",
#	  " WDay=$href->{'week_day:'}\n");
#    foreach $key ( sort keys %$href ) {
#	print "\t$key=$href->{$key}\n";
#    }
#    foreach $key ( sort keys %symbol_table ) {
#	print "\t\t$key=$symbol_table{$key}\n";
#    }
}

1;


More information about the Mew-int mailing list