Browse Source

yamd.pl - Реализована загрузка логотипа для домена. Импорт нескольких почтовых ящиков пока отфильтрован.

master
Sergey Kiselev 7 years ago
parent
commit
061ba20040
  1. 54
      yamd.pl

54
yamd.pl

@ -49,17 +49,51 @@ my $request_content_type = "";
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request($request_type => $request_url);
$request->header(
'PddToken' => $task->{yamd}->{token},
'Content-type' => $request_content_type
);
my $request_content = "domain=" . $task->{yamd}->{domain};
foreach my $k (keys %{$task->{yamd}->{options}}) {
$request_content .= "&" . $k . "=" . $task->{yamd}->{options}->{$k};
}
if ( $task->{yamd}->{service} eq "domain" &&
$task->{yamd}->{sub_service} eq "logo" &&
$task->{yamd}->{query} eq "set" ) {
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
);
my $field = new HTTP::Message([
'Content-Disposition' => 'form-data; name="domain"',
'Content-Type' => 'text/plain; charset=utf-8'
]);
$field->add_content_utf8($task->{yamd}->{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'
]);
$file_content->add_content($_) while <$fh>;
$request->add_part($file_content);
close $fh;
} elsif ( $task->{yamd}->{service} eq "import" &&
$task->{yamd}->{query} eq "start_import_file" ) {
die "Not implemented!\n\n";
} else {
$request->header(
'PddToken' => $task->{yamd}->{token},
'Content-type' => $request_content_type
);
my $request_content = "domain=" . $task->{yamd}->{domain};
foreach my $k (keys %{$task->{yamd}->{options}}) {
$request_content .= "&" . $k . "=" . $task->{yamd}->{options}->{$k};
}
$request->content($request_content);
$request->content($request_content);
}
my $response = $ua->request($request);