I've been working on a relatively simple CGI to accept text in two textareas (one for plain-text and one for HTML). The basic use of this is, as you can probably guess, to format a multi-part email message. I have most of this working, but a "late requirement" was that the text in both sections wrap at ~72 characters.
So, I employed Text::Correct's wrap function to handle the wrapping, since the documentation sounded like a good match for what I wanted.
I can get the code to take the input and it seems to wrap it just fine, but when I look at the output file or the source in the browser, I see strange things.
This is the output as it is read directly from the CGI. Note that it is two long lines, with a blank line between (three lines total).
# Plain text output: This is some text to test the wrapping feature of Text::Correct's wra +p(), using MIME::Lite to create the message. I really just want to have two lines of data to test the functions and + want them both to be over the 72 character limit. # HTML output: <p>This is some text to test the wrapping feature of Text::Corr +ect's wrap(), using MIME::Lite to create the message.</p> <p>I really just want to have two lines of data to test the func +tions and want them both to be over the 72 character limit.</p>
Then there is the post-Text::Correct::wrap() output:
# Plain text output: This is some text to test the wrapping feature of Text::Correct's wrap(), using MIME::Lite to create the message. I really just want to have two lines of data to test the functions and want them both to be over the 72 character limit. # HTML output: <p>This is some text to test the wrapping feature of Text::Cor +rect's wrap(), using MIME::Lite to create the message.</p> <p>I really just want to have two lines of data to test the functions and want them bot +h to be over the 72 character limit.</p>
My problem is that some of the lines wrap properly, and some don't. In the plain text output, there is a short-wrapped line ("I really just want to"), and the HTML output has one, too ("<p>I really just").
When this gets MIME'd up, it gets even worse:
Content-Type: text/plain This is some text to test the wrapping feature of Text::Correct's I really just want toite to create the message. have two lines of data to test the functions and want them both to be over the 72 character limit. ------ Content-Type: text/html <p>This is some text to test the wrapping feature of Text::Corr +ect's <p>I really justME::Lite to create the message.</p> want to have two lines of data to test the functions and want them bot +h to be over the 72 character limit.</p>
I'm at a loss. I have tried everything I can think of to get this to work, but I am very new (this is the second day now :) to both of these modules, so I could be missing something. Here is most the code (didn't put in the non-related stuff), complete with all the prints (STDOUT and file). I use strict and -w, but am not even getting an error in the logfile.
#!/usr/local/bin/perl -w use CGI; use strict; my $q = new CGI; my $emailoutput = '/tmp/email.data'; use MIME::Lite; use Text::Correct qw{ wrap }; my $tp = $q->param('textPLAIN')."\n"; my $th = $q->param('textHTML')."\n"; # Section just for debugging (output to files and browser) print $q->header; print "plain pre:<br>\n $tp<hr>\n"; print "html pre:<br>\n $th<hr>\n"; open O,">/tmp/o1"; print O $tp; close O; open O,">/tmp/o2"; print O $th; close O; my $wtp = wrap(' ','',$tp); my $wth = wrap(' ','',$th); # More debugging (output to files and browser) open O,">/tmp/o3"; print O "$wtp"; close O; open O,">/tmp/o4"; print O "$wth"; close O; print "plain post:<br>\n $wtp<hr>\n"; print "html post:<br>\n $wth<hr>\n"; # Start the message my $msg = MIME::Lite->new( From =>$q->param('emailFrom'), To =>$q->param('emailTo'), Subject =>$q->param('emailSubject'), Type =>'multipart/alternative', ); $msg->attach( Type =>'TEXT', Data =>"$wtp\n", ); $msg->attach( Type =>'text/html', Data =>"$wth\n", Encoding =>'7bit', ); # Add character set (required header) $msg->attr("content-type.charset" => "US-ASCII"); # Remove headers (another requirement) $msg->scrub(['content-transfer-encoding','content-disposition']); # Final output of script to file (yet another requirement) open(OUTFILE,">$emailoutput") or die "Unable to open $emailoutput: $!" +; $msg->print(\*OUTFILE); close OUTFILE;
If anyone can suggest a better way to do this, please feel free - it all helps the learning :) Thanks!
D a d d i o
In reply to Unexpected results using Text::Correct and MIME::Lite by Daddio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |