" -t, --subject=POST_SUBJECT\n".
" -c, --content=POST_CONTENT\n".
" -e, --edit=POST_ID\n".
+ " -a, --append\n".
"\n".
" -d, --data-only\n".
"\n".
'subject|t=s' => \$options{'subject'},
'content|c=s' => \$options{'content'},
'edit|e=s' => \$options{'edit'},
+ 'append|a' => \$options{'append'},
'data-only|d' => \$options{'data-only'},
my $time = time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time);
+my $timetext = sprintf (
+ "%04d-%02d-%02d %02d:%02d:%02d",
+ $year+1900, $mon+1, $mday, $hour, $min, $sec
+);
if ($options{'quiet'} ne '') {
$options{'verbose'} = '';
}
unless ($options{'quiet'} ne '') {
- print sprintf (
- "POST BOT $$ $time - %04d-%02d-%02d %02d:%02d:%02d\n",
- $year+1900, $mon+1, $mday, $hour, $min, $sec
- );
+ print "POST BOT $$ $time - $timetext\n\n";
if ($options{'verbose'} ne '') {
print "OPTIONS:\n";
write_data_file(\*STDOUT, 'console_out', 0, \%options);
'verbose' => $cmd_options->{'verbose'}
);
my %post_data = ();
+ my %previous_post= ();
my %query_data = ();
my %header = ();
my $fh;
return $r;
}
- %header = read_header_file($tmp_path, ENCODING_MIRROR());
+ unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) {
+ unless ($cmd_options->{'quiet'} ne '') {
+ print "FAIL open $tmp_path\n";
+ }
+ print STDERR "Failed to open edit page. $tmp_path\n";
+ return 1;
+ }
+
+ %header = read_header_file($fh, ENCODING_MIRROR());
if ($cmd_options->{'verbose'} ne '') {
print "HEADER\n";
write_data_file(\*STDOUT, 'console_out', 0, \%header);
return int($header{':status-code'})
}
+ 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 1;
+ }
+ if ($cmd_options->{'verbose'} ne '') {
+ print "PREVIOUS POST\n";
+ write_data_file(\*STDOUT, 'console_out', 0, \%previous_post);
+ print "\n";
+ }
+ }
+
+ close ($fh);
+
$wget_options{'referer'} = $edit_url;
$wget_options{'postdata_path'} = $postdata_path;
- $post_data{'subject'} = $post->{'subject'};
+ if ($previous_post{'content'} ne '') {
+ $post_data{'subject'} = $previous_post{'subject'};
+ $post_data{'message'} =
+ $previous_post{'content'}.
+ "\n[size=110][b]".$post->{'subject'}.'[/b][/size] [size=80]'.
+ $timetext."[/size]\n".$post->{'content'};
+ }
+ else {
+ $post_data{'subject'} = $post->{'subject'};
+ $post_data{'message'} = $post->{'content'};
+ }
$post_data{'username'} = $post->{'username'};
$post_data{'password'} = $post->{'password'};
$post_data{'password2'} = '';
- $post_data{'message'} = $post->{'content'};
unless ($post->{'bbcode'}) {
$post_data{'disable_bbcode'} = 'on';
}
}
else {
unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) {
- return "Failed to open $file";
+ return (0, "Failed to open $file");
}
}
return ($ok, $text);
}
+# at this moment only returning subject & content
+sub get_mirror_previous_post {
+ (my $file) = @_;
+ my $fh;
+ my %post;
+ my $text;
+ my $tag;
+ my $textarea = 0;
+
+ if(ref($file)) {
+ $fh=$file;
+ }
+ else {
+ unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) {
+ $post{'error'} = "Failed to open $file";
+ return %post;
+ }
+ }
+
+ while (defined(my $line = <$fh>)) {
+ while ($line ne '') {
+ if ($line =~ /^([^<]*)(<.*)$/s) {
+ $text = $1;
+ $line = $2;
+ }
+ else {
+ $text = $line;
+ $line = '';
+ }
+ if ($textarea) {
+ $post{'content'} .= html_entity_decode($text);
+ }
+ if ($line eq '') {
+ last;
+ }
+
+ if ($line =~ /^(<[^>]*>)(.*)$/s) {
+ $tag = lc($1);
+ $line = $2;
+ }
+ else { # oh no tag doesn't end on this line - whatever, I don't care.
+ $tag = $line;
+ $line = '';
+ }
+
+ if ($tag =~ /^<textarea (.* )?id="message"/) {
+ $textarea = 1;
+ }
+ elsif ($tag =~ /<\/textarea/) {
+ $textarea = 0;
+ }
+
+ # SKIP!: form_token creation_time attachment (from post.awk)
+ if ($tag =~ /name="subject"/) {
+ $tag =~ /value="([^"]*)"/;
+ $post{'subject'} = html_entity_decode($1);
+ }
+ }
+ }
+ return %post;
+}
+
sub wget {
(my $url, my $path, my $options, my $postdata) = @_;