Show import_csv.html syntax highlighted
% # vim:set syntax=mason:
<%args>
$import
</%args>
<& /mail/header.mhtml, title => 'Import from CSV' &>
<p>Click on someones first name (NOT their full name)</p>
<pre>
<%perl>
open DATA, "<$tmploc";
while(<DATA>) {
my @fields = split /,/;
for(my $f=0; $f <= $#fields; $f++) {
$m->print(hyperlink("$base/mail/addressbook/import_fname.html",
$fields[$f],
{ fn => $f,
data => $tmploc }) . ", ") if($fields[$f]);
}
$m->print("\n");
}
close DATA;
</%perl>
</pre>
<& /mail/footer.mhtml &>
<%init>
my ($user, $dir, $username);
eval {
$user = Apache2::SiteControl->getCurrentUser($r);
$dir = $config->getScratchDir($user);
$username = $user->getUsername();
};
if($@) {
$logger->error("Unable to get attachment: $@");
$m->redirect(build_url("$base/mail/index.html", { message => "Request failed" }));
}
my $prefs = new AlphaMail::Preferences($user->getUsername(),
$user->getAttribute('mx'), $config);
my $error = 0;
my $folder = $user->getAttribute('lastfolder') || 'inbox';
my $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
my $book = new AlphaMail::AddressBook($user->getUsername(), $user->getAttribute('mx'), $config);
my $size;
my $tmploc;
eval {
use Apache2::Upload;
use Apache2::Request;
my $req = Apache2::Request->new($r);
# Get the file
my $upload = $req->upload('file');
my $filename = Encode::decode_utf8($upload->filename);
die "No file provided." if $filename =~ m/^\s*$/;
# sanitize the filename
$filename =~ s!^.*[/\\]([^\\/]*)$!$1!;
$filename =~ s/^\.+//g;
$filename =~ s/[^a-z0-9.]/_/ig;
$tmploc = "$dir/" . $username . "_csv_" . $filename;
if(-f $tmploc) {
unlink $tmploc;
}
$upload->link($tmploc);
$size = (stat($tmploc))[7];
die "No (or empty) file provided!" if $size == 0;
};
if($@) {
$logger->error("Import failed: $@");
$error = "Unable to import file. Make sure the file exists and has content.";
}
$m->redirect(build_url("$base/mail/addressbook/index.html", { selected => "Import" ,
message => $error })) if($error);
</%init>
<%once>
use AlphaMail::HTMLHelper qw(hyperlink build_url);
our $logger = Log::Log4perl->get_logger('alphamail');
our $base = $config->get('base_uri');
</%once>
See more files for this project here