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},