Gossamer Forum
Home : Products : DBMan : Installation :

Mail mod

Quote Reply
Mail mod
I have a question about this mail mod.
Code:
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: $in{'To'}\n";
print MAIL "From: $in{'From'}\n";
print MAIL "Subject: $in{'Subject'}\n";
print MAIL "\n\n";
print MAIL "$in{'Message'}\n" ;
print MAIL "\n\n";close (MAIL);
The problem is that when it sends mail if any field is over a certain length the receiving person has to scroll right and left to read the message. Is there any way to force the line to break after so many characters?
Quote Reply
Re: Mail mod In reply to
Seems like there was some post about word-wrapping a while back, but it was quite a while ago and could have been in the Perl/CGI forum. I'll add it to my "think about" list. Smile

------------------
JPD





Quote Reply
Re: Mail mod In reply to
I found the code you were talking about:
Code:
sub linewrap {
# --------------------------------------------------------
# Wraps a line into 60 char chunks. Modified from code by
# Tim Gim Yee <tgy@chocobo.org>.
#
my $line = shift; defined $line or return '';
my @data = split /\t/, $line;
my $columns = 60;
my $tabstop = 1;
my $frag = '';
my $col = $columns - 1;
for (@data) {
$_ = "$frag$_";
$frag = '';
s/(.{1,$columns}$)|(.{1,$col}(?:\S\s+|-(?=\w)))|(.{$col})/
$3 ? "$3-\n" :
$2 ? "$2\n" :
(($frag = $1), '')
/ge;
$frag .= (' ' x ($tabstop - length($frag) % $tabstop));
}
local $_ = join '', @data, $frag;
s/\s+$//gm;
return $_;
}

How do I get this to work with the mail mod, and to only filter the Message?
Quote Reply
Re: Mail mod In reply to
Gee, I came up with something a whole lot simpler than that. Smile (My "thinker" worked fast on this one.)

Try this:

Code:
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: $in{'To'}\n";
print MAIL "From: $in{'From'}\n";
print MAIL "Subject: $in{'Subject'}\n";
print MAIL "\n\n";

$line_length = 60;

while (length($in{'Message'}) > $line_length) {
$i = $line_length;
# Find the end of the last word that will stay on the line
while (substr($in{'Message'},$i,1) ne " ") {
--$i;
}
# Add the line to the array
push(@messages, substr($in{'Message'},0,$i));
# Delete the line from the message
substr($in{'Message'},0,$i+1) = '';
}
# Add the last bit of the message to the array
push(@messages,$in{'Message'});
# Print out the lines
foreach $message_line (@messages) {
print MAIL "$message_line\n";
}
print MAIL "\n\n";
close (MAIL);

I didn't use it to send an email, but it works to break up a long message when I run it on my home computer.

I guess I didn't remember how complicated that other script was. I notice that it has some tab stops in it and some other stuff that you probably won't need. But it sure is interesting to look at! I'll have to study this one for a while to see what it does. Smile

------------------
JPD





Quote Reply
Re: Mail mod In reply to
Thanks JPDeni that worked perfectly! I even understood your code. However, the other coding I had no clue about.

Thanks again!

____________
Opps, spoke one second too soon, maybe. I tried sending a message with no spaces and over 60 characters just for the heck of it to see what it would do. The script hung. It there a way to tell it if there are nospaces then print the line anyways and break at the first space afterwards?

[This message has been edited by Helpdesk (edited June 26, 1999).]
Quote Reply
Re: Mail mod In reply to
Okay. You want it to go ahead and print the whole line, right?

Code:
$line_length = 60;

unless ($in{'Message'} =~ / /) {
print MAIL "$in{'Message'}\n";
}
else {
while (length($in{'Message'}) > $line_length) {
$i = $line_length;
# Find the end of the last word that will stay on the line
while ((substr($in{'Message'},$i,1) ne " ") and ($i>0)) {
--$i;
}
if ($i <1) {
$i = index $in{'Message'}, " ";
}
# Add the line to the array
push(@messages, substr($in{'Message'},0,$i));
# Delete the line from the message
substr($in{'Message'},0,$i+1) = '';
}
# Add the last bit of the message to the array
push(@messages,$in{'Message'});
# Print out the lines
foreach $message_line (@messages) {
print MAIL "$message_line\n";
}
}

------------------
JPD





Quote Reply
Re: Mail mod In reply to
Thanks again! It worked. I can't ever thank you enough, you are very skilled and I appreciate you taking your time to help others and myself out on this forum.