Ignore:
Timestamp:
09/20/12 10:37:15 (12 years ago)
Author:
nanardon
Message:

add attachment support in mail

Location:
trunk/LATMOS-Accounts-Web
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm

    r1135 r1158  
    8686} 
    8787 
     88sub attachments :Local { 
     89    my ( $self, $c ) = @_; 
     90    foreach ($c->req->param('rm_attachment')) { 
     91        $c->session->{mailing}{attachments}[$_ -1] = undef; 
     92    } 
     93 
     94    $c->session->{mailing}{attachments} = [ 
     95        grep { $_ } 
     96        @{ 
     97        $c->session->{mailing}{attachments} || []} 
     98    ]; 
     99} 
     100 
    88101sub end : Private { 
    89102    my ( $self, $c ) = @_; 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm

    r1148 r1158  
    4747        $c->go('send'); 
    4848    } 
     49 
     50    if ($c->req->upload('attachment')) { 
     51        $c->forward('attachment'); 
     52    } 
    4953} 
    5054 
     
    5256    my ( $self, $c ) = @_; 
    5357} 
     58 
     59sub attachment :Private { 
     60    my ( $self, $c ) = @_; 
     61    my $upload = $c->req->upload('attachment'); 
     62    my $attach = Email::MIME->create( 
     63        attributes => { 
     64            content_type => $upload->type, 
     65            filename     => $upload->filename, 
     66            encoding     => 'base64', 
     67            name         => $upload->filename,, 
     68        }, 
     69        body => $upload->slurp, 
     70    ); 
     71    push(@{$c->session->{mailing}{attachments}}, $attach); 
     72}  
    5473 
    5574sub filter :Local { 
     
    96115            charset      => 'utf-8', 
    97116        }, 
    98         parts      => [ $bodypart ], 
     117        parts      => [ $bodypart, @{$c->session->{mailing}{attachments}} ], 
    99118    ); 
    100119    $email->header_set( Subject => $c->req->param('subject') ); 
     
    118137    $c->session->{mailing}{subject} = ''; 
    119138    $c->session->{mailing}{body} = ''; 
     139    $c->session->{mailing}{attachments} = []; 
    120140    $c->session->{to} = {}; 
    121141 
    122142} 
     143 
    123144 
    124145=head1 AUTHOR 
  • trunk/LATMOS-Accounts-Web/root/html/services/mailing/index.tt

    r1136 r1158  
    1515 
    1616</form> 
     17 
     18<div id="attachment_list"> 
     19[% INCLUDE 'ajax/services/mailing/attachments.tt' %] 
     20</div> 
     21<form action="[% c.uri_for('/services', 'mailing') %]" 
     22    enctype="multipart/form-data" method="POST"> 
     23<input type=file name="attachment"> 
     24<input type="submit" value="Ajouter"> 
     25</form> 
Note: See TracChangeset for help on using the changeset viewer.