Changeset 2680 for trunk/gsdl/perllib/plugins/EMAILPlug.pm
- Timestamp:
- 2001-07-31T13:58:05+12:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/EMAILPlug.pm
r2662 r2680 128 128 $Headers =~ s/\r?\n\r?\n(.*)$//s; 129 129 $$textref = $1; 130 # escape [] so it isn't re-interpreted as metadata 131 $Headers =~ s/\[/[/g; $Headers =~ s/\]/]/g; 132 130 133 131 134 # Unfold headers - see rfc822 … … 166 169 # Extract the name and e-mail address from the From metadata 167 170 $frommeta = $raw{"From"}; 168 $frommeta =~ m/(.*)<(.*)>/; 169 my $fromnamemeta=$1; 170 my $fromaddrmeta=$2; 171 my $fromnamemeta; 172 my $fromaddrmeta; 173 174 $frommeta =~ s/\s*$//; # Remove trailing space, if any 175 176 if ($frommeta =~ m/(.+)\s*<(.+)>/) { 177 $fromnamemeta=$1; 178 $fromaddrmeta=$2; 179 } elsif ($frommeta =~ m/(.+@.+)\s+\((.*)\)/) { 180 $fromnamemeta=$2; 181 $fromaddrmeta=$1; 182 } 171 183 if (!defined($fromaddrmeta)) { 172 184 $fromaddrmeta=$frommeta; 173 185 } 186 $fromaddrmeta=~s/<//; $fromaddrmeta=~s/>//; 174 187 $doc_obj->add_utf8_metadata ($cursection, "FromAddr", $fromaddrmeta); 175 188 176 189 if (defined($fromnamemeta)) { 177 190 $fromnamemeta =~ s/\"//g; 178 $fromnamemeta =~ s/(.*) /$1/; # Remove trailing space179 191 } 180 192 else { … … 220 232 my $mimeinfo=""; 221 233 # Do MIME and encoding stuff 222 if ($Headers =~ /^content\-type:\s*([\w\/\-]+)\s*\;?\s*( [^\s]+)\s*$/mi)234 if ($Headers =~ /^content\-type:\s*([\w\/\-]+)\s*\;?\s*(.+?)\s*$/mi) 223 235 { 224 236 $mimetype=$1; … … 227 239 } 228 240 241 my $transfer_encoding="7bit"; 242 if ($Headers =~ /^content-transfer-encoding:\s*([^\s]+)\s*$/mi) { 243 $transfer_encoding=$1; 244 } 229 245 if ($mimetype ne "text/plain") { 230 $$textref=text_from_mime_message($mimetype,$mimeinfo,$$textref); 231 } # end of not text/plain 246 $$textref=text_from_mime_message($mimetype,$mimeinfo,$$textref, 247 $outhandle); 248 } elsif ($transfer_encoding =~ /quoted\-printable/) { 249 $$textref=qp_decode($$textref); 250 } elsif ($transfer_encoding =~ /base64/) { 251 $$textref=base64_decode($$textref); 252 } 232 253 233 254 … … 294 315 # the textref we are given DOES NOT include the header. 295 316 sub text_from_mime_message { 296 my ($mimetype,$mimeinfo,$text )=(@_);317 my ($mimetype,$mimeinfo,$text,$outhandle)=(@_); 297 318 298 319 # Check for multiparts - $mimeinfo will be a boundary 299 320 if ($mimetype =~ /multipart/) { 300 321 $boundary=""; 301 if ($mimeinfo =~ /boundary= "?([^\s]+?)"?\s*$/im) {322 if ($mimeinfo =~ /boundary=\"?([^"]+)\"?\s*$/im) { 302 323 $boundary=$1; 303 324 } … … 305 326 # message ends with "--$boundary--" 306 327 # RFC says boundary is <70 chars, [A-Za-z'()+_,-./:=?], so escape any 307 # that perl might want to interpolate. 328 # that perl might want to interpolate. Also allows spaces... 308 329 309 330 $boundary=~s/\\/\\\\/g; … … 313 334 shift @message_parts; 314 335 my $last=pop @message_parts; 336 # if our boundaries are a bit dodgy and we only found 1 part... 337 if (!defined($last)) {$last="";} 315 338 # make sure it is only -- and whitespace 316 339 if ($last !~ /^\-\-\s*$/ms) { … … 358 381 foreach my $message_part (@message_parts) { 359 382 my $part_header=$message_part; 360 $part_header=~s/\r?\n\r?\n(.*)$//sg; 361 my $part_body=$1; 383 my $part_body; 384 if ($part_header=~s/\r?\n\r?\n(.*)$//sg) { 385 $part_body=$1; 386 } else { 387 # no header... use defaults 388 $part_body=$message_part; 389 $part_header="Content-type: text/plain; charset=us-ascii"; 390 } 362 391 $part_header =~ s/\r?\n[\t\ ]+/ /gs; #unfold 363 392 my $part_content_type=""; … … 367 396 $part_content_type="message/rfc822"; 368 397 } 369 if ($part_header =~ m@^content\-type:\s*([\w+/\-]+)\s*\;?\s*([^\s] +)@mi) {398 if ($part_header =~ m@^content\-type:\s*([\w+/\-]+)\s*\;?\s*([^\s]*)@mi) { 370 399 $part_content_type=$1; $part_content_type =~ tr/A-Z/a-z/; 371 400 $part_content_info=$2; … … 423 452 text_from_mime_message($message_content_type, 424 453 $message_content_info, 425 $message_part_body); 454 $message_part_body, 455 $outhandle); 426 456 } else { 427 457 $message_part_body=text_from_part($part_body); … … 443 473 $tmptext=text_from_mime_message($part_content_type, 444 474 $part_content_info, 445 $part_body); 475 $part_body, 476 $outhandle); 446 477 $text.=$tmptext; 447 478 } elsif ($text eq "") {
Note:
See TracChangeset
for help on using the changeset viewer.