SMS coding complete, beginning testing.
Added getInboxAddresses method to User.pm, with tests. All SMS/Email address choices are made in Mail/Send, on create and on send, since that's when it handles groups. Test variable addresses on creating mails. Updated t/smtpd.pl to handle receiving and sending multiple messages.
This commit is contained in:
parent
bc3b204d9b
commit
7336d2d630
6 changed files with 174 additions and 51 deletions
|
|
@ -151,16 +151,17 @@ sub create {
|
||||||
|
|
||||||
my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject};
|
my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject};
|
||||||
my $mail = WebGUI::Mail::Send->create($session, {
|
my $mail = WebGUI::Mail::Send->create($session, {
|
||||||
toUser=>$self->{_properties}{userId},
|
toUser => $self->{_properties}{userId},
|
||||||
toGroup=>$self->{_properties}{groupId},
|
toGroup => $self->{_properties}{groupId},
|
||||||
subject=>$subject,
|
subject => $subject,
|
||||||
});
|
},
|
||||||
|
'fromInbox',
|
||||||
|
);
|
||||||
if (defined $mail) {
|
if (defined $mail) {
|
||||||
my $preface = "";
|
my $preface = "";
|
||||||
my $fromUser = WebGUI::User->new($session, $properties->{sentBy});
|
my $fromUser = WebGUI::User->new($session, $properties->{sentBy});
|
||||||
#Don't append prefaces to the visitor users or messages that don't specify a user (default case)
|
#Don't append prefaces to the visitor users or messages that don't specify a user (default case)
|
||||||
unless ($fromUser->isVisitor || $fromUser->userId eq 3) { #Can't use isAdmin because it will not send prefaces from normal users who in the admin group
|
unless ($fromUser->isVisitor || $fromUser->userId eq 3) { #Can't use isAdmin because it will not send prefaces from normal users who in the admin group
|
||||||
my $i18n = WebGUI::International->new($session, 'Inbox_Message');
|
|
||||||
$preface = sprintf($i18n->get('from user preface'), $fromUser->username);
|
$preface = sprintf($i18n->get('from user preface'), $fromUser->username);
|
||||||
}
|
}
|
||||||
my $msg = (defined $properties->{emailMessage}) ? $properties->{emailMessage} : $self->{_properties}{message};
|
my $msg = (defined $properties->{emailMessage}) ? $properties->{emailMessage} : $self->{_properties}{message};
|
||||||
|
|
|
||||||
|
|
@ -267,16 +267,28 @@ A unique id for this message, in case you want to see what replies come in for i
|
||||||
|
|
||||||
If this is a reply to a previous message, then you should specify the messageId of the previous message here.
|
If this is a reply to a previous message, then you should specify the messageId of the previous message here.
|
||||||
|
|
||||||
|
=head3 isInbox
|
||||||
|
|
||||||
|
A flag indicating that this email message is from the Inbox, and should follow per user settings
|
||||||
|
for delivery.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub create {
|
sub create {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $headers = shift;
|
my $headers = shift;
|
||||||
|
my $isInbox = shift;
|
||||||
if ($headers->{toUser}) {
|
if ($headers->{toUser}) {
|
||||||
my $user = WebGUI::User->new($session, $headers->{toUser});
|
my $user = WebGUI::User->new($session, $headers->{toUser});
|
||||||
if (defined $user) {
|
if (defined $user) {
|
||||||
my $email = $user->profileField("email");
|
my $email;
|
||||||
|
if ($isInbox) {
|
||||||
|
$email = $user->getInboxAddresses;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$email = $user->profileField("email");
|
||||||
|
}
|
||||||
if ($email) {
|
if ($email) {
|
||||||
if ($headers->{to}) {
|
if ($headers->{to}) {
|
||||||
$headers->{to} .= ','.$email;
|
$headers->{to} .= ','.$email;
|
||||||
|
|
@ -286,9 +298,9 @@ sub create {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">";
|
my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">";
|
||||||
my $type = $headers->{contentType} || "multipart/mixed";
|
my $type = $headers->{contentType} || "multipart/mixed";
|
||||||
my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath");
|
my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath");
|
||||||
|
|
||||||
# format of Message-Id should be '<unique-id@domain>'
|
# format of Message-Id should be '<unique-id@domain>'
|
||||||
my $id = $headers->{messageId} || "WebGUI-" . $session->id->generate;
|
my $id = $headers->{messageId} || "WebGUI-" . $session->id->generate;
|
||||||
|
|
@ -324,7 +336,7 @@ sub create {
|
||||||
delete $headers->{toGroup};
|
delete $headers->{toGroup};
|
||||||
$message->attach(Data=>"This message was intended for ".$to." but was overridden in the config file.\n\n");
|
$message->attach(Data=>"This message was intended for ".$to." but was overridden in the config file.\n\n");
|
||||||
}
|
}
|
||||||
bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup} }, $class;
|
bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup}, _isInbox => $isInbox }, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -467,10 +479,10 @@ sub send {
|
||||||
else {
|
else {
|
||||||
my $smtp = Net::SMTP->new($smtpServer); # connect to an SMTP server
|
my $smtp = Net::SMTP->new($smtpServer); # connect to an SMTP server
|
||||||
if (defined $smtp) {
|
if (defined $smtp) {
|
||||||
$smtp->mail($mail->head->get("X-Return-Path"));
|
$smtp->mail($mail->head->get('X-Return-Path'));
|
||||||
$smtp->to(split(",",$mail->head->get("to")));
|
$smtp->to( split(',', $mail->head->get('to') ));
|
||||||
$smtp->cc(split(",",$mail->head->get("cc")));
|
$smtp->cc( split(',', $mail->head->get('cc') ));
|
||||||
$smtp->bcc(split(",",$mail->head->get("bcc")));
|
$smtp->bcc( split(',', $mail->head->get('bcc') ));
|
||||||
$smtp->data(); # Start the mail
|
$smtp->data(); # Start the mail
|
||||||
$smtp->datasend($mail->stringify);
|
$smtp->datasend($mail->stringify);
|
||||||
$smtp->dataend(); # Finish sending the mail
|
$smtp->dataend(); # Finish sending the mail
|
||||||
|
|
@ -490,15 +502,21 @@ sub send {
|
||||||
if ($group) {
|
if ($group) {
|
||||||
my $group = WebGUI::Group->new($self->session, $group);
|
my $group = WebGUI::Group->new($self->session, $group);
|
||||||
return $status if !defined $group;
|
return $status if !defined $group;
|
||||||
$mail->head->replace("bcc", undef);
|
$mail->head->replace('bcc', undef);
|
||||||
$mail->head->replace("cc", undef);
|
$mail->head->replace('cc', undef);
|
||||||
foreach my $userId (@{$group->getAllUsers(1)}) {
|
USER: foreach my $userId (@{$group->getAllUsers(1)}) {
|
||||||
my $user = WebGUI::User->new($self->session, $userId);
|
my $user = WebGUI::User->new($self->session, $userId);
|
||||||
next unless $user->status eq 'Active'; ##Don't send this to invalid user accounts
|
next USER unless $user->status eq 'Active'; ##Don't send this to invalid user accounts
|
||||||
if ($user->profileField("email")) {
|
my $emailAddress;
|
||||||
$mail->head->replace("To",$user->profileField("email"));
|
if ($self->{_isInbox}) {
|
||||||
$self->queue;
|
$emailAddress = $user->getInboxAddresses;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$emailAddress = $user->profileField('email');
|
||||||
|
}
|
||||||
|
next USER unless $emailAddress;
|
||||||
|
$mail->head->replace('To', $emailAddress);
|
||||||
|
$self->queue;
|
||||||
}
|
}
|
||||||
#Delete the group if it is flagged as an AdHocMailGroup
|
#Delete the group if it is flagged as an AdHocMailGroup
|
||||||
$group->delete if ($group->isAdHocMailGroup);
|
$group->delete if ($group->isAdHocMailGroup);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ my $session = start( $webguiRoot, $configFile );
|
||||||
|
|
||||||
installUserProfileFields($session);
|
installUserProfileFields($session);
|
||||||
installSettings($session);
|
installSettings($session);
|
||||||
|
upgradeMailQueue($session);
|
||||||
|
|
||||||
# Do your work here
|
# Do your work here
|
||||||
finish($session);
|
finish($session);
|
||||||
|
|
@ -58,7 +59,7 @@ sub installUserProfileFields {
|
||||||
);
|
);
|
||||||
WebGUI::ProfileField->create(
|
WebGUI::ProfileField->create(
|
||||||
$session,
|
$session,
|
||||||
'receiveInboxSMSNotifications',
|
'receiveInboxSmsNotifications',
|
||||||
{
|
{
|
||||||
label => q!WebGUI::International::get('receive inbox sms','Message_Center')!,
|
label => q!WebGUI::International::get('receive inbox sms','Message_Center')!,
|
||||||
visible => 1,
|
visible => 1,
|
||||||
|
|
@ -77,6 +78,11 @@ sub installSettings {
|
||||||
$session->setting->add('smsGateway', '');
|
$session->setting->add('smsGateway', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub upgradeMailQueue {
|
||||||
|
my $session = shift;
|
||||||
|
$session->db->write('alter table mailQueue add column isInbox TINYINT(4) default 0');
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub start {
|
sub start {
|
||||||
my $webguiRoot = shift;
|
my $webguiRoot = shift;
|
||||||
|
|
|
||||||
126
t/Mail/Send.t
126
t/Mail/Send.t
|
|
@ -17,10 +17,13 @@ use strict;
|
||||||
use lib "$FindBin::Bin/../lib";
|
use lib "$FindBin::Bin/../lib";
|
||||||
use JSON qw( from_json to_json );
|
use JSON qw( from_json to_json );
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
|
use Data::Dumper;
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
|
|
||||||
use WebGUI::Mail::Send;
|
use WebGUI::Mail::Send;
|
||||||
|
use WebGUI::User;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
|
|
@ -44,12 +47,16 @@ if ($hasServer) {
|
||||||
$oldSettings{ smtpServer } = $session->setting->get('smtpServer');
|
$oldSettings{ smtpServer } = $session->setting->get('smtpServer');
|
||||||
$session->setting->set( 'smtpServer', $SMTP_HOST . ':' . $SMTP_PORT );
|
$session->setting->set( 'smtpServer', $SMTP_HOST . ':' . $SMTP_PORT );
|
||||||
|
|
||||||
|
my $smtpd = File::Spec->catfile( WebGUI::Test->root, 't', 'smtpd.pl' );
|
||||||
|
open MAIL, "perl $smtpd $SMTP_HOST $SMTP_PORT 4 |"
|
||||||
|
or die "Could not open pipe to SMTPD: $!";
|
||||||
|
sleep 1; # Give the smtpd time to establish itself
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 6; # Increment this number for each test you create
|
plan tests => 9; # Increment this number for each test you create
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test create
|
# Test create
|
||||||
|
|
@ -86,7 +93,7 @@ is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test addHtml
|
# Test addHtml
|
||||||
$mail = WebGUI::Mail::Send->create( $session );
|
$mail = WebGUI::Mail::Send->create( $session );
|
||||||
my $text = <<'EOF';
|
$text = <<'EOF';
|
||||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -97,7 +104,7 @@ $mime = $mail->getMimeEntity;
|
||||||
# TODO: Test that addHtml creates a body with the right content type
|
# TODO: Test that addHtml creates a body with the right content type
|
||||||
|
|
||||||
# addHtml should add newlines after 78 characters
|
# addHtml should add newlines after 78 characters
|
||||||
my $newlines = length $text / 78;
|
$newlines = length $text / 78;
|
||||||
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
||||||
"addHtml should add newlines after 78 characters",
|
"addHtml should add newlines after 78 characters",
|
||||||
);
|
);
|
||||||
|
|
@ -107,7 +114,7 @@ is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test addHtmlRaw
|
# Test addHtmlRaw
|
||||||
$mail = WebGUI::Mail::Send->create( $session );
|
$mail = WebGUI::Mail::Send->create( $session );
|
||||||
my $text = <<'EOF';
|
$text = <<'EOF';
|
||||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -117,13 +124,15 @@ $mime = $mail->getMimeEntity;
|
||||||
# TODO: Test that addHtmlRaw doesn't add an HTML wrapper
|
# TODO: Test that addHtmlRaw doesn't add an HTML wrapper
|
||||||
|
|
||||||
# addHtmlRaw should add newlines after 78 characters
|
# addHtmlRaw should add newlines after 78 characters
|
||||||
my $newlines = length $text / 78;
|
$newlines = length $text / 78;
|
||||||
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
||||||
"addHtmlRaw should add newlines after 78 characters",
|
"addHtmlRaw should add newlines after 78 characters",
|
||||||
);
|
);
|
||||||
|
|
||||||
# TODO: Test that addHtml creates a body with the right content type
|
# TODO: Test that addHtml creates a body with the right content type
|
||||||
|
|
||||||
|
my $smtpServerOk = 0;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test emailOverride
|
# Test emailOverride
|
||||||
SKIP: {
|
SKIP: {
|
||||||
|
|
@ -139,6 +148,8 @@ SKIP: {
|
||||||
skip "Cannot test emailOverride: Module Net::SMTP::Server not loaded!", $numtests;
|
skip "Cannot test emailOverride: Module Net::SMTP::Server not loaded!", $numtests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$smtpServerOk = 1;
|
||||||
|
|
||||||
# Override the emailOverride
|
# Override the emailOverride
|
||||||
my $oldEmailOverride = $session->config->get('emailOverride');
|
my $oldEmailOverride = $session->config->get('emailOverride');
|
||||||
$session->config->set( 'emailOverride', 'dufresne@localhost' );
|
$session->config->set( 'emailOverride', 'dufresne@localhost' );
|
||||||
|
|
@ -154,7 +165,7 @@ SKIP: {
|
||||||
|
|
||||||
my $received = sendToServer( $mail );
|
my $received = sendToServer( $mail );
|
||||||
|
|
||||||
if (!$received) {
|
if ($received->{error}) {
|
||||||
skip "Cannot test emailOverride: No response received from smtpd", $numtests;
|
skip "Cannot test emailOverride: No response received from smtpd", $numtests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,6 +179,79 @@ SKIP: {
|
||||||
$session->config->set( 'emailToLog', $oldEmailToLog );
|
$session->config->set( 'emailToLog', $oldEmailToLog );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Test sending an Inbox message to a user who has various notifications configured
|
||||||
|
#
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
my $inboxUser = WebGUI::User->create($session);
|
||||||
|
$inboxUser->username('red');
|
||||||
|
$inboxUser->profileField('receiveInboxEmailNotifications', 1);
|
||||||
|
$inboxUser->profileField('receiveInboxSmsNotifications', 0);
|
||||||
|
$inboxUser->profileField('email', 'ellis_boyd_redding@shawshank.gov');
|
||||||
|
$inboxUser->profileField('cellPhone', '55555');
|
||||||
|
$oldSettings{smsGateway} = $session->setting->get('smsGateway');
|
||||||
|
$session->setting->set('smsGateway', 'textme.com');
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
my $numtests = 1; # Number of tests in this block
|
||||||
|
|
||||||
|
# Must be able to write the config, or we'll die
|
||||||
|
skip "Cannot test email notifications", $numtests unless $smtpServerOk;
|
||||||
|
|
||||||
|
# Send the mail
|
||||||
|
$mail = WebGUI::Mail::Send->create( $session, {
|
||||||
|
toUser => $inboxUser->userId,
|
||||||
|
},
|
||||||
|
'fromInbox',
|
||||||
|
);
|
||||||
|
$mail->addText( 'sent via email' );
|
||||||
|
|
||||||
|
my $received = sendToServer( $mail ) ;
|
||||||
|
|
||||||
|
# Test the mail
|
||||||
|
is($received->{to}->[0], '<ellis_boyd_redding@shawshank.gov>', 'send, toUser with email address');
|
||||||
|
|
||||||
|
$inboxUser->profileField('receiveInboxEmailNotifications', 0);
|
||||||
|
$inboxUser->profileField('receiveInboxSmsNotifications', 1);
|
||||||
|
|
||||||
|
# Send the mail
|
||||||
|
$mail = WebGUI::Mail::Send->create( $session, {
|
||||||
|
toUser => $inboxUser->userId,
|
||||||
|
},
|
||||||
|
'fromInbox',
|
||||||
|
);
|
||||||
|
$mail->addText( 'sent via SMS' );
|
||||||
|
|
||||||
|
my $received = sendToServer( $mail ) ;
|
||||||
|
|
||||||
|
# Test the mail
|
||||||
|
is($received->{to}->[0], '<55555@textme.com>', 'send, toUser with SMS address');
|
||||||
|
|
||||||
|
$inboxUser->profileField('receiveInboxEmailNotifications', 1);
|
||||||
|
$inboxUser->profileField('receiveInboxSmsNotifications', 1);
|
||||||
|
|
||||||
|
# Send the mail
|
||||||
|
$mail = WebGUI::Mail::Send->create( $session, {
|
||||||
|
toUser => $inboxUser->userId,
|
||||||
|
},
|
||||||
|
'fromInbox',
|
||||||
|
);
|
||||||
|
$mail->addText( 'sent via SMS' );
|
||||||
|
|
||||||
|
my $received = sendToServer( $mail ) ;
|
||||||
|
|
||||||
|
# Test the mail
|
||||||
|
cmp_bag(
|
||||||
|
$received->{to},
|
||||||
|
['<55555@textme.com>', '<ellis_boyd_redding@shawshank.gov>',],
|
||||||
|
'send, toUser with SMS and email addresses'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
# TODO: Test the emailToLog config setting
|
# TODO: Test the emailToLog config setting
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -177,6 +261,14 @@ END {
|
||||||
for my $name ( keys %oldSettings ) {
|
for my $name ( keys %oldSettings ) {
|
||||||
$session->setting->set( $name, $oldSettings{ $name } );
|
$session->setting->set( $name, $oldSettings{ $name } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($inboxUser) {
|
||||||
|
$inboxUser->delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
close MAIL
|
||||||
|
or die "Could not close pipe to SMTPD: $!";
|
||||||
|
sleep 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -193,21 +285,17 @@ END {
|
||||||
# by a MIME::Entity parser
|
# by a MIME::Entity parser
|
||||||
sub sendToServer {
|
sub sendToServer {
|
||||||
my $mail = shift;
|
my $mail = shift;
|
||||||
|
my $status = $mail->send;
|
||||||
my $smtpd = File::Spec->catfile( WebGUI::Test->root, 't', 'smtpd.pl' );
|
|
||||||
open MAIL, "perl $smtpd $SMTP_HOST $SMTP_PORT |"
|
|
||||||
or die "Could not open pipe to SMTPD: $!";
|
|
||||||
sleep 1; # Give the smtpd time to establish itself
|
|
||||||
|
|
||||||
$mail->send;
|
|
||||||
my $json;
|
my $json;
|
||||||
while ( my $line = <MAIL> ) {
|
if ($status) {
|
||||||
$json .= $line;
|
$json = <MAIL>;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$json = ' { "error": "mail not sent" } ';
|
||||||
|
}
|
||||||
|
if (!$json) {
|
||||||
|
$json = ' { "error": "error in getting mail" } ';
|
||||||
}
|
}
|
||||||
|
|
||||||
close MAIL
|
|
||||||
or die "Could not close pipe to SMTPD: $!";
|
|
||||||
|
|
||||||
return from_json( $json );
|
return from_json( $json );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
8
t/User.t
8
t/User.t
|
|
@ -658,17 +658,17 @@ $inmate->profileField('email', 'andy@shawshank.com');
|
||||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: email address only');
|
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: email address only');
|
||||||
|
|
||||||
$inmate->profileField('receiveInboxSmsNotifications', 1);
|
$inmate->profileField('receiveInboxSmsNotifications', 1);
|
||||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 but no other profile info');
|
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 but no other profile info');
|
||||||
|
|
||||||
$inmate->profileField('cellPhone', '37927');
|
$inmate->profileField('cellPhone', '37927');
|
||||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and cell phone but no gateway');
|
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and cell phone but no gateway');
|
||||||
|
|
||||||
$inmate->profileField('cellPhone', '');
|
$inmate->profileField('cellPhone', '');
|
||||||
$session->setting->set('smsGateway', 'textme.com');
|
$session->setting->set('smsGateway', 'textme.com');
|
||||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone');
|
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone');
|
||||||
|
|
||||||
$inmate->profileField('cellPhone', '37927');
|
$inmate->profileField('cellPhone', '37927');
|
||||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone');
|
is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone');
|
||||||
|
|
||||||
$inmate->profileField('receiveInboxEmailNotifications', 0);
|
$inmate->profileField('receiveInboxEmailNotifications', 0);
|
||||||
is ($inmate->getInboxAddresses, '37927@textme.com', 'getInboxAddresses: can get SMS and no email, even with email info present');
|
is ($inmate->getInboxAddresses, '37927@textme.com', 'getInboxAddresses: can get SMS and no email, even with email info present');
|
||||||
|
|
|
||||||
14
t/smtpd.pl
14
t/smtpd.pl
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
my $HOST = shift;
|
my $HOST = shift;
|
||||||
my $PORT = shift;
|
my $PORT = shift;
|
||||||
|
my $EMAILS = shift || 1;
|
||||||
|
|
||||||
die "HOST must be first argument"
|
die "HOST must be first argument"
|
||||||
unless $HOST;
|
unless $HOST;
|
||||||
|
|
@ -13,17 +14,26 @@ use Net::SMTP::Server::Client;
|
||||||
|
|
||||||
my $server = Net::SMTP::Server->new( $HOST, $PORT );
|
my $server = Net::SMTP::Server->new( $HOST, $PORT );
|
||||||
|
|
||||||
while ( my $conn = $server->accept ) {
|
my $counter = 0;
|
||||||
|
|
||||||
|
$| = 1;
|
||||||
|
|
||||||
|
CONNECTION: while ( my $conn = $server->accept ) {
|
||||||
my $client = Net::SMTP::Server::Client->new( $conn );
|
my $client = Net::SMTP::Server::Client->new( $conn );
|
||||||
$client->process;
|
$client->process;
|
||||||
print to_json({
|
print to_json({
|
||||||
to => $client->{TO},
|
to => $client->{TO},
|
||||||
from => $client->{FROM},
|
from => $client->{FROM},
|
||||||
contents => $client->{MSG},
|
contents => $client->{MSG},
|
||||||
|
counter => $counter,
|
||||||
|
emails => $EMAILS,
|
||||||
});
|
});
|
||||||
exit(0);
|
print "\n";
|
||||||
|
last CONNECTION if ++$counter >= $EMAILS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sleep 3;
|
||||||
|
exit(0);
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue