# Copyright (c) 2012 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: MailReceiveDispatchForm.bunit,v 1.14 2011/04/22 22:57:43 nagler Exp $ # Copyright (c) 2002-2005 bivio Software, Inc. All rights reserved. config({ class() => { ignore_dashes_in_recipient => 0, }, }); Request('initialize_fully', 'MAIL_RECEIVE_DISPATCH'); [ [req()] => [ { method => 'process', compute_params => sub { my($case, $params) = @_; req()->set_realm(undef); req()->set_user(undef); my($from, $recipient, $header) = @$params; $header ||= ''; $recipient = $recipient . '@bivio.biz' unless $recipient =~ /\@/; $from = email($from) unless $from =~ /\@/; return [req(), { recipient => $recipient, client_addr => '1.2.3.4', message => { name => '', content => \(qq{From: $from$header\n\n}), }, }]; }, check_return => sub { my($case, $actual, $expect) = @_; $case->actual_return([ req()->get('auth_user') && req()->get('auth_user')->get('name'), req()->get('auth_realm')->unsafe_get('owner_name'), $actual->[0]->{task_id}, $case->get('object')->get('recipient'), ]); return [ @$expect[0,1], $expect->[2] || 'MAIL_RECEIVE_IGNORE', $expect->[3] || $case->get('object')->get('recipient'), ]; }, } => [ # [From:, To:] => [auth_user, auth_realm] [qw(demo ignore*demo)] => [qw(demo demo)], ['Bob <' . email('demo') . '>', 'ignore*demo'] => [qw(demo demo)], [qw(not_a_user ignore*demo)] => [undef, 'demo'], [qw(demo ignore*not_a_user)] => MODEL_NOT_FOUND(), [qw(demo demo)] => [qw(demo demo USER_MAIL_RECEIVE)], [qw(demo ignore*demo+antything)] => [qw(demo demo)], # Should not see "unknown facade uri" [qw(demo ignore*demo+antything@petshop.bivio.biz)] => [qw(demo demo)], [qw(demo fourem)] => [qw(demo fourem FORUM_MAIL_RECEIVE)], [qw(demo ignore-fourem)] => [undef, undef, 'ignore_task'], ['demo', email('demo-alias')] => [qw(demo demo USER_MAIL_RECEIVE)], ['demo', email('fourem-alias')] => [qw(demo fourem FORUM_MAIL_RECEIVE)], ['demo', email('random-alias')] => [undef, undef, qw(email_alias_task random@example.com)], [qw(demo any@in.bunit)] => [undef, undef, qw(email_alias_task any@out.bunit)], [qw(demo demo), "\nX-Bivio-Forwarded: 3"] => [qw(demo demo USER_MAIL_RECEIVE)], [qw(demo demo), "\nX-Bivio-Forwarded: 4"] => [undef, undef, 'ignore_task'], [qw(demo demo), "\nX-Spam-Flag: N"] => [qw(demo demo USER_MAIL_RECEIVE)], [qw(demo demo), "\nX-Spam-Flag: Y"] => [undef, undef, 'ignore_task'], ], { method => 'parse_recipient', compute_params => sub { req()->set_user(undef); shift->get('object')->internal_put_field(recipient => shift->[0]), return [1]; }, } => [ 'a*b+c@d.d' => [qw(b a c d.d)], 'a@b.b' => ['a', undef, undef, 'b.b'], ], { method => 'parse_recipient', compute_params => sub { req()->set_user(undef); shift->get('object')->internal_put_field(recipient => shift->[0]), return [0]; }, } => [ 'b*a+c@d.d' => [qw(a b c d.d)], 'a@b.b' => ['a', undef, undef, 'b.b'], 'a*b-c@d.d' => [qw(b-c a), undef, 'd.d'], ], ], ];