File Coverage

blib/lib/Config/Apple/Profile/Payload/Email.pm
Criterion Covered Total %
statement 48 49 97.9
branch 21 22 95.4
condition 11 12 91.6
subroutine 11 11 100.0
pod 1 1 100.0
total 92 95 96.8


line stmt bran cond sub pod time code
1             # This is the code for Config::Apple::Profile::Payload::Email.
2             # For Copyright, please see the bottom of the file.
3              
4             package Config::Apple::Profile::Payload::Email;
5              
6 2     2   54449 use 5.14.4;
  2         8  
  2         87  
7 2     2   11 use strict;
  2         5  
  2         70  
8 2     2   11 use warnings FATAL => 'all';
  2         4  
  2         90  
9 2     2   11 use base qw(Config::Apple::Profile::Payload::Common);
  2         6  
  2         772  
10              
11             our $VERSION = '0.55';
12              
13 2     2   2271 use Email::Valid;
  2         295938  
  2         86  
14 2     2   27 use Readonly;
  2         6  
  2         148  
15 2     2   14 use Regexp::Common;
  2         5  
  2         29  
16 2     2   1548 use Config::Apple::Profile::Targets qw(:all);
  2         7  
  2         324  
17 2     2   14 use Config::Apple::Profile::Payload::Common;
  2         5  
  2         54  
18 2     2   14 use Config::Apple::Profile::Payload::Types qw(:all);
  2         4  
  2         2778  
19              
20              
21             =encoding utf8
22              
23             =head1 NAME
24              
25             Config::Apple::Profile::Payload::Email - The Email payload type.
26              
27             =head1 SYNOPSIS
28              
29             use Config::Apple::Profile;
30             use Config::Apple::Profile::Payload::Email;
31            
32             my $email = new Config::Apple::Profile::Payload::Email;
33             my $payload = $email->payload;
34            
35             $payload->{EmailAccountDescription} = 'Example Email';
36             $payload->{EmailAccountName} = 'Simon Blarfingar';
37             $payload->{EmailAddress} = 'user@example.com';
38             $payload->{EmailAccountType} = 'EmailTypeIMAP';
39            
40             $payload->{IncomingMailServerHostName} = 'mail.example.com';
41             $payload->{OutgoingMailServerHostName} = $payload->{IncomingMailServerHostName};
42            
43             $payload->{IncomingMailServerAuthentication} = 'EmailAuthPassword';
44             $payload->{OutgoingMailServerAuthentication} = $payload->{IncomingMailServerAuthentication};
45            
46             $payload->{IncomingMailServerUsername} = $payload->{EmailAddress};
47             $payload->{OutgoingMailServerUsername} = $payload->{IncomingMailServerUsername};
48            
49             $payload->{OutgoingPasswordSameAsIncomingPassword} = 1;
50             $payload->{SMIMEEnabled} = 1;
51              
52             my $profile = new Config::Apple::Profile::Profile;
53             push @{$profile->content}, $email;
54            
55             print $profile->export;
56              
57             =head1 DESCRIPTION
58              
59             This class implements the Email payload, which is used to configure POP
60             and IMAP accounts. For Exchange accounts, refer to
61             L or
62             L.
63              
64             Each email account has basic information, information about how to fetch mail,
65             information about how to send mail, S/MIME configuration, and interaction.
66              
67             For fetching mail, either POP or IMAP can be used. Authentication is with
68             a password, or it can be turned off. SMTP is used for sending mail, either
69             with or without a username and password. SSL is supported for both sending
70             and receiving, and is enabled by default.
71              
72             B If the server(s) are only accessible on an internal network, you may
73             want to include a VPN payload as part of the profile, so that the user will
74             be able to access the server(s) while not on the internal Wi-Fi network.
75              
76             Passwords can be included in the payload, but then the payload should be
77             encrypted, or delivered in some secure manner. If passwords are not specified,
78             the user will be prompted to enter the password when the profile is installed.
79              
80             S/MIME can be configured for email signing and decryption. For S/MIME to work,
81             a .p12 file (a private key and certificate in a PKCS#12 container, also known
82             as an "identity certificate") must be on the device. The identity certificate
83             can be loaded using L,
84             and may be part of the same profile, or a different profile. If S/MIME is
85             enabled but no signing or decrypting certificates are specified in the payload,
86             the user will be able to choose which identity certificate to use.
87              
88             =head1 INSTANCE METHODS
89              
90             The following instance methods are provided, or overridden, by this class.
91              
92             =head2 validate_key($key, $value)
93              
94             Performs additional validation for certain payload keys in this class:
95              
96             =over 4
97              
98             =item * C
99              
100             This must be a properly-formed email address.
101              
102             =item * C
103              
104             This must be the string C or C.
105              
106             =item * C and C
107              
108             These must be properly-formed hostnames or IP addresses (IPv4 or IPv6).
109              
110             =item * C and C
111              
112             These must be positive numbers less than 65535.
113              
114             =item * C and
115             C
116              
117             These must be the string C or C.
118              
119             All other payload keys will be checked as usual by the parent class.
120              
121             =back
122              
123             See also the documentation in L.
124              
125             =cut
126              
127             sub validate_key {
128 140     140 1 263 my ($self, $key, $value) = @_;
129            
130             # Let's check over some of our keys
131             # Email addresses must match RFC822
132 140 100 100     1136 if ($key eq 'EmailAddress') {
    100 100        
    100 66        
    100          
    50          
133             ## no critic (ProhibitExplicitReturnUndef)
134 8 100       26 return undef if !defined($value);
135             ## use critic
136            
137 7         35 $value = Email::Valid->address($value);
138 7         3787 return $value;
139             }
140            
141             # Email accounts must be POP or IMAP
142             elsif ($key eq 'EmailAccountType') {
143 4 100       23 if ($value =~ m/^(EmailTypePOP|EmailTypeIMAP)$/s) {
144 2         11 return $1;
145             }
146             ## no critic (ProhibitExplicitReturnUndef)
147 2         8 return undef;
148             ## use critic
149             }
150            
151             # Hostnames must be hostnames, or IP addresses
152             elsif ( ($key eq 'IncomingMailServerHostName')
153             || ($key eq 'OutgoingMailServerHostName')
154             ) {
155 106 100       551 if ($value =~ m/^( $RE{net}{domain}{-nospace}
156             |$RE{net}{IPv4}
157             |$RE{net}{IPv6}
158             )$
159             /isx) {
160 32         14348 return $1;
161             }
162             ## no critic (ProhibitExplicitReturnUndef)
163 74         37507 return undef;
164             ## use critic
165             }
166            
167             # Port numbers must be port numbers
168             elsif ( ($key eq 'IncomingMailServerPortNumber')
169             || ($key eq 'OutgoingMailServerPortNumber')
170             ) {
171 14 100       83 if ($value =~ m/^(\d+)$/s) {
172 8         21 my $number = $1;
173 8 100 100     54 return $number if ($number > 0) && ($number < 65535);
174             }
175             ## no critic (ProhibitExplicitReturnUndef)
176 8         26 return undef;
177             ## use critic
178             }
179            
180             # Authentication must be by password or not at all
181             elsif ( ($key eq 'IncomingMailServerAuthentication')
182             || ($key eq 'OutgoingMailServerAuthentication')
183             ) {
184 8 100       34 if ($value =~ m/^(EmailAuthPassword|EmailAuthNone)$/s) {
185 4         19 return $1;
186             }
187             ## no critic (ProhibitExplicitReturnUndef)
188 4         16 return undef;
189             ## use critic
190             }
191            
192             # At this point, we've checked all of our special keys. Over to the parent!
193 0           return $self->SUPER::validate_key($key, $value);
194             }
195              
196              
197             =head1 PAYLOAD KEYS
198              
199             All of the payload keys defined in L
200             are used by this payload.
201              
202             This payload has the following additional keys:
203              
204             =head2 Basic account information
205              
206             =head3 C
207              
208             I
209              
210             A string. This is the account description shown in the Mail and Settings apps.
211              
212             =head3 C
213              
214             I
215              
216             The sender's name, shown in outgoing email addresses.
217              
218             =head3 C
219              
220             I
221              
222             The sender's full email address. If not provided, the user will be asked for
223             it during installation.
224              
225             =head2 Fetching mail
226              
227             =head3 C
228              
229             The type of email account. This is a string, either C or
230             C.
231              
232             =head3 CI
233              
234             The host name or IP address used for fetching mail.
235              
236             =head3 C
237              
238             I
239              
240             The port number used for fetching mail. If not specified, the default port
241             will be used.
242              
243             =head3 C
244              
245             I
246              
247             A Boolean, which defaults to true. If true, use SSL when fetching mail.
248              
249             =head3 C
250              
251             The authentication method for fetching mail. Allowed strings are
252             C and C.
253              
254             =head3 C
255              
256             I
257              
258             The username to use when fetching mail. If a string is not provided, but
259             authentication is used, the user will be asked for it during installation.
260              
261             =head3 C
262              
263             I
264              
265             The password to use when fetching mail. If a string is not provided, but
266             authentication is used, the user may be asked for it during installation.
267              
268             B This is private information. If this payload key is set, then the
269             profile should be delivered to the user in a secure way.
270              
271             =head2 Sending Mail
272              
273             =head3 C
274              
275             The host name or IP address used for sending mail.
276              
277             =head3 C
278              
279             I
280              
281             The port number used for sending mail. If not specified, ports 25, 587, and
282             465, in that order, will be tried.
283              
284             =head3 C
285              
286             I
287              
288             A Boolean, which defaults to true. If true, use SSL when fetching mail.
289              
290             =head3 C
291              
292             The authentication method for sending mail. Allowed strings are
293             C and C.
294              
295             =head3 C
296              
297             I
298              
299             The username to use when sending mail. If a string is not provided, but
300             authentication is used, the user will be asked for it during installation.
301              
302             =head3 C
303              
304             I
305              
306             The password to use when sending mail. If a string is not provided, but
307             authentication is used, the user may be asked for it during installation.
308              
309             B This is private information. If this payload key is set, then the
310             profile should be delivered to the user in a secure way.
311              
312             =head3 C
313              
314             I
315              
316             A Boolean, defaults to false. If no passwords have been set in the profile,
317             but passwords are in use, and this key is true, then the user will be asked
318             for a password once, and that one password will be used for fetching and
319             sending mail.
320              
321             =head2 S/MIME
322              
323             =head3 C
324              
325             I
326              
327             A Boolean. If true, this account supports S/MIME. Defaults to false.
328              
329             =head3 C
330              
331             I
332              
333             The UUID of the PKCS12 Certificate payload used to sign emails.
334              
335             =head3 C
336              
337             I
338              
339             The UUID of the PKCS12 Certificate payload used to decrypt emails.
340              
341             =head2 Application Interaction
342              
343             =head3 C
344              
345             I
346              
347             A Boolean. If true, messages may not be moved to other email accounts, and
348             forwarding/replying from other accounts is prohibited. Defaults to false.
349              
350             This payload key only applies to iOS 5.0 and later.
351              
352             =head3 C
353              
354             I
355              
356             A Boolean. If true, 3rd-party applications may not use this account to send
357             mail. Defaults to false.
358              
359             This payload key only applies to iOS 5.0 and later.
360              
361             =head3 C
362              
363             I
364              
365             A Boolean. If true, this account is excluded from syncing recently-used
366             addresses. Defaults to false.
367              
368             This payload key only applies to iOS 6.0 and later.
369              
370             =head2 C
371              
372             This is fixed to the string C.
373              
374             =head2 C
375              
376             This is fixed to the value C<1>.
377              
378             =cut
379              
380             Readonly our %payloadKeys => (
381             # Bring in the common keys...
382             %Config::Apple::Profile::Payload::Common::payloadKeys,
383            
384             # ... and define our own!
385             # Start with information about the user
386             'EmailAccountDescription' => {
387             type => $ProfileString,
388             description => 'Description shown in the Mail and Settings apps.',
389             optional => 1,
390             targets => {
391             $TargetIOS => '5.0',
392             $TargetMACOSX => '10.7',
393             },
394             },
395             'EmailAccountName' => {
396             type => $ProfileString,
397             description => "The sender's name, used in outgoing messages.",
398             optional => 1,
399             targets => {
400             $TargetIOS => '5.0',
401             $TargetMACOSX => '10.7',
402             },
403             },
404             'EmailAddress' => {
405             type => $ProfileString,
406             description => "The sender's full email address. If not provided, the"
407             . 'user will be asked for it during installation.',
408             optional => 1,
409             targets => {
410             $TargetIOS => '5.0',
411             $TargetMACOSX => '10.7',
412             },
413             },
414            
415             # Information on how to fetch mail
416             'EmailAccountType' => {
417             type => $ProfileString,
418             description => 'Either EmailTypePOP or EmailTypeIMAP.',
419             targets => {
420             $TargetIOS => '5.0',
421             $TargetMACOSX => '10.7',
422             },
423             },
424             'IncomingMailServerHostName' => {
425             type => $ProfileString,
426             description => 'The host name or IP for fetching mail.',
427             targets => {
428             $TargetIOS => '5.0',
429             $TargetMACOSX => '10.7',
430             },
431             },
432             'IncomingMailServerPortNumber' => {
433             type => $ProfileNumber,
434             description => 'The port number used for fetching mail.',
435             optional => 1,
436             targets => {
437             $TargetIOS => '5.0',
438             $TargetMACOSX => '10.7',
439             },
440             },
441             'IncomingMailserverUseSSL' => {
442             type => $ProfileBool,
443             description => 'If true, use SSL to fetch mail. Defaults to true.',
444             targets => {
445             $TargetIOS => '5.0',
446             $TargetMACOSX => '10.7',
447             },
448             },
449             'IncomingMailServerAuthentication' => {
450             type => $ProfileString,
451             description => 'The authentication method for fetching mail. Allowed '
452             . 'values are EmailAuthPassword and EmailAuthNone.',
453             targets => {
454             $TargetIOS => '5.0',
455             $TargetMACOSX => '10.7',
456             },
457             },
458             'IncomingMailServerUsername' => {
459             type => $ProfileString,
460             description => 'The username to use when fetching mail. If not '
461             . 'provided, the user may be asked for it during '
462             . 'installation.',
463             optional => 1,
464             targets => {
465             $TargetIOS => '5.0',
466             $TargetMACOSX => '10.7',
467             },
468             },
469             'IncomingPassword' => {
470             type => $ProfileString,
471             description => 'The password to use when fetching mail. If not '
472             . 'provided, the user may be asked for it during '
473             . 'installation.',
474             optional => 1,
475             private => 1,
476             targets => {
477             $TargetIOS => '5.0',
478             $TargetMACOSX => '10.7',
479             },
480             },
481            
482             # Information on how to send mail
483             'OutgoingMailServerHostName' => {
484             type => $ProfileString,
485             description => 'The host name or IP for sending mail.',
486             targets => {
487             $TargetIOS => '5.0',
488             $TargetMACOSX => '10.7',
489             },
490             },
491             'OutgoingMailServerPortNumber' => {
492             type => $ProfileNumber,
493             description => 'The port number used for sending mail. If not '
494             . 'specified, ports 25, 587, and 465 are checked.',
495             targets => {
496             $TargetIOS => '5.0',
497             $TargetMACOSX => '10.7',
498             },
499             optional => 1,
500             },
501             'OutgoingMailserverUseSSL' => {
502             type => $ProfileBool,
503             description => 'If true, use SSL to send mail. Defaults to true.',
504             targets => {
505             $TargetIOS => '5.0',
506             $TargetMACOSX => '10.7',
507             },
508             },
509             'OutgoingMailServerAuthentication' => {
510             type => $ProfileString,
511             description => 'The authentication method for sending mail. Allowed '
512             . 'values are EmailAuthPassword and EmailAuthNone.',
513             targets => {
514             $TargetIOS => '5.0',
515             $TargetMACOSX => '10.7',
516             },
517             },
518             'OutgoingMailServerUsername' => {
519             type => $ProfileString,
520             description => 'The username to use when sending mail. If not '
521             . 'provided, the user may be asked for it during '
522             . 'installation.',
523             optional => 1,
524             targets => {
525             $TargetIOS => '5.0',
526             $TargetMACOSX => '10.7',
527             },
528             },
529             'OutgoingPassword' => {
530             type => $ProfileString,
531             description => 'The password to use when sending mail. If not '
532             . 'provided, the user may be asked for it during '
533             . 'installation.',
534             optional => 1,
535             private => 1,
536             targets => {
537             $TargetIOS => '5.0',
538             $TargetMACOSX => '10.7',
539             },
540             },
541             'OutgoingPasswordSameAsIncomingPassword' => {
542             type => $ProfileBool,
543             description => 'If true, the user will be prompted for a password only '
544             . 'once, and it will be used for sending and '
545             . 'receiving mail.',
546             optional => 1,
547             targets => {
548             $TargetIOS => '5.0',
549             $TargetMACOSX => '10.7',
550             },
551             },
552            
553             # S/MIME
554             'SMIMEEnabled' => {
555             type => $ProfileBool,
556             description => 'If true, this account supports S/MIME. Default false.',
557             optional => 1,
558             targets => {
559             $TargetIOS => '5.0',
560             },
561             },
562             'SMIMESigningCertificateUUID' => {
563             type => $ProfileUUID,
564             description => 'The UUID of the PKCS12 payload used to sign emails.',
565             optional => 1,
566             targets => {
567             $TargetIOS => '5.0',
568             },
569             },
570             'SMIMEEncryptionCertificateUUID' => {
571             type => $ProfileUUID,
572             description => 'The UUID of the PKCS12 payload used to decrypt emails.',
573             optional => 1,
574             targets => {
575             $TargetIOS => '5.0',
576             },
577             },
578            
579             # Application interaction
580             'PreventMove' => {
581             type => $ProfileBool,
582             description => 'If true, messages may not be moved to other email '
583             . 'accounts, and forwarding/replying from other '
584             . 'accounts is prohibited. Defaults to false.',
585             optional => 1,
586             targets => {
587             $TargetIOS => '5.0',
588             },
589             },
590             'PreventAppSheet' => {
591             type => $ProfileBool,
592             description => 'If true, 3rd-party applications may not use this '
593             . 'account to send mail. Defaults to false.',
594             optional => 1,
595             targets => {
596             $TargetIOS => '5.0',
597             },
598             },
599             'disableMailRecentsSyncing' => {
600             type => $ProfileBool,
601             description => 'If true, this account is excluded from syncing '
602             . 'recently-used addresses. Defaults to false.',
603             optional => 1,
604             targets => {
605             $TargetIOS => '6.0',
606             },
607             },
608            
609             # Finish with basic payload information
610             'PayloadType' => {
611             type => $ProfileString,
612             value => 'com.apple.mail.managed',
613             targets => {
614             $TargetIOS => '5.0',
615             $TargetMACOSX => '10.7',
616             },
617             },
618             'PayloadVersion' => {
619             type => $ProfileNumber,
620             value => 1,
621             targets => {
622             $TargetIOS => '5.0',
623             $TargetMACOSX => '10.7',
624             },
625             },
626             ); # End of %payloadKeys
627              
628              
629             =head1 ACKNOWLEDGEMENTS
630              
631             Refer to L for acknowledgements.
632              
633             =head1 AUTHOR
634              
635             A. Karl Kornel, C<< >>
636              
637             =head1 COPYRIGHT AND LICENSE
638              
639             Copyright © 2014 A. Karl Kornel.
640              
641             This program is free software; you can redistribute it and/or modify it
642             under the terms of either: the GNU General Public License as published
643             by the Free Software Foundation; or the Artistic License.
644              
645             See L for more information.
646              
647             =cut
648              
649             1;