# Copyright (c) 2006 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: RealmMail.bunit,v 1.6 2011/01/28 19:49:06 nagler Exp $ Request('initialize_fully'); set_realm_and_user(qw(fourem-sub1 root)); model('Bulletin')->delete_all; model('RealmMail')->delete_all; my($domain) = 'Util.RealmMail.bunit'; my($data) = [ ['2008-05-12', 'plain subject', 'text/plain', 'plain body'], ['2007-06-15', 'html subject', 'text/html', <<'EOF'],
html body
EOF ['2007-03-23', 'attached subject', 'text/plain', 'attached body', { name => 'attach-item-1.txt', content => 'attachment item 1 body', }], ]; my($_IOF) = b_use('IO.File'); my($_FP) = b_use('Type.FilePath'); my($_LFT) = b_use('UI.LocalFileType'); my($_UIF) = b_use('Bivio::UI::Facade')->get_instance; foreach my $item (@$data) { my($date, $subject, $type, $body, @files) = @$item; my($bulletin) = model('Bulletin')->create({ date_time => Date($date), body => $body, body_content_type => $type, subject => $subject, }); next unless @files; foreach my $file (@files) { my($fullname) = $_UIF->get_local_file_name($_LFT->REALM_DATA, $_FP->join('bulletin', $bulletin->get('bulletin_id'), $file->{name})); $_IOF->mkdir_parent_only($fullname, 02770); $_IOF->write($fullname, \($file->{content})); } } [ { object => class(), compute_return => sub { return model(MailThreadRootList => {})->map_rows(sub { my($msg) = @_; return [ $msg->get(qw(RealmMail.subject RealmFile.modified_date_time)), $msg->get_mail_part_list->map_rows(sub { return shift->get_header('Content-Disposition') || (); }), ]; }); }, } => [ import_bulletins => [ [] => [ ['plain subject', Date('2008-05-12'), []], ['html subject', Date('2007-06-15'), []], ['attached subject', Date('2007-03-23'), [ 'inline', qr{attach-item-1.txt}, ]], ], ], ], inline_case(sub { model('RealmMail')->delete_all; model('Bulletin')->delete_all; }), { object => class(), compute_return => sub { return [scalar(@{ model('RealmMail')->map_iterate( sub { shift->get('message_id') =~ /$domain/ ? 1 : (); }, 'message_id', ), })]; }, } => [ delete_message_id => [ [map($_ . '@' . $domain, 'a' .. 'g')] => 0, ], import_rfc822 => [ RealmMail => 7, ], ], ];