Show import_csv.html syntax highlighted
% # vim:set syntax=mason:
<%args>
$import
</%args>
<& /mail/header.mhtml, title => 'Import from CSV' &>
<p>CSV file (<% $size %> bytes). Import coming soon...</p>
% open DATA, "<$tmploc";
<table class="csveditor">
% while(<DATA>) {
<tr>
<%perl>
my @fields = split /,/;
if($. == 1) {
$m->print("<th>Nickname</th>\n");
for my $h (@fields) {
$m->print("<td><input type=\"radio\" name=\"nick\"></td>\n");
}
$m->print("</tr><tr>\n");
$m->print("<th>EMail</th>\n");
for my $h (@fields) {
$m->print("<td><input type=\"radio\" name=\"email\"></td>\n");
}
$m->print("</tr><tr>\n");
}
</%perl>
<td><input type="checkbox" name="add" value="<% $. %>"></td>
% for(my $f=0; $f <= $#fields; $f++) {
<td><input type="hidden" name="<% $. . ",$f" %>" value="<% $fields[$f] |h %>"><% $fields[$f] |h %></td>
% }
</tr>
% }
</table>
<& /mail/footer.mhtml &>
<%init>
my $user = Apache::SiteControl->getCurrentUser($r);
my $prefs = new AlphaMail::Preferences($user->getUsername(),
$user->getAttribute('imap'), $config);
my $username = $user->getUsername();
my $error = 0;
my $folder = $user->getAttribute('lastfolder') || 'inbox';
my $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
my $logger = Log::Log4perl->get_logger('alphamail');
my $dir = $config->get('message_tmpdir', '/tmp');
my $book = new AlphaMail::AddressBook($user->getUsername(), $user->getAttribute('imap'), $config);
my $size;
my $tmploc;
eval {
# Get the file
my $upload = $r->upload;
my $filename = $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("Attachment failed: $@");
$error = "Unable to attach file. Make sure the file exists and has content.";
}
</%init>
<%once>
use MIME::Words;
use Time::Format;
</%once>
See more files for this project here