Mail::MtPolicyd::Cookbook::BasicPlugin(3pm) | User Contributed Perl Documentation | Mail::MtPolicyd::Cookbook::BasicPlugin(3pm) |
Mail::MtPolicyd::Cookbook::BasicModule - how to write your own mtpolicyd plugin
version 2.04
mtpolicyd makes use of Moose. If you're not yet familiar with Moose you should start reading the Moose::Intro first.
A plugin in mtpolicyd is basically a class which inherits from Mail::MtPolicyd::Plugin and is located below the Mail::MtPolicyd::Plugin:: namespace:
package Mail::MtPolicyd::Plugin::HelloWorld; use Moose; use namespace::autoclean; # VERSION # ABSTRACT: a mtpolicyd plugin which just returns a hello world reject extends 'Mail::MtPolicyd::Plugin'; use Mail::MtPolicyd::Plugin::Result; sub run { my ( $self, $r ) = @_; return Mail::MtPolicyd::Plugin::Result->new( action => 'reject Hello World!', abort => 1, ); } __PACKAGE__->meta->make_immutable; 1;
Every plugin must implement a run() method. mtpolicyd will call run() every time your module is called from the configuration to process a request. A Mail::MtPolicyd::Request object containing the current request is passed to the method. The run() method must return undef or a <Mail::MtPolicyd::Plugin::Result> object. If undef is return mtpolicyd will continue with the next plugin. If a result is returned mtpolicyd will push the result to the list of results and abort processing the request if abort is set.
After you placed the module with your lib search path you should be able to use the plugin within mtpolicyd.conf:
<Plugin hello-world> module = "HelloWorld" </Plugin>
For now our plugin will just return an "reject Hello World!" action to the MTA.
All options defined in the configuration file will be passed to the object constructor new() when creating an object of your plugin class.
The parameter "module" is not passed to the object constructor because it contains the name of your class.
You can defined configuration parameters by adding attributes to your class.
You're class already inherits 3 attributes from the Plugin base class:
If set to "continue" mtpolicyd will continue processing and just leaves a line in the log.
Add a new attribute to your plugin class:
has 'text' => ( is => 'rw', isa => 'Str', default => 'Hello World!');
Return this string instead of the hard coded string:
action => 'reject '.$self->text,
The string is now configurable from the configuration:
<Plugin hello-world> module = "HelloWorld" text = "Hello Universe!" </Plugin>
Markus Benning <ich@markusbenning.de>
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991
2020-06-03 | perl v5.30.2 |