/[notice-sender]/trunk/Nos.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Nos.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by dpavlin, Sun May 15 21:52:56 2005 UTC revision 23 by dpavlin, Sun May 15 22:12:31 2005 UTC
# Line 73  sub new { Line 73  sub new {
73          $self ? return $self : return undef;          $self ? return $self : return undef;
74  }  }
75    
76    =head2 add_member_to_list
77    
78    Add new member to list
79    
80     $nos->add_member_to_list(
81            list => "My list",
82            email => "john.doe@example.com",
83            name => "John A. Doe",
84     );
85    
86    C<name> parametar is optional.
87    
88    Return true if user is added.
89    
90    =cut
91    
92    sub add_member_to_list {
93            my $self = shift;
94    
95            my $arg = {@_};
96    
97            my $email = $arg->{'email'} || confess "can't add user without e-mail";
98            my $name = $arg->{'name'} || '';
99            confess "need list name" unless ($arg->{'list'});
100    
101            if (! Email::Valid->address($email)) {
102                    warn "SKIPPING $name <$email>";
103                    return 0;
104            }
105    
106            print "# $name <$email>\n";
107    
108            my $lists = $self->{'loader'}->find_class('lists');
109            my $users = $self->{'loader'}->find_class('users');
110            my $user_list = $self->{'loader'}->find_class('user_list');
111    
112            my $list = $lists->find_or_create({
113                    name => $arg->{'list'},
114            }) || croak "can't add list ",$arg->{'list'},"\n";
115            
116            my $this_user = $users->find_or_create({
117                    email => $email,
118                    full_name => $name,
119            }) || croak "can't find or create member\n";
120    
121            my $user_on_list = $user_list->find_or_create({
122                    user_id => $this_user->id,
123                    list_id => $list->id,
124            }) || croak "can't add user to list";
125    
126            $list->dbi_commit;
127            $this_user->dbi_commit;
128            $user_on_list->dbi_commit;
129    
130            return 1;
131    }
132    
133  =head2 send_queued_messages  =head2 send_queued_messages
134    
135  Send queued messages or just ones for selected list  Send queued messages or just ones for selected list

Legend:
Removed from v.22  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC 1.1.26