Webqq/Plugin/PostQRcode.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 59 CC 9 SCAR 39.0
CC
9
Cov
0%
call
72.0
BEGIN
6.0
BEGIN
2.0
CRAP 49.3
1 package Mojo::Webqq::Plugin::PostQRcode;
2 our $PRIORITY = 0;
3 our $CALL_ON_LOAD = 1;
4 use MIME::Base64;
5 BEGIN{
6 our $has_mime_lite = 0;
7 eval{require MIME::Lite;};
8 $has_mime_lite = 1 if not $@;
9 }
10 sub call{
11 my $client = shift;
12 my $data = shift;
13 $client->die("插件[". __PACKAGE__ ."]依赖模块 MIME::Lite,请先确认该模块已经正确安装") if not $has_mime_lite;
14 $data->{max} = 10 if not defined $data->{max};
15 #$data->{charset} = "UTF-8" if not defined $data->{charset};
16 my $count = 0;
17 $client->on(login=>sub{$count = 0});
18 $client->on(input_qrcode=>sub{
19 my($client,$filename) = @_;
20 if($count > $data->{max}){
21 $client->fatal("等待扫描二维码超时");
22 $client->stop();
23 return
24 }
25 $data->{subject} = "QQ帐号" . (defined $client->uid?$client->uid:$client->account) . "扫描二维码" if not defined $data->{subject};
26 my $mime = MIME::Lite->new(
27 Type => 'multipart/mixed',
28 From => $data->{from},
29 To => $data->{to},
30 );
31 $mime->add("Subject"=>"=?UTF-8?B?" . MIME::Base64::encode_base64($data->{subject},"") . "?=");
32 $mime->attach(
33 Type =>"text/plain; charset=UTF-8",
34 Data =>"请使用手机QQ扫描附件中的二维码",
35 );
36 $mime->attach(
37 Path => $filename,
38 Disposition => 'attachment',
39 Type => 'image/png',
40 );
41 $data->{data} = $mime->as_string;
42 my($is_success,$err) = $client->mail(%$data);
43 if(not $is_success){
44 if($data->{smtp} eq 'smtp.qq.com'){
45 $client->error("插件[".__PACKAGE__."]邮件发送失败: " . $client->encode("utf8",$client->decode("gbk",$err)));
46 }
47 else{
48 $client->error("插件[".__PACKAGE__."]邮件发送失败: $err");
49 }
50 }
51 else{
52 $client->info("登录二维码已经发送到邮箱: $data->{to}");
53 }
54 $count++;
55 });
56 }
57 1;