| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl -w | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # SendToKindle.pm | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # Send a file to Amazon's personal document service. | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | package Amazon::SendToKindle; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 29503 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 10 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 120 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | require Exporter; | 
| 13 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 14 |  |  |  |  |  |  | our $VERSION = "0.2"; | 
| 15 |  |  |  |  |  |  | our %EXPORT_TAGS = ('all' => [qw(new send)]); | 
| 16 |  |  |  |  |  |  | our @EXPORT_OK = (@{ $EXPORT_TAGS{'all'} }); | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 1 |  |  | 1 |  | 1038 | use Net::SMTP::TLS; | 
|  | 1 |  |  |  |  | 129678 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 19 | 1 |  |  | 1 |  | 1293 | use MIME::Lite; | 
|  | 1 |  |  |  |  | 37927 |  | 
|  | 1 |  |  |  |  | 263 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | # Constructor. | 
| 22 |  |  |  |  |  |  | sub new { | 
| 23 | 0 |  |  | 0 | 0 |  | my ($class) = @_; | 
| 24 | 0 |  |  |  |  |  | my $self = { | 
| 25 |  |  |  |  |  |  | file_name => $_[1], | 
| 26 |  |  |  |  |  |  | address => $_[2], | 
| 27 |  |  |  |  |  |  | smtp_server => $_[3], | 
| 28 |  |  |  |  |  |  | smtp_port => $_[4], | 
| 29 |  |  |  |  |  |  | smtp_user => $_[5], | 
| 30 |  |  |  |  |  |  | smtp_password => $_[6] | 
| 31 |  |  |  |  |  |  | }; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | bless $self, $class; | 
| 34 | 0 |  |  |  |  |  | return $self; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # Sends the document. | 
| 38 |  |  |  |  |  |  | sub send { | 
| 39 | 0 |  |  | 0 | 0 |  | my ($self, $account, $convert) = @_; | 
| 40 | 0 |  |  |  |  |  | $account = "$account\@kindle.com"; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # Setup Net::SMTP. | 
| 43 | 0 |  |  |  |  |  | my $email = new Net::SMTP::TLS( | 
| 44 |  |  |  |  |  |  | $self->{smtp_server}, | 
| 45 |  |  |  |  |  |  | Port => $self->{smtp_port}, | 
| 46 |  |  |  |  |  |  | User => $self->{smtp_user}, | 
| 47 |  |  |  |  |  |  | Password => $self->{smtp_password}, | 
| 48 |  |  |  |  |  |  | Timeout => 60); | 
| 49 | 0 |  |  |  |  |  | $email->mail($self->{address}); | 
| 50 | 0 |  |  |  |  |  | $email->to($account); | 
| 51 | 0 |  |  |  |  |  | $email->data(); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Prepare the email subject. | 
| 54 | 0 |  |  |  |  |  | my $subject = ""; | 
| 55 | 0 | 0 |  |  |  |  | if ($convert) { | 
| 56 | 0 |  |  |  |  |  | $subject = "convert"; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | # Setup MIME::Lite. | 
| 60 | 0 |  |  |  |  |  | my $msg = MIME::Lite->new( | 
| 61 |  |  |  |  |  |  | From    => $self->{address}, | 
| 62 |  |  |  |  |  |  | To      => $account, | 
| 63 |  |  |  |  |  |  | Subject => $subject, | 
| 64 |  |  |  |  |  |  | Type    => "application/octet-stream", | 
| 65 |  |  |  |  |  |  | Path    => $self->{file_name}); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # Send email. | 
| 68 | 0 |  |  |  |  |  | $email->datasend($msg->as_string); | 
| 69 | 0 |  |  |  |  |  | $email->dataend(); | 
| 70 | 0 |  |  |  |  |  | $email->quit(); | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | 1; | 
| 74 |  |  |  |  |  |  | __END__ |