Browse Source

yamd.pl - дописал импорт писем нескольких почтовых ящиков на Яндекс.Почту для домена

examples/import_file_example.yml - пример импорта нескольких почтовых ящиков
examples/mail_list_example.lst - пример списка почтовых ящиков для импорта
master
Sergey Kiselev 7 years ago
parent
commit
c4a9651f63
  1. 14
      examples/import_file_example.yml
  2. 3
      examples/mail_list_example.lst
  3. 28
      yamd.pl

14
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'

3
examples/mail_list_example.lst

@ -0,0 +1,3 @@
login1 external_password1
login2@example.com external_password2
login4 external_password4 user4 internal_password4

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