Skip to content

Instantly share code, notes, and snippets.

@stefb69
Created November 1, 2015 20:36
Show Gist options
  • Save stefb69/579bf025d56cc8698837 to your computer and use it in GitHub Desktop.
Save stefb69/579bf025d56cc8698837 to your computer and use it in GitHub Desktop.
Mail to fax gateway script for france free.fr free fax service
#!/usr/bin/perl
# mail2fax_free.pl stefb69
#
use strict;
use warnings;
use WWW::Mechanize;
use MIME::Parser;
my $baseurl = "https://subscribe.free.fr";
my $username = "fbxXXXusername";
my $password = "yourfreeboxpassword";
my $domain = "your.fax.domain";
my $faxnumber;
my $file;
my $parser = MIME::Parser->new( );
$parser->output_under("/tmp");
my $message = $parser->parse(\*STDIN);
$faxnumber = $message->head->get('to');
$faxnumber =~ s/.*<(\d+)\@$domain>$/$1/;
chomp($faxnumber);
#print "fax: $faxnumber -\n";
foreach my $part ($message->parts()) {
if ($part->effective_type =~ m/(pdf|tif)/) {
$file = $part->bodyhandle->path;
}
}
stat $file;
exit unless -e $file;
my $mech = WWW::Mechanize->new();
$mech->agent_alias("Mac Safari");
$mech->get($baseurl . "/login/");
$mech->submit_form(
form_id => "log_form",
fields => {
login => $username,
pass => $password,
}
);
$mech->follow_link( url_regex => qr"https://adsl\.free\.fr/tel_fax.pl.*" );
#print "got login\n";
$mech->submit_form(
form_id => "form_envoifax",
fields => {
destinataire => $faxnumber,
document => $file,
}
);
#print "$file\n";
#unlink $file;
$parser->filer->purge;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment