root/websites/mobilecat/trunk/lib/MobileCat/Controller/API/Mail/Post.pm

Revision 17116, 1.2 kB (checked in by tomi-ru, 18 months ago)

エントリの削除機能追加。Catalyst::Controller::Resourcesを使う

Line 
1package MobileCat::Controller::API::Mail::Post;
2use strict;
3use warnings;
4use base 'Catalyst::Controller';
5
6use Email::MIME;
7use Email::MIME::XPath;
8use Encode::JP::Mobile;
9
10sub index :Private {
11    my ($self, $c) = @_;
12    my ($action, $secret) = split /\W/, $c->req->param('rcpt') || "";
13   
14    my $user = $c->model('Users')->single({
15        username  => { '!=', undef },
16        email     => $c->req->params->{sender},
17        secret    => $secret,
18    });
19   
20    return unless $user;
21   
22    my $email = Email::MIME->new($c->req->param('source'));
23    my ($part) = $email->xpath_findnodes('//plain');
24   
25    return unless $part;
26   
27    my $carrier = Email::Address::JP::Mobile->new($c->req->param('from'));
28   
29    my $text = do {
30        my $carrier = $carrier->name eq 'EZweb' ? 'ezweb-auto' : $carrier->name;
31        my $charset = $part->{ct}{attributes}{charset};
32        my $encoding = Encode::find_encoding("x-$charset-$carrier");
33        if ($encoding) {
34            $encoding->decode($part->body);
35        } else {
36            Encode::decode('iso-2022-jp', $part->body);
37        }
38    };
39
40    $c->user($user);
41    $c->req->param(filter => 1);
42    $c->req->param(body   => $text);
43    $c->forward('/entry/create');
44}
45
461;
Note: See TracBrowser for help on using the browser.