# Copyright (c) 2009 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: CRMThread3.bunit,v 1.7 2010/03/16 22:29:18 nagler Exp $ Request('initialize_fully'); options({ class_name => 'Model.RealmMail', comparator => 'nested_contains', }); req()->set_realm('crm_forum'); my($next_num) = model('CRMThread')->internal_next_ord; my($first_num) = $next_num; my($first_tid); my($second_num) = $first_num + 1; my($id) = 1; my($msg_id); my($msg) = <<'EOF'; To: a@a.a From: b@b.b Subject: $subject Message-Id: $message_id $extra_headers body EOF [ [req()] => [ { method => 'create_from_rfc822', compute_params => sub { my(undef, $params) = @_; req()->delete_all_by_regexp(qr{CRMThread|RealmMail}); $id++; return [template(\(my $x = $msg), { subject => $params->[0], message_id => "", extra_headers => $params->[1] ? $params->[1]->() : '', })]; }, compute_return => sub {[ req(), ${model(RealmFile => { realm_file_id => req(qw(Model.RealmMail realm_file_id)), })->get_content}, ]}, } => [ problem => [{ 'Model.CRMThread' => { crm_thread_num => $first_num, }, 'Model.RealmMail' => { realm_file_id => sub {$first_tid = shift}, message_id => sub {$msg_id = shift}, }, }, qr{Subject: .*#$first_num\] problem.*}s], ['problem2', sub { "In-Reply-To: <$msg_id>\n"; }] => [{ 'Model.RealmMail' => { subject => qr{#$second_num\] problem2}, thread_parent_id => undef, thread_root_id => sub { req(qw(Model.RealmMail realm_file_id)); }, }, 'Model.CRMThread' => { crm_thread_num => $second_num, }, }, qr{Subject: .*#$second_num\] problem2}s], ['problem', sub { "In-Reply-To: <$msg_id>\n"; }] => [{ 'Model.RealmMail' => { subject => qr{#$first_num\] problem}, thread_parent_id => sub {$first_tid}, thread_root_id => sub {$first_tid}, }, 'Model.CRMThread' => { crm_thread_num => $first_num, }, }, qr{Subject: .*#$first_num\] problem}], ['Re: problem', sub { "In-Reply-To: <$msg_id>\n"; }] => [{ 'Model.RealmMail' => { subject => qr{#$first_num\] Re: problem}, thread_parent_id => sub {$first_tid}, thread_root_id => sub {$first_tid}, }, 'Model.CRMThread' => { crm_thread_num => $first_num, }, }, qr{Subject: .*#$first_num\]}s], map(([$_, sub { "In-Reply-To: <$msg_id>\n"; }] => [{ 'Model.CRMThread' => { crm_thread_num => $first_num, subject => $_ =~ /(\w+)$/, }, }, qr{Subject: \[[^]]+ #$first_num\]}]), 'Re: problem', 'Re problem', 'Aw: problem', 'Aw problem', 'Fwd: problem', 'Fwd problem', 'Fw: problem', 'Fw problem', '[fwd] problem', 'Fwd: RE: re: fw problem', ), ], ], ];