- if ($ARGV[$i] eq "-h" || $ARGV[$i] eq "--help") {
- usage;
- } elsif ($ARGV[$i] =~ /^--list-/) {
- $ARGV[$i] =~ s/^--list-//;
- if ($ARGV[$i] eq "categories") {
- list_categories;
- } else {
- usage;
- }
- } elsif ($ARGV[$i] =~ /^--buchung-/) {
- $ARGV[$i] =~ s/^--buchung-//;
- if ($ARGV[$i] eq "category") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)) {
- $i++;
- sales_list("category = '$ARGV[$i]'");
- } else {
- sales_list;
- }
- } elsif ($ARGV[$i] eq "hidden") {
- my $saved_table = $table;
- $table = "sales_dm";
- sales_list("visible = 0");
- $table = "sales";
- sales_list("visible = 0");
- $table = $saved_table;
- } elsif ($ARGV[$i] eq "input") {
- buchung_input;
- } elsif ($ARGV[$i] eq "unpaid") {
- my $saved_table = $table;
- $table = "sales_dm";
- sales_list("paid = 0");
- $table = "sales";
- sales_list("paid = 0");
- $table = $saved_table;
- } else {
- usage;
- }
- } elsif ($ARGV[$i] eq "--pay") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
- && ($ARGV[$i+1] =~ /^\d+$/)) {
- $i++;
- pay_invoice ($ARGV[$i], 1);
- }
- } elsif ($ARGV[$i] eq "--unpay") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
- && ($ARGV[$i+1] =~ /^\d+$/)) {
- $i++;
- pay_invoice ($ARGV[$i], 0);
- }
- } elsif ($ARGV[$i] eq "--hide") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
- && ($ARGV[$i+1] =~ /^\d+$/)) {
- $i++;
- hide_invoice ($ARGV[$i], 1);
- }
- } elsif ($ARGV[$i] eq "--unhide") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
- && ($ARGV[$i+1] =~ /^\d+$/)) {
- $i++;
- hide_invoice ($ARGV[$i], 0);
- }
- } elsif ($ARGV[$i] eq "--year" || $ARGV[$i] eq "-y") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] =~ /^(\d+)$/)) {
- $i++;
- $opt_year = $1;
- if ($opt_year < 70) {
- $opt_year += 2000;
- } elsif ($opt_year < 100) {
- $opt_year += 1900;
- }
- if ($opt_year < 2002) {
- $table = "sales_dm";
- } elsif ($opt_year > 2001) {
- $table = "sales";
- }
- }
- } elsif ($ARGV[$i] eq "--direction" || $ARGV[$i] eq "--dir"
- || $ARGV[$i] eq "-d") {
- if ($i+1 <= $#ARGV && ($ARGV[$i+1] =~ /^(in|out)$/i)) {
- $i++;
- $opt_direction = $1;
- }
- } elsif ($ARGV[$i] eq "--dm") {
- $table = "sales_dm";
- } elsif ($ARGV[$i] eq "-a" || $ARGV[$i] eq "--all") {
- $opt_all = 1;
- } elsif ($ARGV[$i] eq "-v" || $ARGV[$i] eq "--verbose") {
- $opt_verbose = 1;
+if (defined $opt_direction) {
+ usage unless $opt_direction =~ /^(in|out)$/i;
+}
+
+if (defined $data{mailto}) {
+ if (open(STDOUT, "| /usr/sbin/sendmail -t")) {
+ print "From: Joey Schulze <joey\@infodrom.org>\n";
+ printf "To: %s\n", length($data{mailto})?$data{mailto}:'Joey Schulze <joey@infodrom.org>';
+ printf "Subject: %s\n", $cmdln;
+ print "MIME-Version: 1.0\n";
+ print "Content-type: text/plain; charset=iso-8859-1\n";
+ print "Content-Disposition: inline\n";
+ print "Content-Transfer-Encoding: 8bit\n";
+ print "\n";