From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- lib/tasks/fax.rake | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lib/tasks/fax.rake (limited to 'lib/tasks/fax.rake') diff --git a/lib/tasks/fax.rake b/lib/tasks/fax.rake new file mode 100644 index 0000000..1f1c282 --- /dev/null +++ b/lib/tasks/fax.rake @@ -0,0 +1,74 @@ +# encoding: UTF-8 + +desc "Import inbound fax" + +task :import_inbound_fax, [ + :fax_account_id, + :result_code, + :document_total_pages, + :document_transferred_pages, + :ecm_requested, + :ecm_used, + :image_resolution, + :remote_station_id, + :transfer_rate, + :transmission_time, + :document, + :caller_id_number, + :caller_id_name, + ] => :environment do |t, a| + + TIFF_FUFFIX = ".tiff" + PDF_SUFFIX = ".pdf" + + fax_arguments = a.to_hash + + tiff_file = fax_arguments[:document] + + if !tiff_file or !File.exists?( tiff_file ) + $stderr.puts "File \"#{tiff_file}\" does not exist" + exit 1 + end + + paper_size = "letter" + pdf_file = "#{File.dirname(tiff_file)}/#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}" + + system "tiff2pdf \\ + -o \"#{pdf_file}\" \\ + -p #{paper_size} \\ + -a \"#{fax_arguments[:remote_station_id]}\" \\ + -c \"AMOOMA Gemeinschaft version #{GEMEINSCHAFT_VERSION}\" \\ + -t \"#{fax_arguments[:remote_station_id]}\" \"#{tiff_file}\"" + + if !File.exists?( pdf_file ) + $stderr.puts "File \"#{pdf_file}\" does not exist" + exit 1 + end + + fax_account = FaxAccount.find(fax_arguments[:fax_account_id]) + if !fax_account + $stderr.puts "Fax account \"#{fax_arguments[:fax_account_id]}\" does not exist" + exit 1 + end + + fax_arguments[:document] = nil + fax_arguments[:success] = true + fax_arguments[:inbound] = true + fax_arguments[:sent_at] = Time.now + fax_arguments[:local_station_id] = fax_account.station_id + fax_arguments[:retry_counter] = 0 + fax_arguments[:fax_resolution_id] = FaxResolution.first.id + fax_arguments[:image_size] = File.size(tiff_file) + fax_arguments[:ecm_used] = fax_arguments[:ecm_used] == "on" ? true : false + fax_document = fax_account.fax_documents.build(fax_arguments) + fax_document.document = File.open(pdf_file) + + if fax_document.save + fax_document.mark_as_inbound! + exit 0 + else + $stderr.puts "Error(s) creating fax document:" + $stderr.puts fax_document.errors.inspect + exit 1 + end +end -- cgit v1.2.3