I've noticed in the past that the QP team prefers to receive multiple
smaller patches in a set rather than one large patch for significant
changes.  I can't say I have a set together yet for the significant
change (per-recipient prefs), but I'm working on it, and I've attached a
couple of versions of a pretty digestible patch to make the popular
'notes' method from cxn/txn objects available for address objects.  This
may have some immediate uses, but will be especially useful in a bright
future when plugins of all kinds are concerned about each recipient in a
transaction.

rcpt_notes.diff:

adds notes() to Qpsmtpd::Address, and contains some functional changes
and cleanups along the way.  Most notably for Address:host(), user(),
notes() and Connection::notes(), Transaction::notes(): it changes the
'set' version of these get/set methods to return $self.  This makes it
possible to do things like:

$rcpt->user('jaredj')->host('nmgi.com')->notes(score => 5.0);

where one was previously forced to do:

$rcpt->user('jaredj');
$rcpt->host('nmgi.com');
$rcpt->notes(score => 5.0);

It also removes some commented debug code, drops multiple 'my $foo =
shift' statements in favor of my (...) = @_, and brings the language in
the POD for notes() in Qpsmtpd::Connection in line with the language for
the same in Qpsmtpd::Transaction, and now in Qpsmtpd::Address as well.



rcpt_notes_minor.diff:

Less ambitious patch to simply add a notes() method to Qpsmtpd::Address,
in case we aren't interested in the larger changes for one reason or
another.


Feel free to take the big one, take the little one, or give me feedback
to make the big one and/or the little one more suitable.  Thanks for
reading!

Jared Johnson
Software Developer and Support Engineer
Network Management Group, Inc.
620-664-6000 x118

Index: lib/Qpsmtpd/Transaction.pm
===================================================================
--- lib/Qpsmtpd/Transaction.pm	(revision 967)
+++ lib/Qpsmtpd/Transaction.pm	(working copy)
@@ -55,11 +55,10 @@
 #}
 
 sub notes {
-  my $self = shift;
-  my $key  = shift;
-  @_ and $self->{_notes}->{$key} = shift;
-  #warn Data::Dumper->Dump([\$self->{_notes}], [qw(notes)]);
-  $self->{_notes}->{$key};
+  my ($self,$key,$value) = @_;
+  return $self->{_notes}->{$key} unless defined $value;
+  $self->{_notes}->{$key} = $value;
+  return $self;
 }
 
 sub set_body_start {
Index: lib/Qpsmtpd/Address.pm
===================================================================
--- lib/Qpsmtpd/Address.pm	(revision 967)
+++ lib/Qpsmtpd/Address.pm	(working copy)
@@ -297,8 +297,9 @@
 
 sub user {
     my ($self, $user) = @_;
-    $self->{_user} = $user if defined $user;
-    return $self->{_user};
+    return $self->{_user} unless defined $user;
+    $self->{_user} = $user;
+    return $self;
 }
 
 =head2 host([$host])
@@ -313,10 +314,26 @@
 
 sub host {
     my ($self, $host) = @_;
-    $self->{_host} = $host if defined $host;
-    return $self->{_host};
+    return $self->{_host} unless defined $host;
+    $self->{_host} = $host;
+    return $self;
 }
 
+=head2 notes($key[,$value])
+
+Get or set a note on the recipient. This is a piece of data that you wish
+to attach to the recipient and read somewhere else. For example you can
+use this to pass data between plugins.
+
+=cut
+
+sub notes {
+    my ($self,$key,$value) = @_;
+    return $self->{_notes}->{$key} unless defined $value;
+    $self->{_notes}->{$key} = $value;
+    return $self;
+}
+
 sub _addr_cmp {
     require UNIVERSAL;
     my ($left, $right, $swap) = @_;
Index: lib/Qpsmtpd/Connection.pm
===================================================================
--- lib/Qpsmtpd/Connection.pm	(revision 967)
+++ lib/Qpsmtpd/Connection.pm	(working copy)
@@ -108,10 +108,10 @@
 }
 
 sub notes {
-  my $self = shift;
-  my $key  = shift;
-  @_ and $self->{_notes}->{$key} = shift;
-  $self->{_notes}->{$key};
+  my ($self,$key,$value) = @_;
+  return $self->{_notes}->{$key} unless defined $value;
+  $self->{_notes}->{$key} = $value;
+  return $self;
 }
 
 sub reset {
@@ -200,7 +200,9 @@
 
 =head2 notes($key [, $value])
 
-Connection-wide notes, used for passing data between plugins.
+Get or set a note on the transaction. This is a piece of data that you wish
+to attach to the transaction and read somewhere else. For example you can
+use this to pass data between plugins.
 
 =head2 clone([%args])
 
Index: lib/Qpsmtpd/Address.pm
===================================================================
--- lib/Qpsmtpd/Address.pm	(revision 7285)
+++ lib/Qpsmtpd/Address.pm	(working copy)
@@ -317,6 +317,21 @@
     return $self->{_host};
 }
 
+=head2 notes($key[,$value])
+
+Get or set a note on the recipient. This is a piece of data that you wish
+to attach to the recipient and read somewhere else. For example you can
+use this to pass data between plugins.
+
+=cut
+
+sub notes {
+    my $self = shift;
+    my $key  = shift;
+    @_ and $self->{_notes}->{$key} = shift;
+    $self->{_notes}->{$key};
+}
+
 sub _addr_cmp {
     require UNIVERSAL;
     my ($left, $right, $swap) = @_;

Reply via email to