| 1 | # HTTP Email Address (for things like From) | ||
| 2 | # Should probably be a Mail:: not IDS::DataSource::HTTP:: object | ||
| 3 | # | ||
| 4 | # subclass of HTTP; see that for interface requirements | ||
| 5 | # | ||
| 6 | |||
| 7 | package IDS::DataSource::HTTP::EmailAddr; | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | use Carp qw(carp confess); | ||
| 12 | use base qw(IDS::DataSource::HTTP::Part); | ||
| 13 | |||
| 14 | use IDS::DataSource::HTTP::Host; | ||
| 15 | |||
| 16 | $IDS::DataSource::HTTP::EmailAddr::VERSION = "1.0"; | ||
| 17 | |||
| 18 | sub empty { | ||
| 19 | my $self = shift; | ||
| 20 | undef $self->{"data"}, $self->{"tokens"}, $self->{"host"}; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub parse { | ||
| 24 | my $self = shift; | ||
| 25 | my $data = $self->{"data"}; # convenience | ||
| 26 | my @tokens; | ||
| 27 | my $token; | ||
| 28 | |||
| 29 | $self->mesg(1, *parse{PACKAGE} . "::parse: data '$data'"); | ||
| 30 | |||
| 31 | # Contrary to the standard, google and microsoft both use (at) | ||
| 32 | # instead of @ in the From: line. Sigh. | ||
| 33 | if ($data =~ /^([^@]+)(@|\(at\))([^@]+)$/) { | ||
| 34 | my $user = $1; | ||
| 35 | my $host = $3; | ||
| 36 | |||
| 37 | $token = "Email user: "; | ||
| 38 | $token .= ${$self->{"params"}}{"email_user_length_only"} | ||
| 39 | ? length($user) | ||
| 40 | : $user; | ||
| 41 | push @tokens, $token; | ||
| 42 | |||
| 43 | $self->{"host"} = new IDS::DataSource::HTTP::Host($self->{"params"}, $host); | ||
| 44 | push @tokens, $self->{"host"}->tokens; | ||
| 45 | } else { | ||
| 46 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 47 | ${$self->{"params"}}{"source"} . | ||
| 48 | " invalid email addr in '$data'\n"; | ||
| 49 | $self->warn($pmsg, \@tokens, "!Invalid email addr"); | ||
| 50 | } | ||
| 51 | |||
| 52 | $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ", | ||
| 53 | "\n ", \@tokens); | ||
| 54 | $self->{"tokens"} = \@tokens; | ||
| 55 | } | ||
| 56 | |||
| 57 | # accessor functions not provided by the superclass | ||
| 58 | |||
| 59 | =head1 AUTHOR INFORMATION | ||
| 60 | |||
| 61 | Copyright 2005-2007, Kenneth Ingham. All rights reserved. | ||
| 62 | |||
| 63 | This library is free software; you can redistribute it and/or modify | ||
| 64 | it under the same terms as Perl itself. | ||
| 65 | |||
| 66 | Address bug reports and comments to: ids_test at i-pi.com. When sending | ||
| 67 | bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm, | ||
| 68 | IDS::DataSource.pm, the version of Perl, and the name and version of the | ||
| 69 | operating system you are using. Since Kenneth is a PhD student, the | ||
| 70 | speed of the reponse depends on how the research is proceeding. | ||
| 71 | |||
| 72 | =head1 BUGS | ||
| 73 | |||
| 74 | Please report them. | ||
| 75 | |||
| 76 | =head1 SEE ALSO | ||
| 77 | |||
| 78 | L<IDS::Algorithm>, L<IDS::DataSource> | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | 1; |