Open Discussion → How to use the XML-RPC interface

How to use the XML-RPC interface

Hi all,

I configured popfile to make the XML-RPC proxy listen on port 8081.

Then I'm running this little test script:

#! /usr/bin/env perl

use strict;
use XMLRPC::Lite;
 
my $xmlrpc = XMLRPC::Lite ->proxy('http://localhost:8081/RPC2');

my $sk = $xmlrpc->call('POPFile/API.get_session_key','admin', '')-> result;

print "session key: $sk\n";

print $xmlrpc->call('POPFile/API.classify',$sk,'spam.txt')-> result;
print "\n";

my @buckets = $xmlrpc->call('POPFile/API.get_all_buckets', $sk)->result;

$" = ", ";
print "buckets:\n@buckets\n";

$xmlrpc->call('POPFile/API.release_session_key', $sk);

and this is the output I get:

perl xml-rpc-test.pl
session key: vxxLOvG9Glie41IVK
unclassified
buckets:
ARRAY(0xa6d8ab8)

I'd like to see a human readable representation of the array with the buckets, which is not what I see. How am I supposed to treat the result of the get_buckets RPC request?

Also, how am I supposed to make popfile actually *process* the mail, and put it in the history?

TIA, regards.

  • Message #1241

    I'd like to see a human readable representation of the array with the buckets, which is not what I see.

    I'm not a Perl programmer ... but this script manages to list all of the buckets in my system. No doubt there are better ways to do this!

    #!/usr/bin/perl
    
    use strict;
    use XMLRPC::Lite;
     
    my $xmlrpc = XMLRPC::Lite ->proxy('http://localhost:8081/RPC2');
    
    print "Get session key (";
    my $sk = $xmlrpc->call('POPFile/API.get_session_key','admin', '')-> result;
    print "$sk)\n";
    
    my $buckets = $xmlrpc->call('POPFile/API.get_all_buckets', $sk)->result;
    print "\nBuckets:\n";
    foreach my $bucket_name (@$buckets) {
            print "   $bucket_name\n";
        }
    
    print "\nRelease session key\n";
    $xmlrpc->call('POPFile/API.release_session_key', $sk);
    

    Also, how am I supposed to make popfile actually *process* the mail, and put it in the history?

    From the POPFile XML-RPC API:

    handle_message

    call('POPFile/API.handle_message', 'session_key', 'inputfilename', 'outputfilename')

    returns bucketname, the history slot-id, and a Boolean specifying whether a magnet was used for classification, similar to classify but adds message to POPFile history and writes message with POPFile headers to output file. Note, there is a known issue with this call. It presently adds a . and 0x0d0a to the end of output file.

    Brian

    • Message #1242

      I'm not a Perl programmer ... but this script manages to list all of the buckets in my system. No doubt there are better ways to do this!
      {{{
      #!perl
      #!/usr/bin/perl

      use strict;
      use XMLRPC::Lite;

      my $xmlrpc = XMLRPC::Lite ->proxy('http://localhost:8081/RPC2');

      print "Get session key (";
      my $sk = $xmlrpc->call('POPFile/API.get_session_key','admin', )-> result;
      print "$sk)\n";

      my $buckets = $xmlrpc->call('POPFile/API.get_all_buckets', $sk)->result;
      print "\nBuckets:\n";
      foreach my $bucket_name (@$buckets) {
      print " $bucket_name\n";
      }

      print "\nRelease session key\n";
      $xmlrpc->call('POPFile/API.release_session_key', $sk);
      }}}

      Thanks brian that did the trick, $xmlrpc->call is returning a *reference* to the list, so I need to dereference it (maybe this fact should be stressed in the docs).

      Also, how am I supposed to make popfile actually *process* the mail, and put it in the history?


      From the POPFile XML-RPC API:

      handle_message
      call('POPFile/API.handle_message', 'session_key', 'inputfilename', 'outputfilename')
      returns bucketname, the history slot-id, and a Boolean specifying whether a magnet was used for classification, similar to classify but adds message to POPFile history and writes message with POPFile headers to output file. Note, there is a known issue with this call. It presently adds a . and 0x0d0a to the end of output file.

      Thanks again, greetings.

      • Message #1245

        Thanks brian that did the trick, $xmlrpc->call is returning a *reference* to the list, so I need to dereference it (maybe this fact should be stressed in the docs)

        I've raised ticket:142 for this in case it gets forgotten (it is very easy to overlook something mentioned in the forums). At least one of the examples also needs to be updated to work with the current API, I think.

        Brian