From 06a4de26e05b74e3ed5493cef205af91462678a1 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 23 Sep 2012 20:57:43 +0200 Subject: Making the list creation method. --- lib/Fripost/Schema/List.pm | 27 +++++++++++++++++++++++---- lib/Fripost/Schema/Misc.pm | 1 - 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'lib/Fripost/Schema') diff --git a/lib/Fripost/Schema/List.pm b/lib/Fripost/Schema/List.pm index 69317b1..edf9d24 100644 --- a/lib/Fripost/Schema/List.pm +++ b/lib/Fripost/Schema/List.pm @@ -20,6 +20,8 @@ use parent 'Fripost::Schema'; use Fripost::Schema::Misc qw/concat explode must_attrs email_valid/; use Net::IDN::Encode qw/domain_to_ascii email_to_ascii email_to_unicode/; +use Mail::GnuPG; +use MIME::Entity; =head1 METHODS @@ -105,6 +107,7 @@ sub add { my $l = shift; my %options = @_; + my $lname = $l->{list}; $l->{description} = explode ($options{'-concat'}, $l->{description}) if defined $l->{description}; @@ -114,7 +117,7 @@ sub add { die "Missing list name\n" if $l eq ''; must_attrs( $l, 'transport' ); &_is_valid($l); - die "‘".$l->{list}."‘ alread exists\n" + die "‘".$l->{list}."‘ already exists\n" if $self->local->exists($l->{list},%options); my %attrs = ( objectClass => 'FripostVirtualList' @@ -134,8 +137,24 @@ sub add { die $mesg->error."\n"; } }; - return $@; - # TODO: send email to mklist-$transport to finalize + return $@ if $@; + + # Ask the list manager to create the list now. + my $member = $self->whoami; + $member =~ s/^fvu=([^,]+),fvd=([^,]+),.*$/$1\@$2/; + my $mail = MIME::Entity::->build( + From => 'Fripost Admin Panel ', + To => 'mklist+'.$l->{transport}.'@fripost.org', + Subject => "New ".$l->{transport}." list", + Encoding => 'quoted-printable', + Charset => 'utf-8', + Data => [ map { $_ . "\n"} ($lname, $member, $l->{password}) ] + ); + my $gpg = Mail::GnuPG::->new( %{$options{gpg}} ); + my $ret = $gpg->mime_sign( $mail ); + return join ("\n", @{$gpg->{last_message}}) if $ret; + $mail->send; + return 0; } @@ -166,7 +185,7 @@ sub is_pending { die "Error: Multiple matching entries found." if $mesg->count > 1; my $list = $mesg->pop_entry; - + die "Error: No matching entry found." unless defined $list; my $r = $list->get_value('fripostIsStatusPending'); return (defined $r and $r eq 'TRUE'); diff --git a/lib/Fripost/Schema/Misc.pm b/lib/Fripost/Schema/Misc.pm index 39fa3b7..745a20b 100644 --- a/lib/Fripost/Schema/Misc.pm +++ b/lib/Fripost/Schema/Misc.pm @@ -10,7 +10,6 @@ use 5.010_000; use strict; use warnings; use utf8; -use feature "unicode_strings"; use Exporter 'import'; our @EXPORT_OK = qw /concat get_perms explode -- cgit v1.2.3