###RUN_PERL:
-# Copyright (C) 2023 Balthasar Szczepański
+# Copyright (C) 2023, 2024 Balthasar Szczepański
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
'read_header_file',
'merge_url',
'html_entity_decode', 'url_query_encode',
- 'make_temp_path'
+ 'make_temp_path',
+ 'open_encoded'
);
use post_common (
'prepare_post',
my %data = ();
unless (($arg == \*STDIN) and ($options{'content'} ne '') and ($options{'data-only'} ne ''))
{
- %data = read_data_file($arg, ENCODING_FILE, $options{'data-only'});
+ %data = read_data_file($arg, ENCODING_FILE(), $options{'data-only'});
unless (keys %data) {
unless ($options{'quiet'} ne '') {
print "NO DATA\n";
return CODE->{'POST_FAILED'};
}
- unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) {
+ unless (open_encoded($fh, '<:encoding('.ENCODING_MIRROR.')', $tmp_path)) {
unless ($cmd_options->{'quiet'} ne '') {
print "FAIL open $tmp_path\n";
}
return CODE->{'POST_FAILED'};
}
- if (($cmd_options->{'edit'} ne '') and ($cmd_options->{'append'} ne '')) {
- %previous_post = get_mirror_previous_post($fh);
- if ($previous_post{'error'} ne '') {
- unless ($cmd_options->{'quiet'} ne '') {
- print "FAIL previous post\n";
- }
- print STDERR 'Failed getting previous post content: '.$previous_post{'error'}."\n";
- return CODE->{'POST_FAILED'};
- }
- if ($cmd_options->{'verbose'} ne '') {
- print "PREVIOUS POST\n";
- write_data_file(
- \*STDOUT, \%previous_post, 'console_out',
- 0, 0, 0,
- '>>', 1
- );
- print "\n";
+ %previous_post = get_mirror_previous_post($fh);
+ if ($cmd_options->{'verbose'} ne '') {
+ print "PREVIOUS POST\n";
+ write_data_file(
+ \*STDOUT, \%previous_post, 'console_out',
+ 0, 0, 0,
+ '>>', 1
+ );
+ print "\n";
+ }
+ if ($previous_post{'error'} ne '') {
+ unless ($cmd_options->{'quiet'} ne '') {
+ print "FAIL previous post\n";
}
+ print STDERR 'Failed getting previous post content: '.$previous_post{'error'}."\n";
+ return CODE->{'POST_FAILED'};
}
-
+
close ($fh);
$wget_options{'referer'} = $edit_url;
$wget_options{'postdata_path'} = $postdata_path;
- if ($previous_post{'content'} ne '') {
+ if (
+ ($cmd_options->{'edit'} ne '') and
+ ($cmd_options->{'append'} ne '') and
+ ($previous_post{'content'} ne '')
+ ) {
$post_data{'subject'} = $previous_post{'subject'};
$post_data{'message'} =
$previous_post{'content'}.
if ($cmd_options->{'edit'} ne '') {
$post_data{'forceID'} = $cmd_options->{'edit'};
}
+ if ($previous_post{'st'} ne '') {
+ $post_data{'st'} = $previous_post{'st'};
+ }
+
$post_data{'post'} = 'Submit';
unless ($cmd_options->{'quiet'} ne '') {
0, 0, 0,
'>>', 1
);
+ print "WAIT 5s\n";
}
+ sleep(5); # TODO: selectable wait time
print "SUBMIT post";
if ($cmd_options->{'verbose'} ne '') {
print ": $post_url SAVE $tmp_path\n";
return CODE->{'POST_FAILED'};
}
- unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) {
+ unless (open_encoded($fh, '<:encoding('.ENCODING_MIRROR.')', $tmp_path)) {
unless ($cmd_options->{'quiet'} ne '') {
print "FAIL open $tmp_path\n";
}
($r, $s) = get_mirror_post_status($fh);
close ($fh);
+ # TODO: wait & retry
+
unless ($r) {
unless ($cmd_options->{'quiet'} ne '') {
print "FAIL $s\n";
$fh=$file;
}
else {
- unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) {
+ unless (open_encoded ($fh, '<:encoding('.ENCODING_MIRROR.')', $file)) {
return (0, "Failed to open $file");
}
}
my %post;
my $text;
my $tag;
+ my $input_name;
+ my $input_value;
my $textarea = 0;
+ my $comment = 0;
if(ref($file)) {
$fh=$file;
}
else {
- unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) {
+ unless (open_encoded ($fh, '<:encoding('.ENCODING_MIRROR.')', $file)) {
$post{'error'} = "Failed to open $file";
return %post;
}
while (defined(my $line = <$fh>)) {
while ($line ne '') {
- if ($line =~ /^([^<]*)(<.*)$/s) {
+ if ($comment) {
+ if ($line =~ /-->/) {
+ $comment = 0;
+ $line = $';
+ next;
+ }
+ else {
+ last;
+ }
+ }
+
+ if ($line =~ /^([^<]*)(<)/s) {
$text = $1;
- $line = $2;
+ $line = $2.$';
}
else {
$text = $line;
last;
}
- if ($line =~ /^(<[^>]*>)(.*)$/s) {
+ if ($line =~ /^<!--/) {
+ $comment = 1;
+ $line = $';
+ next;
+ }
+
+ if ($line =~ /^(<[^>]*>)/s) {
$tag = lc($1);
- $line = $2;
+ $line = $';
}
else { # oh no tag doesn't end on this line - whatever, I don't care.
$tag = $line;
}
# SKIP!: form_token creation_time attachment (from post.awk)
- if ($tag =~ /name="subject"/) {
- $tag =~ /value="([^"]*)"/;
- $post{'subject'} = html_entity_decode($1);
+ if ($tag =~ /^<input (.* )?name="([^"]*)"/) {
+ $input_name = html_entity_decode($2);
+ if ($tag =~ /value="([^"]*)"/) {
+ $input_value = html_entity_decode($1);
+ }
+ else {
+ $input_value = '';
+ }
+ $post{$input_name} = $input_value;
}
}
}