Breaking Lines #

Something came up which prevented me from moving on to the new user log-in thing that I had planned before. So far, I've been using <PRE> </PRE> tags to delimit the message body, so that the spacing within it would be retained (HTML ignores more than two consecutive spaces, line breaks, tabs, etc.). However, I realized that this screwed up line wrapping (as in, if a line was longer than the width of the window, neither Netscape nor Internet Explorer would wrap it). In the end I decided I had to convert the message body to HTML too, since only then would the wrapping work. Converting line breaks and tabs was easy, it involved a simple substitution. However, I had problems with whitespace made out of the ' ' character. The closest HTML entity to it which isn't ignored when there's more tha none is &nbsp;, but that's a non-breakable space so I couldn't simply globally substitute &nbsp; for ' ', instead I would have to find places where there were two or more and then substitute for it. In the end, this yielded the following code:

while ($line =~ /( {2,})/)
{
	local($spaces) = '&nbsp;' x length($1);
	$line =~ s/$1/$spaces/; 
}

This can be interpreted as "while there are spaces surrounded by non-space characters and the length of the spaces is 2 or more, substitute the spaces by the string '&nbsp;' repeated as many times as there are spaces"

Another thing which I did that wasn't in the schedule was to deal with multiple recipients. The To: field can have multiple addresses in it, separated by commas and or line breaks. The realization that headers can be split across multiple lines caused me some problems, because I couldn't simply use the split to divide up each line into the key (the field name, e.g. From) and the contents (e.g. "User Foo <user@example.com>") by using ":" as the delimitor. Now I loop through each of the line, look for a <string:>:<string> pattern, if I find it I insert it into the headers associative array (basically, a hash table) and if I don't it append it to the entry of the previous field that I found. As for the multiple recipients themselves, I divide up the string by using the comma as the delimiter, and then use the name/address splitter function that I did earlier on each address.

I then wanted to move on to the delete function, and I got it to the point where it does actually delete messages (good for pre-emptive spam removal, that way I don't have to download them in my Inbox), but I'm still not getting it to refresh the message list or the message that's being displayed in the message view frame.

Post a Comment