Browse Source

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

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

34
yamd.pl

@ -49,6 +49,39 @@ my $request_content_type = "";
my $ua = new LWP::UserAgent; my $ua = new LWP::UserAgent;
my $request = new HTTP::Request($request_type => $request_url); my $request = new HTTP::Request($request_type => $request_url);
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( $request->header(
'PddToken' => $task->{yamd}->{token}, 'PddToken' => $task->{yamd}->{token},
'Content-type' => $request_content_type 'Content-type' => $request_content_type
@ -60,6 +93,7 @@ foreach my $k (keys %{$task->{yamd}->{options}}) {
} }
$request->content($request_content); $request->content($request_content);
}
my $response = $ua->request($request); my $response = $ua->request($request);