Hello,
I would like to know if there was a way to set a width for lines outputted to aid in formatting, to make sure that lines always wrap after a certain amount. I will be using the code below to sort and print emails, and would prefer messages that are on very long lines are neatly broken up, but I am unsure how to do this. I have attempted with Text::Wrap
#!/usr/bin/perl
use warnings;
use strict;
use Text::Wrap
use Mail::Box::Manager;
open (MYFILE, '>>data.txt');
binmode(MYFILE, ':encoding(UTF-8)');
my $file = shift || $ENV{MAIL};
my $mgr = Mail::Box::Manager->new(
access => 'r',
);
my $folder = $mgr->open( folder => $file )
or die "$file: Unable to open: $!\n";
for my $msg ( sort { $a->timestamp <=> $b->timestamp } $folder->messages)
{
my $to = join( ', ', map { $_->format } $msg->to );
my $from = join( ', ', map { $_->format } $msg->from );
my $date = localtime( $msg->timestamp );
my $subject = $msg->subject;
my $body = $msg->decoded->string;
# Strip all quoted text
$body =~ s/^>.*$//msg;
$Text::Wrap::columns=20;
print MYFILE wrap("", "", <<"");
From: $from
To: $to
Date: $date
Subject: $subject
\n
$body
}
I am using the above code, but now get this error:
Undefined subroutine &main::wrap called at x.pl line 29, line 136516.