[svn:qpsmtpd] r686 - contrib/hjp/address_notes

[email protected] Sat, 16 Dec 2006 02:19:30 -0800 (PST)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: hjp
Date: Sat Dec 16 02:19:29 2006
New Revision: 686

Added:
   contrib/hjp/address_notes/
   contrib/hjp/address_notes/Makefile
   contrib/hjp/address_notes/address_notes
   contrib/hjp/address_notes/address_notes_aliases
   contrib/hjp/address_notes/address_notes_test
   contrib/hjp/address_notes/qpsmtpd-plugin-address_notes.spec

Log:
Added plugin address_notes:

This plugin adds a notes method to the Qpsmtpd::Address class.
This allows arbitrary data to be attached to an address similar to the
connection and transaction notes. One possible use would be to use it to
pass per-recipient configuration between plugins.



Added: contrib/hjp/address_notes/Makefile
==============================================================================
--- (empty file)
+++ contrib/hjp/address_notes/Makefile	Sat Dec 16 02:19:29 2006
@@ -0,0 +1,14 @@
+NAME=address_notes
+FILES = $(PKG).spec \
+    Makefile \
+    address_notes \
+    address_notes_aliases \
+    address_notes_test \
+
+all:
+
+clean:
+	rm -f $(PKG).tar.gz *.tmp
+
+include Makerules
+

Added: contrib/hjp/address_notes/address_notes
==============================================================================
--- (empty file)
+++ contrib/hjp/address_notes/address_notes	Sat Dec 16 02:19:29 2006
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+=head1 NAME
+
+address_notes - add a notes method to Qpsmtpd::Address
+
+=head1 DESCRIPTION
+
+This plugin adds a notes method to the Qpsmtpd::Address class.
+This allows arbitrary data to be attached to an address similar to the
+connection and transaction notes. One possible use would be to use it to
+pass per-recipient configuration between plugins.
+
+=head2 $address->notes([$key [, $value]])
+
+The notes method can be called with 0, 1, or 2 parameters. If both a key
+and a value is given, the note with the given key is set to the given
+value. If only a key is given, the note with this key is returned. If
+neither is given, a list of keys is returned.
+
+=cut
+
+
+package Qpsmtpd::Address;
+use Qpsmtpd::Constants;
+
+sub notes {
+    my $self = shift;
+    if (@_) {
+	my $c = shift;
+	if (@_) {
+	    $self->{notes}{$c} = $_[0];
+	} else {
+	    return $self->{notes}{$c};
+	}
+    } else {
+	if ($self->{notes}) {
+	    return keys %{ $self->{notes} };
+	} else {
+	    return ();
+	}
+    }
+}

Added: contrib/hjp/address_notes/address_notes_aliases
==============================================================================
--- (empty file)
+++ contrib/hjp/address_notes/address_notes_aliases	Sat Dec 16 02:19:29 2006
@@ -0,0 +1,12 @@
+sub hook_rcpt {
+    my ($self, $transaction, $recipient) = @_;
+    $self->log(LOGINFO, "in address_notes_aliases for recipient $recipient\n");
+    if (my $ro = $transaction->notes('recipient_options')) {
+	for (keys %$ro) {
+	    $self->log(LOGINFO, "setting option $_ => $ro->{$_} for recipient $recipient\n");
+	    $recipient->notes($_, $ro->{$_});
+	}
+    }
+    return DECLINED;
+}
+# vim:sw=4 tw=0 expandtab

Added: contrib/hjp/address_notes/address_notes_test
==============================================================================
--- (empty file)
+++ contrib/hjp/address_notes/address_notes_test	Sat Dec 16 02:19:29 2006
@@ -0,0 +1,9 @@
+sub hook_rcpt {
+    my ($self, $transaction, $recipient) = @_;
+    $self->log(LOGINFO, "in address_notes_test for recipient $recipient\n");
+    for ($recipient->notes) {
+	$self->log(LOGINFO, "$recipient has note $_ => " .  $recipient->notes($_));
+    }
+    return DECLINED;
+}
+# vim: sw=4 tw=0 expandtab

Added: contrib/hjp/address_notes/qpsmtpd-plugin-address_notes.spec
==============================================================================
--- (empty file)
+++ contrib/hjp/address_notes/qpsmtpd-plugin-address_notes.spec	Sat Dec 16 02:19:29 2006
@@ -0,0 +1,44 @@
+Name: qpsmtpd-plugin-address_notes
+Version: 195
+Release: 1
+Packager: [email protected]
+Summary: plugin to add notes to Qpsmtpd::Address
+License: distributable
+Group: System Environment/Daemons
+URL: http://smtpd.develooper.com/
+BuildRoot: %{_tmppath}/%{name}-root
+Source0: %{name}.tar.gz
+BuildArch: noarch
+
+%description
+This plugin adds a notes method to the Qpsmtpd::Address class.
+This allows arbitrary data to be attached to an address similar to the
+connection and transaction notes. One possible use would be to use it to
+pass per-recipient configuration between plugins.
+
+%prep
+%setup -q -c %{name}
+
+%build
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%install
+rm -rf $RPM_BUILD_ROOT
+mkdir -p $RPM_BUILD_ROOT/usr/share/qpsmtpd/plugins
+cp address_notes* $RPM_BUILD_ROOT/usr/share/qpsmtpd/plugins
+
+[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress
+
+
+%files
+%defattr(-,root,root)
+/usr/share/qpsmtpd/plugins/address_notes
+/usr/share/qpsmtpd/plugins/address_notes_aliases
+/usr/share/qpsmtpd/plugins/address_notes_test
+
+%changelog
+* Sat Aug 05 2006 <[email protected]> 195-1
+- First RPM package.
+