From c4a9651f632f74ad4e5ba9ff8485dc4bfebe4b92 Mon Sep 17 00:00:00 2001 From: Sergey Kiselev Date: Thu, 21 Jun 2018 13:19:45 +0500 Subject: [PATCH] =?UTF-8?q?yamd.pl=20-=20=D0=B4=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=20=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B5=D0=BC=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=B8=D1=85=20=D0=BF=D0=BE=D1=87=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D1=85=20=D1=8F=D1=89=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=AF=D0=BD=D0=B4=D0=B5=D0=BA=D1=81.=D0=9F=D0=BE?= =?UTF-8?q?=D1=87=D1=82=D1=83=20=D0=B4=D0=BB=D1=8F=20=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20examples/import=5Ffile=5Fexample.yml=20-?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=20=D0=B8=D0=BC=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B0=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=B8=D1=85=20=D0=BF=D0=BE=D1=87=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D1=85=20=D1=8F=D1=89=D0=B8=D0=BA=D0=BE=D0=B2=20examples/?= =?UTF-8?q?mail=5Flist=5Fexample.lst=20-=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=87=D1=82=D0=BE=D0=B2=D1=8B=D1=85=20=D1=8F=D1=89=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D0=BC=D0=BF=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/import_file_example.yml | 14 ++++++++++++++ examples/mail_list_example.lst | 3 +++ yamd.pl | 28 ++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 examples/import_file_example.yml create mode 100644 examples/mail_list_example.lst diff --git a/examples/import_file_example.yml b/examples/import_file_example.yml new file mode 100644 index 0000000..9cfe485 --- /dev/null +++ b/examples/import_file_example.yml @@ -0,0 +1,14 @@ +--- +yamd: + # Импорт нескольких почтовых ящиков + domain: 'example.ru' + token: '123456789ABCDEF0000000000000000000000000000000000000' + service: 'import' + query: 'start_import_file' + options: + method: 'imap' + server: 'imap.example.com' + port: '993' + ssl: 'yes' + file: '/full/path/to/mail_list_example.lst' + diff --git a/examples/mail_list_example.lst b/examples/mail_list_example.lst new file mode 100644 index 0000000..ec43a91 --- /dev/null +++ b/examples/mail_list_example.lst @@ -0,0 +1,3 @@ +login1 external_password1 +login2@example.com external_password2 +login4 external_password4 user4 internal_password4 diff --git a/yamd.pl b/yamd.pl index c4c911d..7d72e1e 100755 --- a/yamd.pl +++ b/yamd.pl @@ -33,6 +33,13 @@ my $request_content_type = ""; $request_url .= (defined $sub_service) ? "/" . $sub_service : ""; $request_url .= "/" . $query; + if ( $service eq "import" && $query eq "start_import_file" ) { + $request_url .= "?domain=" . $task->{yamd}->{domain}; + foreach my $k (keys %{$task->{yamd}->{options}}) { + $request_url .= "&" . $k . "=" . $task->{yamd}->{options}->{$k}; + } + } + if (defined $sub_service) { $request_type = $query_options->{$service}->{$sub_service}->{$query}->{query_type}; $request_content_type = $query_options->{$service}->{$sub_service}->{$query}->{content_type}; @@ -69,7 +76,6 @@ if ( $task->{yamd}->{service} eq "domain" && $request->add_part($field); open(my $fh, '<', $task->{yamd}->{options}->{file}); - my $size = (stat $task->{yamd}->{options}->{file})[7]; my $file_content = new HTTP::Message([ 'Content-Disposition' => 'form-data; name="file"; filename="logo"', 'Content-Type' => 'application/octet-stream' @@ -80,7 +86,25 @@ if ( $task->{yamd}->{service} eq "domain" && close $fh; } elsif ( $task->{yamd}->{service} eq "import" && $task->{yamd}->{query} eq "start_import_file" ) { - die "Not implemented!\n\n"; + my $boundary = 'X'; + my @rand = ('a'..'z', 'A'..'Z'); + for (0..14) { $boundary .= $rand[rand(@rand)]; } + + $request->header( + 'PddToken' => $task->{yamd}->{token}, + 'Content-type' => $request_content_type . "; boundary=" . $boundary + ); + + open(my $fh, '<', $task->{yamd}->{options}->{file}); + my $file_content = new HTTP::Message([ + 'Content-Disposition' => 'form-data; name="import_list_file"; filename="import_list_file"', + 'Content-Type' => 'text/plain', + ]); + $file_content->add_content($_) while <$fh>; + + $request->add_part($file_content); + + close $fh; } else { $request->header( 'PddToken' => $task->{yamd}->{token},