use Encode qw(encode decode);
###PERL_LIB: use lib '/botm/lib/post';
-use botm_common qw(readdatafile);
+use botm_common qw(readdatafile writedatafile join_path);
-###PERL_ENCODING_FILE_IN: use constant ENCODING_FILE_IN => 'UTF-8'
-###PERL_ENCODING_FILE_OUT: use constant ENCODING_FILE_OUT => 'utf8'
-###PERL_ENCODING_STD_IN: use constant ENCODING_STD_IN => 'UTF-8'
-###PERL_ENCODING_STD_OUT: use constant ENCODING_STD_OUT => 'utf8'
+###PERL_ENCODING_FILE_IN: use constant ENCODING_FILE_IN => 'UTF-8';
+###PERL_ENCODING_FILE_OUT: use constant ENCODING_FILE_OUT => 'utf8';
+###PERL_ENCODING_STD_IN: use constant ENCODING_STD_IN => 'UTF-8';
+###PERL_ENCODING_STD_OUT: use constant ENCODING_STD_OUT => 'utf8';
-binmode STDIN, ':encoding('.ENCODING_STD_IN.')';
-# binmode ARGV, ':encoding('.ENCODING_STD_IN.')'; # not working
-binmode STDOUT, ':encoding('.ENCODING_STD_OUT.')';
-binmode STDERR, ':encoding('.ENCODING_STD_OUT.')';
+###PERL_DEFAULT_PASSWORD: use constant DEFAULT_PASSWORD => 'password';
+###PERL_DEFAULT_SUBJECT: use constant DEFAULT_SUBJECT => 'Re: 1190: "Time"';
+###PERL_DEFAULT_USERNAME: use constant DEFAULT_USERNAME => 'username';
-my $helptext =
+###PERL_MIRROR_URL: use constant MIRROR_URL => 'https://1190.bicyclesonthemoon.info/ott';
+
+use constant HELP_TEXT =>
"sendpost [options] [file(s)]\n".
- " -s, --username=USERNAME\n".
+ " -l, --username=USERNAME\n".
" -p, --password=PASSWORD\n".
" -t, --subject=POST_SUBJECT\n".
" -c, --content=POST_CONTENT\n".
"\n".
" -M, --mirror\n".
" -m, --no-mirror\n".
+ " -R, --mirror-url=MIRROR_URL\n",
"\n".
" -h, --help\n";
+binmode STDIN, ':encoding('.ENCODING_STD_IN.')';
+# binmode ARGV, ':encoding('.ENCODING_STD_IN.')'; # not working
+binmode STDOUT, ':encoding('.ENCODING_STD_OUT.')';
+binmode STDERR, ':encoding('.ENCODING_STD_OUT.')';
+
my %options = {};
foreach my $arg (@ARGV) {
'mirror|M' => \$options{ 'mirror'},
'no-mirror|m' => \$options{'no-mirror'},
+ 'mirror-url|R=s' => \$options{ 'mirror-url'},
+
'help|h' => \$options{ 'help'}
);
if ($options{'help'} ne '') {
- print $helptext;
+ print HELP_TEXT;
exit 0;
}
-
-print "options\n";
-foreach my $ind (keys %options) {
- print $ind.'='.$options{$ind}."\n";
+if ($options{'mirror-url'} eq '') {
+ $options{'mirror-url'} = MIRROR_URL;
}
-print;
+
+print "options:\n";
+my $a = writedatafile(\*STDOUT, ENCODING_STD_OUT, 0, \%options);
+print "$a\n";
+# foreach my $ind (keys %options) {
+ # print $ind.'='.$options{$ind}."\n";
+# }
+# print;
foreach my $arg (@ARGV) {
print "\nFILE $arg\n";
my %data = readdatafile($arg, 'utf8', 1);
print $ind.'='.$data{$ind}."\n";
}
}
-if ((scalar @ARGV) == 0) {
- print "\nSTDIN\n";
- my $fh;
- my %data = readdatafile(\*STDIN, 'utf8', 1);
- foreach my $ind (keys %data) {
- print $ind.'='.$data{$ind}."\n";
+# if ((scalar @ARGV) == 0) {
+ # print "\nSTDIN\n";
+ # my $fh;
+ # my %data = readdatafile(\*STDIN, 'utf8', 1);
+ # foreach my $ind (keys %data) {
+ # print $ind.'='.$data{$ind}."\n";
+ # }
+# }
+
+
+sub prepare_post {
+ (my $cmd_options, my $file_data) = @_;
+ my %post;
+
+ if ($cmd_options->{'subject'}) ne '') {
+ $post{'subject'} = $cmd_options->{'subject'};
+ }
+ elsif ($file_data->{'subject'}) ne '') {
+ $post{'subject'} = $file_data->{'subject'};
+ }
+ else {
+ $post{'subject'} = DEFAULT_SUBJECT;
+ }
+
+ if ($cmd_options->{'username'}) ne '') {
+ $post{'username'} = $cmd_options->{'username'};
+ }
+ elsif ($file_data->{'username'}) ne '') {
+ $post{'username'} = $file_data->{'username'};
+ }
+ else {
+ $post{'username'} = DEFAULT_USERNAME;
+ }
+
+ if ($cmd_options->{'password'}) ne '') {
+ $post{'password'} = $cmd_options->{'password'};
+ }
+ elsif ($file_data->{'password'}) ne '') {
+ $post{'password'} = $file_data->{'password'};
+ }
+ else {
+ $post{'password'} = DEFAULT_PASSWORD;
+ }
+
+ if ($cmd_options->{'content'}) ne '') {
+ $post{'content'} = $cmd_options->{'content'};
+ }
+ elsif ($file_data->{'content'}) ne '') {
+ $post{'content'} = $file_data->{'content'};
+ }
+ else {
+ $post{'content'} = '';
}
+
+ if ($cmd_options->{'no-bbcode'}) ne '') {
+ $post{'bbcode'} = 0;
+ }
+ elsif ($cmd_options->{'bbcode'}) ne '') {
+ $post{'bbcode'} = 1;
+ }
+ elsif ($file_data->{'bbcode'}) ne '') {
+ $post{'bbcode'} = $file_data->{'bbcode'}+0;
+ }
+ else {
+ $post{'bbcode'} = 1;
+ }
+
+ if ($cmd_options->{'no-smilies'}) ne '') {
+ $post{'smilies'} = 0;
+ }
+ elsif ($cmd_options->{'smilies'}) ne '') {
+ $post{'smilies'} = 1;
+ }
+ elsif ($file_data->{'smilies'}) ne '') {
+ $post{'smilies'} = $file_data->{'smilies'}+0;
+ }
+ else {
+ $post{'smilies'} = 1;
+ }
+
+ if ($cmd_options->{'no-urls'}) ne '') {
+ $post{'urls'} = 0;
+ }
+ elsif ($cmd_options->{'urls'}) ne '') {
+ $post{'urls'} = 1;
+ }
+ elsif ($file_data->{'urls'}) ne '') {
+ $post{'urls'} = $file_data->{'urls'}+0;
+ }
+ else {
+ $post{'urls'} = 1;
+ }
+
+ if ($cmd_options->{'no-signature'}) ne '') {
+ $post{'signature'} = 0;
+ }
+ elsif ($cmd_options->{'signature'}) ne '') {
+ $post{'signature'} = 1;
+ }
+ elsif ($file_data->{'signature'}) ne '') {
+ $post{'signature'} = $file_data->{'signature'}+0;
+ }
+ else {
+ $post{'signature'} = 1;
+ }
+
+ if ($cmd_options->{'no-notify'}) ne '') {
+ $post{'notify'} = 0;
+ }
+ elsif ($cmd_options->{'notify'}) ne '') {
+ $post{'notify'} = 1;
+ }
+ elsif ($file_data->{'notify'}) ne '') {
+ $post{'notify'} = $file_data->{'notify'}+0;
+ }
+ else {
+ $post{'notify'} = 0;
+ }
+
+ if ($file_data->{'time'}) ne '') {
+ $post{'time'} = $file_data->{'time'}+0;
+ }
+ else {
+ $post{'time'} = 0;
+ }
+
+ return %post;
}
+sub post_to_mirror {
+ (my $cmd_options, my $post) = @_;
+ my $post_url = join_path('/', $cmd_options->{'mirror-url'}, 'post');
+
+}
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+_PERL_STR: '@_ESCAPE($0,')'
_SHEBANG: #!$0
_PERL_USE_2: use $0 $1;
_PERL_CONSTANT: use constant $0 => $1;
+_PERL_CONSTANT_STR: @_PERL_CONSTANT($0,@_PERL_STR($1))
MAKE_CONFIGURE = CONFIGURE = $configure
MAKE_TARGET = TARGET = $target
MAKE_LIB_PATH = LIB_PATH = $lib_path
-PERL_ENCODING_FILE_IN = @_PERL_CONSTANT(ENCODING_FILE_IN , '$encoding_file_in')
-PERL_ENCODING_FILE_OUT = @_PERL_CONSTANT(ENCODING_FILE_OUT, '$encoding_file_out')
-PERL_ENCODING_STD_IN = @_PERL_CONSTANT(ENCODING_STD_IN , '$encoding_std_in')
-PERL_ENCODING_STD_OUT = @_PERL_CONSTANT(ENCODING_STD_OUT , '$encoding_std_out')
+PERL_DEFAULT_PASSWORD = @_PERL_CONSTANT_STR( DEFAULT_PASSWORD , $default_password)
+PERL_DEFAULT_SUBJECT = @_PERL_CONSTANT_STR( DEFAULT_SUBJECT , $default_subject)
+PERL_DEFAULT_USERNAME = @_PERL_CONSTANT_STR( DEFAULT_USERNAME , $default_username)
+PERL_ENCODING_FILE_IN = @_PERL_CONSTANT_STR( ENCODING_FILE_IN , $encoding_file_in)
+PERL_ENCODING_FILE_OUT = @_PERL_CONSTANT_STR( ENCODING_FILE_OUT, $encoding_file_out)
+PERL_ENCODING_STD_IN = @_PERL_CONSTANT_STR( ENCODING_STD_IN , $encoding_std_in)
+PERL_ENCODING_STD_OUT = @_PERL_CONSTANT_STR( ENCODING_STD_OUT , $encoding_std_out)
+PERL_MIRROR_URL = @_PERL_CONSTANT_STR( MIRROR_URL , $mirror_url);
+
PERL_LIB = @_PERL_USE_2(lib, '$lib_path')