MIME-Lite-3.038000755000765000024 015144704407 12403 5ustar00rjbsstaff000000000000README100644000765000024 57615144704407 13334 0ustar00rjbsstaff000000000000MIME-Lite-3.038This archive contains the distribution MIME-Lite, version 3.038: low-calorie MIME generator This software is copyright (c) 1997 by Eryq, ZeeGee Software, and Yves Orton. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.037. Changes100644000765000024 2412315144704407 14001 0ustar00rjbsstaff000000000000MIME-Lite-3.038Revision history for MIME-Lite 3.038 2026-02-16 16:15:46-05:00 America/New_York - fix metdata/doc errors introduced during conversion to Dist::Zilla 3.037 2026-02-10 20:56:44-05:00 America/New_York - tweak prereq generation to install on ancient perls (5.12, 5.16) 3.036 2026-02-09 09:46:19-05:00 America/New_York (TRIAL RELEASE) - converted to Dist::Zilla 3.035 (unknown) - No changes since previous version, just made non-trial. 3.034 (unknown) (TRIAL RELEASE) - Add in-reply-to to known field list. - Remove Date header when setting top_level off. - Do not quote rfc2331-encoded parameters. - Automatically fold headers, if needed. 3.033 (unknown) - No changes since previous version, just made non-trial. 3.032 (unknown) - Fix an error in printing to Net::SMTP (thanks, Peter Heirich) - Add "use warnings" and require v5.6 3.031 (unknown) - Add an SSL option to connect to the SMTP relay via SSL on port 465. (thanks, Max Maischein) - Document some tips on using non-ASCII content with MIME::Lite (thanks, traveljury.com and Tom Hukins) 3.030 (unknown) - Make send_by_sendmail set sender like documentation says it does (thanks, Michael Schout!) 3.029 (unknown) - Allow the MIME-Version header to be replaced (thanks, Florian!) 3.028 (unknown) - Various documentation fixes 3.027 (unknown) - Add send_to_testfile method (Thanks, AlexanderBecker) 3.026 (unknown) - Fix tests to pass with MIME::Types 1.28 3.025 (unknown) - Added back support for providing a non-default SMTP port (#21156, #48783, thanks John Bokma!). 3.024 (unknown) - add git repo link to metadata 3.023 (unknown) - Correct erroneous changelog entry - Fix typo in perldoc: utf-8, not utf8 3.022 (unknown) - Behave on Cygwin as on Win32 with regard to defaulting to SMTP sending. - Respect crazy people who put multiple Cc or Bcc headers in message (#30574, thanks Pavel V. Rochnyack!) - We no longer rewrite array and hash refs in the send_by_sendmail args so aggressively. - Cope with missing local sendmail (thanks to Debian for patching for this) - Fix weird unicode-in-$1 bug (thanks SREZIC!) - Other minor bug fixes. 3.021 (unknown) - Replace Email::Date with Email::Date::Format to limit prereqs (Email::Date::Format produced just for this!) - Begin the process of removing use of ExtUtils::TBone for testing 3.020 (unknown) - Optimized code for speedup of creation of two-part messages. The internal structure of the object has changes, but that won't matter if you were using the published interface. (Sam Tregar) - Removed the "advanced features", ie auto-fallback delivery, from send_by_smtp. They didn't belong there in the first place. 3.01_06 2007-07-29 - First release from Perl Email Project. Updated packaging. 3.01_04 2004-05-05 - Reworked the new send_by_smtp stuff. Documentation modifications. 3.01_02 2003-08-28 - Fixed tests on Win32 due to line ending format change. - Fixed email extraction for SMTP with or without Mail::Address. 3.01_01 2003-04-25 - Test release with various fixes. - Added support for funky names in the from field when sending via SMTP. - Win32 now defaults to using SMTP instead of sendmail. - Fixed SMTP interaction bug with Net::CMD regarding "\n\n" endings. - Content-Id now automatically gets angle brackets. - Fixed sendmail path discovery. - Fixed date stamp formatting. - Fixed quoted-printable handling of weird \r\n combinations. 3.01 2003-04-25 - Eryq has reappeared long enough to graciously hand over the maintenance of the module. Thanks. 3.00 2003-04-24 - Eryq has disappeared; taken over maintenance. - This release has code that actually works with MIME::Lite now, as well as a few other minor additions. 2.117 2001-08-20 - The terms-of-use have been placed in the distribution file "COPYING". Also, small documentation tweaks were made. 2.116 2001-08-17 - Added long-overdue patch which makes the instance method form of send() do the right thing when given HOW... arguments. (thanks, Casey West) 2.114 2001-08-16 - New special 'AUTO' content type in new()/build() tells MIME::Lite to try and guess the type from file extension. - File::Basename is used if it is available. (thanks, Ville Skytta) - SMTP failures now add $smtp->message to the croak'ed exception. (thanks, Thomas R. Wyant III) - Subtle change to as_string for Perl 5.004_04 on NT 4. (thanks, John Gotts) - Added contrib directory, with MailTool.pm. (thanks, Tom Wyant) - Improved HTML documentation. - Corrected some mis-docs. 2.111 2001-04-03 - Added long-overdue parts() and parts_DFS() methods. - Added long-overdue auto-verify logic to print() method. - Added long-overdue preamble() method. (thanks, Jim Daigle) 2.108 2001-03-30 - New field_order() allows you to set the header order, both on a per-message basis, and package-wide. (thanks, Thomas Stromberg) - Added code to try and divine "sendmail" path more intelligently. (thanks, Slaven Rezic) 2.107 2001-03-27 - Fixed serious bug where tainted data with quoted-printable encoding was causing infinite loops. (thanks, Stefan Sautter and Larry Geralds) - Fixed bugs where a non-local $_ was being modified. (thanks, Maarten Koskamp) - Fixed buglet in add() where all value references were being treated as arrayrefs. (thanks, dLux) - Added "Approved" as an acceptable header field for new(), as per RFC1036. (thanks, Thomax) - Small improvements to docs. (thanks, Sven Rassman and Roland Walter) 2.106 2000-11-21 - Added Alpha version of scrub() to make it easy for people to suppress the printing of unwanted MIME attributes. - Headers with empty-strings for their values are no longer printed. 2.105 2000-10-14 - Fixed regression-test failure related to \-quoting in autoloaded code. (thanks, Scott Schwartz) 2.104 2000-09-28 - Now attempts to load and use Mail::Address for parsing email addresses before falling back to our own method. - Added FromSender option to send_by_sendmail(). (thanks, Bill Moseley) 2.101 2000-06-06 - Major revision to print_body() and body_as_string() so that "body" really means "the part after the header". - Added support for attaching a part to a "message/rfc822". - Now takes care not to include "Bcc:" in header when using send_by_smtp. (thanks, Tatsuhiko Miyagawa) - Improved efficiency of many stringifying operations. - Cleaned up the "examples" directory. 1.147 2000-06-02 - Fixed buglet where lack of Cc:/Bcc: was causing extract_addrs to emit "undefined variable" warnings. (thanks, David Mitchell) 1.146 2000-05-18 - Fixed bug in parsing of addresses. - Added automatic inclusion of a UT "Date:" at top level. (thanks, Andy Jacobs) 1.145 2000-05-06 - Fixed bug in encode_7bit(): a lingering /e modifier was removed. (thanks, Michael A. Chase) 1.142 2000-05-02 - Added new, taint-safe invocation of "sendmail", one which also sets up the -f option. (thanks, Jeremy Howard) 1.140 2000-04-27 - Fixed bug in support for "To", "Cc", and "Bcc" in send_by_smtp(): multiple (comma-separated) addresses should now work fine. (thanks, John Mason) - Added automatic verification that attached data files exist. 1.137 2000-03-22 - Added support for "Cc" and "Bcc" in send_by_smtp(). (thanks, Lucas Maneos) - Chooses a better default content-transfer-encoding if the content-type is "image/*", "audio/*", etc. - Fixed bug in QP-encoding where a non-local $_ was being modified. (thanks, Jochen Stenzel) - Removed references to $`, $', and $&. - Added an example of how to send HTML files with enclosed in-line images. 1.133 1999-04-17 - Fixed bug in "Data" handling: arrayrefs were not being handled properly. 1.130 1998-12-14 - Added much larger and more-flexible send() facility. (thanks, Andrew McRae and Optimation New Zealand Ltd) - Added get() method for extracting basic attributes. - New... "t" tests! 1.124 1998-11-13 - Folded in filehandle (FH) support in build/attach. (thanks, Miko O'Sullivan) 1.122 1998-01-19 - MIME::Base64 and MIME::QuotedPrint are used if available. - The 7bit encoding no longer does "escapes"; it merely strips 8-bit characters. 1.121 1997-04-08 - Filename attribute is now no longer ignored by build(). (thanks, Ian Smith) 1.120 1997-03-29 - Efficiency hack to speed up MIME::Lite::IO_Scalar. (thanks, David Aspinwall) 1.116 1997-03-19 - Small bug in our private copy of encode_base64() was patched. (thanks, Andreas Koenig) - New, prettier way of specifying mail message headers in build(). - New quiet method to turn off warnings. - Changed "stringify" methods to more-standard "as_string" methods. 1.112 1997-03-06 - Added read_now(), and binmode() method for non-Unix-using brethren. (thanks, Xiangzhou Wang) 1.110 1997-03-06 - Fixed bug in opening the data filehandle. 1.102 1997-03-01 - Initial release. 1.101 1997-03-01 - Baseline code. Originally created: 11 December 1996. LICENSE100644000765000024 4641415144704407 13522 0ustar00rjbsstaff000000000000MIME-Lite-3.038This software is copyright (c) 1997 by Eryq, ZeeGee Software, and Yves Orton. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 1997 by Eryq, ZeeGee Software, and Yves Orton. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Moe Ghoul, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 1997 by Eryq, ZeeGee Software, and Yves Orton. This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End dist.ini100644000765000024 117315144704407 14132 0ustar00rjbsstaff000000000000MIME-Lite-3.038name = MIME-Lite author = Ricardo SIGNES author = Eryq author = Yves Orton license = Perl_5 copyright_holder = Eryq, ZeeGee Software, and Yves Orton copyright_year = 1997 [@RJBS] perl-window = long-term [Prereqs] Email::Date::Format = 1.000 [RemovePrereqs] ; This will remove the Perl::PrereqScanner-found MIME::Types from the tests, ; then it can be re-added only as RuntimeRecommends (which will cover tests, if ; recommended things are installed). remove = MIME::Types remove = Mail::Address [Prereqs / RuntimeRecommends] MIME::Types = 1.28 Mail::Address = 1.62 t000755000765000024 015144704407 12567 5ustar00rjbsstaff000000000000MIME-Lite-3.038data.t100644000765000024 174115144704407 14030 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More; # Make a tester... here are 3 different alternatives: $MIME::Lite::VANILLA = 1; $MIME::Lite::PARANOID = 1; my ($me, $str); #------------------------------ $me = MIME::Lite->build(Type => 'text/plain', Data => "Hello\nWorld\n"); $str = $me->as_string; ok(($str =~ m{Hello\nWorld\n}), "Data string"); #------------------------------ $me = MIME::Lite->build(Type => 'text/plain', Data => ["Hel", "lo\n", "World\n"]); $str = $me->as_string; ok(($str =~ m{Hello\nWorld\n}), "Data array 1"); #------------------------------ $me = MIME::Lite->build(Type => 'text/plain', Data => ["Hel", "lo", "\n", "", "World", "", "","\n"]); $str = $me->as_string; ok(($str =~ m{Hello\nWorld\n}), "Data array 2"); #------------------------------ $me = MIME::Lite->build(Type => 'text/plain', Path => "./testin/hello"); $str = $me->as_string; ok(($str =~ m{Hello\r?\nWorld\r?\n}), "Data file"); done_testing; head.t100644000765000024 403515144704407 14017 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More; # Make a tester... here are 3 different alternatives: $MIME::Lite::VANILLA = 1; $MIME::Lite::PARANOID = 1; # New: my $from = 'me@myhost.com'; my $me = MIME::Lite->build(From => $from, To => 'you@yourhost.com', Subject => 'Me!', Type => 'text/plain', Data => "Hello!\n"); # Test "get" [4 tests]: is($me->get('From'), $from, "get: simple get of 'From'"); is($me->get('From',0), $from, "get: indexed get(0) of 'From' gets first"); is($me->get('From',-1), $from, "get: indexed get(-1) of 'From' gets first"); is($me->get('FROM',0), $from, "get: indexed get(0) of 'FROM' gets From"); # Test "add": add one, then two [6 tests]: $me->add('Received', 'sined'); $me->add('Received', ['seeled', 'delivered']); is(scalar($me->get('Received')), 'sined', "add: scalar context get of 'Received'"); is($me->get('Received',0), 'sined', "add: scalar context get(0) of 'Received'"); is($me->get('Received',1), 'seeled', "add: scalar context get(1) of 'Received'"); is($me->get('Received',2), 'delivered', "add: scalar context get(2) of 'Received'"); is($me->get('Received',-1), 'delivered', "add: scalar context get(-1) of 'Received'"); is(($me->get('Received'))[1], 'seeled', "add: array context get of 'Received', indexed to 1'th elem"); # Test "delete" [1 test]: $me->delete('RECEIVED'); ok(!defined($me->get('Received')), "delete: deletion of RECEIVED worked"); # Test "replace" [1 test]: $me->replace('subject', "Hellooooo, nurse!"); is($me->get('SUBJECT'), "Hellooooo, nurse!", "replace: replace of SUBJECT worked"); # Test "attr" [2 tests]: $me->attr('content-type.charset', 'US-ASCII'); is($me->attr('content-type.charset'), 'US-ASCII', "attr: replace of charset worked"); # my ($ct) = map {($_->[0] eq 'content-type') ? $_->[1] : ()} @{$me->fields}; is($ct, 'text/plain; charset="US-ASCII"', "attr: replace of charset worked on whole line"); done_testing; META.yml100644000765000024 3301015144704407 13752 0ustar00rjbsstaff000000000000MIME-Lite-3.038--- abstract: 'low-calorie MIME generator' author: - 'Ricardo SIGNES ' - 'Eryq ' - 'Yves Orton' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0.96' configure_requires: ExtUtils::MakeMaker: '6.78' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.037, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MIME-Lite recommends: MIME::Types: '1.28' Mail::Address: '1.62' requires: Carp: '0' Email::Date::Format: '1.000' File::Basename: '0' File::Spec: '0' FileHandle: '0' Net::SMTP: '0' perl: '5.012' strict: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/rjbs/MIME-Lite/issues homepage: https://github.com/rjbs/MIME-Lite repository: https://github.com/rjbs/MIME-Lite.git version: '3.038' x_Dist_Zilla: perl: version: '5.040001' plugins: - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@RJBS/Git::GatherDir' version: '2.052' - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@RJBS/CheckPrereqsIndexed' version: '0.022' - class: Dist::Zilla::Plugin::CheckExtraTests name: '@RJBS/CheckExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 0 check_all_prereqs: 0 modules: - Dist::Zilla::PluginBundle::RJBS phase: build run_under_travis: 0 skip: [] name: '@RJBS/RJBS-Outdated' version: '0.060' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 0 modules: [] phase: release run_under_travis: 0 skip: - Dist::Zilla::Plugin::RJBSMisc name: '@RJBS/CPAN-Outdated' version: '0.060' - class: Dist::Zilla::Plugin::PruneCruft name: '@RJBS/@Filter/PruneCruft' version: '6.037' - class: Dist::Zilla::Plugin::ManifestSkip name: '@RJBS/@Filter/ManifestSkip' version: '6.037' - class: Dist::Zilla::Plugin::MetaYAML name: '@RJBS/@Filter/MetaYAML' version: '6.037' - class: Dist::Zilla::Plugin::License name: '@RJBS/@Filter/License' version: '6.037' - class: Dist::Zilla::Plugin::Readme name: '@RJBS/@Filter/Readme' version: '6.037' - class: Dist::Zilla::Plugin::ExecDir name: '@RJBS/@Filter/ExecDir' version: '6.037' - class: Dist::Zilla::Plugin::ShareDir name: '@RJBS/@Filter/ShareDir' version: '6.037' - class: Dist::Zilla::Plugin::Manifest name: '@RJBS/@Filter/Manifest' version: '6.037' - class: Dist::Zilla::Plugin::TestRelease name: '@RJBS/@Filter/TestRelease' version: '6.037' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@RJBS/@Filter/ConfirmRelease' version: '6.037' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@RJBS/@Filter/UploadToCPAN' version: '6.037' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 9 name: '@RJBS/MakeMaker' version: '6.037' - class: Dist::Zilla::Plugin::AutoPrereqs name: '@RJBS/AutoPrereqs' version: '6.037' - class: Dist::Zilla::Plugin::Git::NextVersion config: Dist::Zilla::Plugin::Git::NextVersion: first_version: '0.001' version_by_branch: 1 version_regexp: (?^:^([0-9]+\.[0-9]+)$) Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/Git::NextVersion' version: '2.052' - class: Dist::Zilla::Plugin::PkgVersion name: '@RJBS/PkgVersion' version: '6.037' - class: Dist::Zilla::Plugin::MetaConfig name: '@RJBS/MetaConfig' version: '6.037' - class: Dist::Zilla::Plugin::MetaJSON name: '@RJBS/MetaJSON' version: '6.037' - class: Dist::Zilla::Plugin::NextRelease name: '@RJBS/NextRelease' version: '6.037' - class: Dist::Zilla::Plugin::Test::ChangesHasContent name: '@RJBS/Test::ChangesHasContent' version: '0.011' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@RJBS/PodSyntaxTests' version: '6.037' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@RJBS/Test::ReportPrereqs' version: '0.029' - class: Dist::Zilla::Plugin::Git::Remote::Check name: '@RJBS/Git::Remote::Check' version: 0.1.2 - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: 1 fail_on_warning: author fake_home: 0 filename: xt/author/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: develop script_finder: - ':PerlExecFiles' skips: [] switch: [] name: '@RJBS/Test::Compile' version: '2.059' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@RJBS/TestMoreWithSubtests' version: '6.037' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugins: - '@RJBS' finder: - ':InstallModules' - ':PerlExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.020' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.020' - class: Pod::Weaver::Plugin::SingleEncoding name: '@RJBS/SingleEncoding' version: '4.020' - class: Pod::Weaver::Section::Name name: '@RJBS/Name' version: '4.020' - class: Pod::Weaver::Section::Version name: '@RJBS/Version' version: '4.020' - class: Pod::Weaver::Section::Region name: '@RJBS/Prelude' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Synopsis' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Description' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Overview' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Stability' version: '4.020' - class: Pod::Weaver::Section::GenerateSection name: '@RJBS/PerlSupport' version: '4.020' - class: Pod::Weaver::Section::Collect name: Attributes version: '4.020' - class: Pod::Weaver::Section::Collect name: Methods version: '4.020' - class: Pod::Weaver::Section::Collect name: Functions version: '4.020' - class: Pod::Weaver::Section::Leftovers name: '@RJBS/Leftovers' version: '4.020' - class: Pod::Weaver::Section::Region name: '@RJBS/postlude' version: '4.020' - class: Pod::Weaver::Section::Authors name: '@RJBS/Authors' version: '4.020' - class: Pod::Weaver::Section::Contributors name: '@RJBS/Contributors' version: '0.009' - class: Pod::Weaver::Section::Legal name: '@RJBS/Legal' version: '4.020' - class: Pod::Weaver::Plugin::Transformer name: '@RJBS/List' version: '4.020' name: '@RJBS/PodWeaver' version: '4.010' - class: Dist::Zilla::Plugin::RJBSMisc name: '@RJBS/RJBSMisc' version: '5.035' - class: Dist::Zilla::Plugin::GithubMeta name: '@RJBS/GithubMeta' version: '0.58' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/@Git/Check' version: '2.052' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%V%n%n%c signoff: 0 Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Commit' version: '2.052' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '3.038' tag_format: '%v' tag_message: v%V Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Tag' version: '2.052' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - 'github :' remotes_must_exist: 0 Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/@Git/Push' version: '2.052' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: '2.50.1 (Apple Git-155)' include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@RJBS/Git::Contributors' version: '0.038' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: '6.037' - class: Dist::Zilla::Plugin::RemovePrereqs config: Dist::Zilla::Plugin::RemovePrereqs: modules_to_remove: - MIME::Types - Mail::Address name: RemovePrereqs version: '6.037' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: recommends name: RuntimeRecommends version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.037' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.037' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: '6.037' x_contributors: - 'Claude ' - 'Damien Krotkine ' - 'David Steinbrunner ' - 'Florian ' - 'Jan Willamowius ' - 'John Bokma ' - 'Karen Etheridge ' - 'Max Maischein ' - 'Michael Schout ' - 'Michael Stevens ' - 'Peder Stray ' - 'Peter Heirich ' - 'Ricardo Signes ' - 'Tom Hukins ' x_generated_by_perl: v5.40.1 x_rjbs_perl_window: long-term x_serialization_backend: 'YAML::Tiny version 1.76' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' MANIFEST100644000765000024 112515144704407 13614 0ustar00rjbsstaff000000000000MIME-Lite-3.038# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.037 Changes LICENSE MANIFEST META.json META.yml Makefile.PL README contrib/MailTool.pm contrib/README dist.ini examples/mime_fwd examples/mime_gif examples/mime_hack examples/mime_longlines examples/mime_postcard examples/nodisp lib/MIME/Lite.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/addrs.t t/data.t t/head.t t/mime-version.t t/parts.t t/sendmail.t t/stupid-params.t t/types.t t/verify.t testin/README testin/hello testin/test.html xt/author/00-compile.t xt/author/pod-syntax.t xt/release/changes_has_content.t addrs.t100644000765000024 250515144704407 14213 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More; $MIME::Lite::VANILLA = 1; $MIME::Lite::PARANOID = 1; # Pairs: my @pairs = ( [' me@myhost.com ', 1, ''], [' mylogin ', 1, ''], [' "Me, Jr." < me@myhost.com > ', 1, ''], [' Me ', 1, ''], ['"Me, Jr." ', 1, ''], ['"Me@somewhere.com, Jr." ', 1, ''], ['me@myhost.com,you@yourhost.com', 2, ' '], ['"Me" , "You"', 2, ' '], ['"Me" , you@yourhost.com, "And also" ', 3, ' '], ['"Me" , mylogin ,yourlogin , She ', 4, ' '] ); plan tests => 2 * @pairs; # New: foreach my $pair (@pairs) { my ($to, $count, $result) = @$pair; my @addrs = MIME::Lite::extract_only_addrs($to); is(@addrs, $count, "as many addrs as expected"); is( join(' ', map {"<$_>"} @addrs), $result, "addrs stringify together as expected", ); } parts.t100644000765000024 111615144704407 14244 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More; # Make a tester... here are 3 different alternatives: $MIME::Lite::VANILLA = 1; $MIME::Lite::PARANOID = 1; my $msg; $msg = MIME::Lite->new(From=>"me", To=>"you", Data=>"original text"); $msg->attach(Data => "attachment 1"); $msg->attach(Data => "attachment 2"); my $part = $msg->attach(Data => "attachment 3"); $part->attach(Data => "attachment 4"); $part->attach(Data => "attachment 5"); is($msg->parts, 4, "->parts count is correct"); is($msg->parts_DFS, 7, "->parts_DFS count is correct"); done_testing; types.t100644000765000024 302615144704407 14261 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More; if (eval { require MIME::Types; MIME::Types->VERSION(1.28); 1 }) { plan tests => 1; } else { plan skip_all => "MIME::Types >= 1.28 not available"; } $MIME::Lite::VANILLA = 1; # warn "#\n#Testing MIME::Types interaction\n"; my $msg = MIME::Lite->new( From => 'me@myhost.com', To => 'you@yourhost.com', Cc => 'some@other.com, some@more.com', Subject => 'Helloooooo, nurse!', Data => "How's it goin', eh?" ); # this test requires output in a particular order, so specify it $msg->field_order(qw( Content-Transfer-Encoding Content-Type MIME-Version From To Cc Subject )); $msg->attach( Type => 'AUTO', Path => "./testin/test.html", ReadNow => 1, Filename => "test.html", ); (my $ret=$msg->stringify)=~s/^Date:.*\n//m; my $expect=<<'EOFEXPECT'; Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_0" MIME-Version: 1.0 From: me@myhost.com To: you@yourhost.com Cc: some@other.com, some@more.com Subject: Helloooooo, nurse! This is a multi-part message in MIME format. --_----------=_0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain How's it goin', eh? --_----------=_0 Content-Disposition: inline; filename="test.html" Content-Transfer-Encoding: 8bit Content-Type: text/html; name="test.html" This isn't really html. We are only checking the filename silly. --_----------=_0-- EOFEXPECT is($ret, $expect, "we got the message we expected"); META.json100644000765000024 5205115144704407 14130 0ustar00rjbsstaff000000000000MIME-Lite-3.038{ "abstract" : "low-calorie MIME generator", "author" : [ "Ricardo SIGNES ", "Eryq ", "Yves Orton" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.037, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "MIME-Lite", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.78" } }, "develop" : { "requires" : { "Encode" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0.94", "Test::Pod" : "1.41" } }, "runtime" : { "recommends" : { "MIME::Types" : "1.28", "Mail::Address" : "1.62" }, "requires" : { "Carp" : "0", "Email::Date::Format" : "1.000", "File::Basename" : "0", "File::Spec" : "0", "FileHandle" : "0", "Net::SMTP" : "0", "perl" : "5.012", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::More" : "0.96" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/rjbs/MIME-Lite/issues" }, "homepage" : "https://github.com/rjbs/MIME-Lite", "repository" : { "type" : "git", "url" : "https://github.com/rjbs/MIME-Lite.git", "web" : "https://github.com/rjbs/MIME-Lite" } }, "version" : "3.038", "x_Dist_Zilla" : { "perl" : { "version" : "5.040001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@RJBS/Git::GatherDir", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@RJBS/CheckPrereqsIndexed", "version" : "0.022" }, { "class" : "Dist::Zilla::Plugin::CheckExtraTests", "name" : "@RJBS/CheckExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 0, "check_all_prereqs" : 0, "modules" : [ "Dist::Zilla::PluginBundle::RJBS" ], "phase" : "build", "run_under_travis" : 0, "skip" : [] } }, "name" : "@RJBS/RJBS-Outdated", "version" : "0.060" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 1, "check_all_prereqs" : 0, "modules" : [], "phase" : "release", "run_under_travis" : 0, "skip" : [ "Dist::Zilla::Plugin::RJBSMisc" ] } }, "name" : "@RJBS/CPAN-Outdated", "version" : "0.060" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@RJBS/@Filter/PruneCruft", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@RJBS/@Filter/ManifestSkip", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@RJBS/@Filter/MetaYAML", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@RJBS/@Filter/License", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@RJBS/@Filter/Readme", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@RJBS/@Filter/ExecDir", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@RJBS/@Filter/ShareDir", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@RJBS/@Filter/Manifest", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@RJBS/@Filter/TestRelease", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@RJBS/@Filter/ConfirmRelease", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@RJBS/@Filter/UploadToCPAN", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 9 } }, "name" : "@RJBS/MakeMaker", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@RJBS/AutoPrereqs", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "config" : { "Dist::Zilla::Plugin::Git::NextVersion" : { "first_version" : "0.001", "version_by_branch" : 1, "version_regexp" : "(?^:^([0-9]+\\.[0-9]+)$)" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/Git::NextVersion", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "@RJBS/PkgVersion", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@RJBS/MetaConfig", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@RJBS/MetaJSON", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@RJBS/NextRelease", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Test::ChangesHasContent", "name" : "@RJBS/Test::ChangesHasContent", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@RJBS/PodSyntaxTests", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@RJBS/Test::ReportPrereqs", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::Git::Remote::Check", "name" : "@RJBS/Git::Remote::Check", "version" : "0.1.2" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 1, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "xt/author/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "develop", "script_finder" : [ ":PerlExecFiles" ], "skips" : [], "switch" : [] } }, "name" : "@RJBS/Test::Compile", "version" : "2.059" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@RJBS/TestMoreWithSubtests", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugins" : [ "@RJBS" ], "finder" : [ ":InstallModules", ":PerlExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@RJBS/SingleEncoding", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@RJBS/Name", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@RJBS/Version", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/Prelude", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Synopsis", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Description", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Overview", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Stability", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::GenerateSection", "name" : "@RJBS/PerlSupport", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Attributes", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Methods", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Functions", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@RJBS/Leftovers", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/postlude", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@RJBS/Authors", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "@RJBS/Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@RJBS/Legal", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "@RJBS/List", "version" : "4.020" } ] } }, "name" : "@RJBS/PodWeaver", "version" : "4.010" }, { "class" : "Dist::Zilla::Plugin::RJBSMisc", "name" : "@RJBS/RJBSMisc", "version" : "5.035" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@RJBS/GithubMeta", "version" : "0.58" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/@Git/Check", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%V%n%n%c", "signoff" : 0 }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Commit", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "3.038", "tag_format" : "%v", "tag_message" : "v%V" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Tag", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "github :" ], "remotes_must_exist" : 0 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/@Git/Push", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.50.1 (Apple Git-155)", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@RJBS/Git::Contributors", "version" : "0.038" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::RemovePrereqs", "config" : { "Dist::Zilla::Plugin::RemovePrereqs" : { "modules_to_remove" : [ "MIME::Types", "Mail::Address" ] } }, "name" : "RemovePrereqs", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "recommends" } }, "name" : "RuntimeRecommends", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.037" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.037" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.037" } }, "x_contributors" : [ "Claude ", "Damien Krotkine ", "David Steinbrunner ", "Florian ", "Jan Willamowius ", "John Bokma ", "Karen Etheridge ", "Max Maischein ", "Michael Schout ", "Michael Stevens ", "Peder Stray ", "Peter Heirich ", "Ricardo Signes ", "Tom Hukins " ], "x_generated_by_perl" : "v5.40.1", "x_rjbs_perl_window" : "long-term", "x_serialization_backend" : "Cpanel::JSON::XS version 4.40", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } verify.t100644000765000024 106515144704407 14422 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More tests => 2; $MIME::Lite::VANILLA = 1; $MIME::Lite::PARANOID = 1; my $msg; $msg = MIME::Lite->new(From => "me", To => "you"); $msg->attach(Path => "boguscmd |"); $msg->attach(Data => "Hello"); $msg->attach(Path => "verify_data }; like($@, qr/path\.to\.missing\.file/, "we detected a missing file"); $msg = MIME::Lite->new(From=>"me", To=>"you"); $msg->attach(Data => "Hello"); eval { $msg->verify_data }; ok(!$@, "we detected NO missing file"); Makefile.PL100644000765000024 276115144704407 14444 0ustar00rjbsstaff000000000000MIME-Lite-3.038# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.037 use strict; use warnings; use 5.012; use ExtUtils::MakeMaker 6.78; my %WriteMakefileArgs = ( "ABSTRACT" => "low-calorie MIME generator", "AUTHOR" => "Ricardo SIGNES , Eryq , Yves Orton", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.78" }, "DISTNAME" => "MIME-Lite", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.012", "NAME" => "MIME::Lite", "PREREQ_PM" => { "Carp" => 0, "Email::Date::Format" => "1.000", "File::Basename" => 0, "File::Spec" => 0, "FileHandle" => 0, "Net::SMTP" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::More" => "0.96" }, "VERSION" => "3.038", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Email::Date::Format" => "1.000", "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Spec" => 0, "FileHandle" => 0, "Net::SMTP" => 0, "Test::More" => "0.96", "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); sendmail.t100644000765000024 60615144704407 14672 0ustar00rjbsstaff000000000000MIME-Lite-3.038/t#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use Test::More tests => 2; use_ok('MIME::Lite') or exit 1; # set up dummy sendmail args. MIME::Lite->send('sendmail', '/foo/bar/sendmail -x -y -z'); # retrieve the settings. my @prev = MIME::Lite->send(sendmail => '/foo/bar/sendmail'); is_deeply \@prev, ['sendmail', '/foo/bar/sendmail -x -y -z'], 'sendmail args updated'; testin000755000765000024 015144704407 13632 5ustar00rjbsstaff000000000000MIME-Lite-3.038hello100644000765000024 1615144704407 14755 0ustar00rjbsstaff000000000000MIME-Lite-3.038/testinHello World README100644000765000024 2615144704407 14610 0ustar00rjbsstaff000000000000MIME-Lite-3.038/testinTest input directory contrib000755000765000024 015144704407 13764 5ustar00rjbsstaff000000000000MIME-Lite-3.038README100644000765000024 26415144704407 14766 0ustar00rjbsstaff000000000000MIME-Lite-3.038/contribSnippets in this directory have been contributed by users of MIME::Lite. Please don't email me with questions or comments; I'm not the maintainer... I'm just passing them on. examples000755000765000024 015144704407 14142 5ustar00rjbsstaff000000000000MIME-Lite-3.038nodisp100755000765000024 50415144704407 15503 0ustar00rjbsstaff000000000000MIME-Lite-3.038/examples#!/usr/bin/perl -w use MIME::Lite; use strict; my $msg = MIME::Lite->new(From => "me", To => "you", Subject => "hello", Type => "multipart/mixed"); my $part = $msg->attach(Type => "text/plain", Path => "/home/eryq/.cshrc", Encoding => '7bit'); $msg->scrub; $msg->print; MIME000755000765000024 015144704407 13621 5ustar00rjbsstaff000000000000MIME-Lite-3.038/libLite.pm100644000765000024 51347415144704407 15272 0ustar00rjbsstaff000000000000MIME-Lite-3.038/lib/MIMEpackage MIME::Lite 3.038; # ABSTRACT: low-calorie MIME generator use v5.12.0; use warnings; use File::Basename; #pod =begin :prelude #pod #pod =head1 WAIT! #pod #pod MIME::Lite is not recommended by its current maintainer. There are a number of #pod alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you #pod should probably use instead. MIME::Lite continues to accrue weird bug reports, #pod and it is not receiving a large amount of refactoring due to the availability #pod of better alternatives. Please consider using something else. #pod #pod =end :prelude #pod #pod =head1 SYNOPSIS #pod #pod Create and send using the default send method for your OS a single-part message: #pod #pod use MIME::Lite; #pod ### Create a new single-part message, to send a GIF file: #pod $msg = MIME::Lite->new( #pod From => 'me@myhost.com', #pod To => 'you@yourhost.com', #pod Cc => 'some@other.com, some@more.com', #pod Subject => 'Helloooooo, nurse!', #pod Type => 'image/gif', #pod Encoding => 'base64', #pod Path => 'hellonurse.gif' #pod ); #pod $msg->send; # send via default #pod #pod Create a multipart message (i.e., one with attachments) and send it via SMTP #pod #pod ### Create a new multipart message: #pod $msg = MIME::Lite->new( #pod From => 'me@myhost.com', #pod To => 'you@yourhost.com', #pod Cc => 'some@other.com, some@more.com', #pod Subject => 'A message with 2 parts...', #pod Type => 'multipart/mixed' #pod ); #pod #pod ### Add parts (each "attach" has same arguments as "new"): #pod $msg->attach( #pod Type => 'TEXT', #pod Data => "Here's the GIF file you wanted" #pod ); #pod $msg->attach( #pod Type => 'image/gif', #pod Path => 'aaa000123.gif', #pod Filename => 'logo.gif', #pod Disposition => 'attachment' #pod ); #pod ### use Net::SMTP to do the sending #pod $msg->send('smtp','some.host', Debug=>1 ); #pod #pod Output a message: #pod #pod ### Format as a string: #pod $str = $msg->as_string; #pod #pod ### Print to a filehandle (say, a "sendmail" stream): #pod $msg->print(\*SENDMAIL); #pod #pod Send a message: #pod #pod ### Send in the "best" way (the default is to use "sendmail"): #pod $msg->send; #pod ### Send a specific way: #pod $msg->send('type',@args); #pod #pod Specify default send method: #pod #pod MIME::Lite->send('smtp','some.host',Debug=>0); #pod #pod with authentication #pod #pod MIME::Lite->send('smtp','some.host', AuthUser=>$user, AuthPass=>$pass); #pod #pod using SSL #pod #pod MIME::Lite->send('smtp','some.host', SSL => 1, Port => 465 ); #pod #pod =head1 DESCRIPTION #pod #pod In the never-ending quest for great taste with fewer calories, #pod we proudly present: I. #pod #pod MIME::Lite is intended as a simple, standalone module for generating #pod (not parsing!) MIME messages... specifically, it allows you to #pod output a simple, decent single- or multi-part message with text or binary #pod attachments. It does not require that you have the Mail:: or MIME:: #pod modules installed, but will work with them if they are. #pod #pod You can specify each message part as either the literal data itself (in #pod a scalar or array), or as a string which can be given to open() to get #pod a readable filehandle (e.g., "new( #pod From =>'me@myhost.com', #pod To =>'you@yourhost.com', #pod Cc =>'some@other.com, some@more.com', #pod Subject =>'Helloooooo, nurse!', #pod Data =>"How's it goin', eh?" #pod ); #pod #pod =head2 Create a simple message containing just an image #pod #pod $msg = MIME::Lite->new( #pod From =>'me@myhost.com', #pod To =>'you@yourhost.com', #pod Cc =>'some@other.com, some@more.com', #pod Subject =>'Helloooooo, nurse!', #pod Type =>'image/gif', #pod Encoding =>'base64', #pod Path =>'hellonurse.gif' #pod ); #pod #pod #pod =head2 Create a multipart message #pod #pod ### Create the multipart "container": #pod $msg = MIME::Lite->new( #pod From =>'me@myhost.com', #pod To =>'you@yourhost.com', #pod Cc =>'some@other.com, some@more.com', #pod Subject =>'A message with 2 parts...', #pod Type =>'multipart/mixed' #pod ); #pod #pod ### Add the text message part: #pod ### (Note that "attach" has same arguments as "new"): #pod $msg->attach( #pod Type =>'TEXT', #pod Data =>"Here's the GIF file you wanted" #pod ); #pod #pod ### Add the image part: #pod $msg->attach( #pod Type =>'image/gif', #pod Path =>'aaa000123.gif', #pod Filename =>'logo.gif', #pod Disposition => 'attachment' #pod ); #pod #pod #pod =head2 Attach a GIF to a text message #pod #pod This will create a multipart message exactly as above, but using the #pod "attach to singlepart" hack: #pod #pod ### Start with a simple text message: #pod $msg = MIME::Lite->new( #pod From =>'me@myhost.com', #pod To =>'you@yourhost.com', #pod Cc =>'some@other.com, some@more.com', #pod Subject =>'A message with 2 parts...', #pod Type =>'TEXT', #pod Data =>"Here's the GIF file you wanted" #pod ); #pod #pod ### Attach a part... the make the message a multipart automatically: #pod $msg->attach( #pod Type =>'image/gif', #pod Path =>'aaa000123.gif', #pod Filename =>'logo.gif' #pod ); #pod #pod #pod =head2 Attach a pre-prepared part to a message #pod #pod ### Create a standalone part: #pod $part = MIME::Lite->new( #pod Top => 0, #pod Type =>'text/html', #pod Data =>'

Hello

', #pod ); #pod $part->attr('content-type.charset' => 'UTF-8'); #pod $part->add('X-Comment' => 'A message for you'); #pod #pod ### Attach it to any message: #pod $msg->attach($part); #pod #pod #pod =head2 Print a message to a filehandle #pod #pod ### Write it to a filehandle: #pod $msg->print(\*STDOUT); #pod #pod ### Write just the header: #pod $msg->print_header(\*STDOUT); #pod #pod ### Write just the encoded body: #pod $msg->print_body(\*STDOUT); #pod #pod #pod =head2 Print a message into a string #pod #pod ### Get entire message as a string: #pod $str = $msg->as_string; #pod #pod ### Get just the header: #pod $str = $msg->header_as_string; #pod #pod ### Get just the encoded body: #pod $str = $msg->body_as_string; #pod #pod #pod =head2 Send a message #pod #pod ### Send in the "best" way (the default is to use "sendmail"): #pod $msg->send; #pod #pod #pod =head2 Send an HTML document... with images included! #pod #pod $msg = MIME::Lite->new( #pod To =>'you@yourhost.com', #pod Subject =>'HTML with in-line images!', #pod Type =>'multipart/related' #pod ); #pod $msg->attach( #pod Type => 'text/html', #pod Data => qq{ #pod #pod Here's my image: #pod #pod #pod }, #pod ); #pod $msg->attach( #pod Type => 'image/gif', #pod Id => 'myimage.gif', #pod Path => '/path/to/somefile.gif', #pod ); #pod $msg->send(); #pod #pod #pod =head2 Change how messages are sent #pod #pod ### Do something like this in your 'main': #pod if ($I_DONT_HAVE_SENDMAIL) { #pod MIME::Lite->send('smtp', $host, Timeout=>60, #pod AuthUser=>$user, AuthPass=>$pass); #pod } #pod #pod ### Now this will do the right thing: #pod $msg->send; ### will now use Net::SMTP as shown above #pod #pod =head1 PUBLIC INTERFACE #pod #pod =head2 Global configuration #pod #pod To alter the way the entire module behaves, you have the following #pod methods/options: #pod #pod =over 4 #pod #pod #pod =item MIME::Lite->field_order() #pod #pod When used as a L, this changes the default #pod order in which headers are output for I messages. #pod However, please consider using the instance method variant instead, #pod so you won't stomp on other message senders in the same application. #pod #pod #pod =item MIME::Lite->quiet() #pod #pod This L can be used to suppress/unsuppress #pod all warnings coming from this module. #pod #pod #pod =item MIME::Lite->send() #pod #pod When used as a L, this can be used to specify #pod a different default mechanism for sending message. #pod The initial default is: #pod #pod MIME::Lite->send("sendmail", "/usr/lib/sendmail -t -oi -oem"); #pod #pod However, you should consider the similar but smarter and taint-safe variant: #pod #pod MIME::Lite->send("sendmail"); #pod #pod Or, for non-Unix users: #pod #pod MIME::Lite->send("smtp"); #pod #pod #pod =item $MIME::Lite::AUTO_CC #pod #pod If true, automatically send to the Cc/Bcc addresses for send_by_smtp(). #pod Default is B. #pod #pod #pod =item $MIME::Lite::AUTO_CONTENT_TYPE #pod #pod If true, try to automatically choose the content type from the file name #pod in C/C. In other words, setting this true changes the #pod default C from C<"TEXT"> to C<"AUTO">. #pod #pod Default is B, since we must maintain backwards-compatibility #pod with prior behavior. B consider keeping it false, #pod and just using Type 'AUTO' when you build() or attach(). #pod #pod #pod =item $MIME::Lite::AUTO_ENCODE #pod #pod If true, automatically choose the encoding from the content type. #pod Default is B. #pod #pod #pod =item $MIME::Lite::AUTO_VERIFY #pod #pod If true, check paths to attachments right before printing, raising an exception #pod if any path is unreadable. #pod Default is B. #pod #pod #pod =item $MIME::Lite::PARANOID #pod #pod If true, we won't attempt to use MIME::Base64, MIME::QuotedPrint, #pod or MIME::Types, even if they're available. #pod Default is B. Please consider keeping it false, #pod and trusting these other packages to do the right thing. #pod #pod #pod =back #pod #pod =cut use Carp (); use FileHandle; # GLOBALS, EXTERNAL/CONFIGURATION... ### Automatically interpret CC/BCC for SMTP: our $AUTO_CC = 1; ### Automatically choose content type from file name: our $AUTO_CONTENT_TYPE = 0; ### Automatically choose encoding from content type: our $AUTO_ENCODE = 1; ### Check paths right before printing: our $AUTO_VERIFY = 1; ### Set this true if you don't want to use MIME::Base64/QuotedPrint/Types: our $PARANOID = 0; ### Don't warn me about dangerous activities: our $QUIET = undef; ### Unsupported (for tester use): don't qualify boundary with time/pid: our $VANILLA = 0; our $DEBUG = 0; #============================== #============================== # # GLOBALS, INTERNAL... my $Sender = ""; my $SENDMAIL = ""; if ( $^O =~ /win32|cygwin/i ) { $Sender = "smtp"; } else { ### Find sendmail: $Sender = "sendmail"; $SENDMAIL = "/usr/lib/sendmail"; ( -x $SENDMAIL ) or ( $SENDMAIL = "/usr/sbin/sendmail" ); ( -x $SENDMAIL ) or ( $SENDMAIL = "sendmail" ); unless (-x $SENDMAIL) { require File::Spec; for my $dir (File::Spec->path) { if ( -x "$dir/sendmail" ) { $SENDMAIL = "$dir/sendmail"; last; } } } unless (-x $SENDMAIL) { undef $SENDMAIL; } } ### Our sending facilities: my %SenderArgs = ( sendmail => [], smtp => [], sub => [], ); ### Boundary counter: my $BCount = 0; ### Known Mail/MIME fields... these, plus some general forms like ### "x-*", are recognized by build(): my %KnownField = map { $_ => 1 } qw( bcc cc comments date encrypted from keywords message-id mime-version organization received references reply-to return-path sender subject to in-reply-to approved ); ### What external packages do we use for encoding? my @Uses = ( "F" . File::Basename->VERSION, ); ### Header order: my @FieldOrder; ### See if we have/want MIME::Types my $HaveMimeTypes = 0; if ( !$PARANOID and eval "require MIME::Types; MIME::Types->VERSION(1.28);" ) { $HaveMimeTypes = 1; push @Uses, "T$MIME::Types::VERSION"; } #============================== #============================== # # PRIVATE UTILITY FUNCTIONS... #------------------------------ # # fold STRING # # Make STRING safe as a field value. Remove leading/trailing whitespace, # and make sure newlines are represented as newline+space sub fold { my $str = shift; $str =~ s/^\s*|\s*$//g; ### trim $str =~ s/\n/\n /g; $str; } #------------------------------ # # gen_boundary # # Generate a new boundary to use. # The unsupported $VANILLA is for test purposes only. sub gen_boundary { return ( "_----------=_" . ( $VANILLA ? '' : int(time) . $$ ) . $BCount++ ); } #------------------------------ # # is_mime_field FIELDNAME # # Is this a field I manage? sub is_mime_field { $_[0] =~ /^(mime\-|content\-)/i; } #------------------------------ # # extract_full_addrs STRING # extract_only_addrs STRING # # Split STRING into an array of email addresses: somewhat of a KLUDGE. # # Unless paranoid, we try to load the real code before supplying our own. BEGIN { my $ATOM = '[^ \000-\037()<>@,;:\134"\056\133\135]+'; my $QSTR = '".*?"'; my $WORD = '(?:' . $QSTR . '|' . $ATOM . ')'; my $DOMAIN = '(?:' . $ATOM . '(?:' . '\\.' . $ATOM . ')*' . ')'; my $LOCALPART = '(?:' . $WORD . '(?:' . '\\.' . $WORD . ')*' . ')'; my $ADDR = '(?:' . $LOCALPART . '@' . $DOMAIN . ')'; my $PHRASE = '(?:' . $WORD . ')+'; my $SEP = "(?:^\\s*|\\s*,\\s*)"; ### before elems in a list sub my_extract_full_addrs { my $str = shift; return unless $str; my @addrs; $str =~ s/\s/ /g; ### collapse whitespace pos($str) = 0; while ( $str !~ m{\G\s*\Z}gco ) { ### print STDERR "TACKLING: ".substr($str, pos($str))."\n"; if ( $str =~ m{\G$SEP($PHRASE)\s*<\s*($ADDR)\s*>}gco ) { push @addrs, "$1 <$2>"; } elsif ( $str =~ m{\G$SEP($ADDR)}gco or $str =~ m{\G$SEP($ATOM)}gco ) { push @addrs, $1; } else { my $problem = substr( $str, pos($str) ); die "can't extract address at <$problem> in <$str>\n"; } } return wantarray ? @addrs : $addrs[0]; } sub my_extract_only_addrs { my @ret = map { /<([^>]+)>/ ? $1 : $_ } my_extract_full_addrs(@_); return wantarray ? @ret : $ret[0]; } } #------------------------------ if ( !$PARANOID and eval "require Mail::Address" ) { push @Uses, "A$Mail::Address::VERSION"; eval q{ sub extract_full_addrs { my @ret=map { $_->format } Mail::Address->parse($_[0]); return wantarray ? @ret : $ret[0] } sub extract_only_addrs { my @ret=map { $_->address } Mail::Address->parse($_[0]); return wantarray ? @ret : $ret[0] } }; ### q } else { eval q{ *extract_full_addrs=*my_extract_full_addrs; *extract_only_addrs=*my_extract_only_addrs; }; ### q } ### if #============================== #============================== # # PRIVATE ENCODING FUNCTIONS... #------------------------------ # # encode_base64 STRING # # Encode the given string using BASE64. # Unless paranoid, we try to load the real code before supplying our own. if ( !$PARANOID and eval "require MIME::Base64" ) { MIME::Base64->import(qw(encode_base64)); push @Uses, "B$MIME::Base64::VERSION"; } else { eval q{ sub encode_base64 { my $res = ""; my $eol = "\n"; pos($_[0]) = 0; ### thanks, Andreas! while ($_[0] =~ /(.{1,45})/gs) { $res .= substr(pack('u', $1), 1); chop($res); } $res =~ tr|` -_|AA-Za-z0-9+/|; ### Fix padding at the end: my $padding = (3 - length($_[0]) % 3) % 3; $res =~ s/.{$padding}$/'=' x $padding/e if $padding; ### Break encoded string into lines of no more than 76 characters each: $res =~ s/(.{1,76})/$1$eol/g if (length $eol); return $res; } ### sub } ### q } ### if #------------------------------ # # encode_qp STRING # # Encode the given string, LINE BY LINE, using QUOTED-PRINTABLE. # Stolen from MIME::QuotedPrint by Gisle Aas, with a slight bug fix: we # break lines earlier. Notice that this seems not to work unless # encoding line by line. # # Unless paranoid, we try to load the real code before supplying our own. if ( !$PARANOID and eval "require MIME::QuotedPrint" ) { import MIME::QuotedPrint qw(encode_qp); push @Uses, "Q$MIME::QuotedPrint::VERSION"; } else { eval q{ sub encode_qp { my $res = shift; local($_); $res =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord($1))/eg; ### rule #2,#3 $res =~ s/([ \t]+)$/ join('', map { sprintf("=%02X", ord($_)) } split('', $1) )/egm; ### rule #3 (encode whitespace at eol) ### rule #5 (lines shorter than 76 chars, but can't break =XX escapes: my $brokenlines = ""; $brokenlines .= "$1=\n" while $res =~ s/^(.{70}([^=]{2})?)//; ### 70 was 74 $brokenlines =~ s/=\n$// unless length $res; "$brokenlines$res"; } ### sub } ### q } ### if #------------------------------ # # encode_8bit STRING # # Encode the given string using 8BIT. # This breaks long lines into shorter ones. sub encode_8bit { my $str = shift; $str =~ s/^(.{990})/$1\n/mg; $str; } #------------------------------ # # encode_7bit STRING # # Encode the given string using 7BIT. # This NO LONGER protects people through encoding. sub encode_7bit { my $str = shift; $str =~ s/[\x80-\xFF]//g; $str =~ s/^(.{990})/$1\n/mg; $str; } #============================== #============================== #pod =head2 Construction #pod #pod =over 4 #pod #pod =cut #------------------------------ #pod =item new [PARAMHASH] #pod #pod I #pod Create a new message object. #pod #pod If any arguments are given, they are passed into C; otherwise, #pod just the empty object is created. #pod #pod =cut sub new { my $class = shift; ### Create basic object: my $self = { Attrs => {}, ### MIME attributes SubAttrs => {}, ### MIME sub-attributes Header => [], ### explicit message headers Parts => [], ### array of parts }; bless $self, $class; ### Build, if needed: return ( @_ ? $self->build(@_) : $self ); } #------------------------------ #pod =item attach PART #pod #pod =item attach PARAMHASH... #pod #pod I #pod Add a new part to this message, and return the new part. #pod #pod If you supply a single PART argument, it will be regarded #pod as a MIME::Lite object to be attached. Otherwise, this #pod method assumes that you are giving in the pairs of a PARAMHASH #pod which will be sent into C to create the new part. #pod #pod One of the possibly-quite-useful hacks thrown into this is the #pod "attach-to-singlepart" hack: if you attempt to attach a part (let's #pod call it "part 1") to a message that doesn't have a content-type #pod of "multipart" or "message", the following happens: #pod #pod =over 4 #pod #pod =item * #pod #pod A new part (call it "part 0") is made. #pod #pod =item * #pod #pod The MIME attributes and data (but I the other headers) #pod are cut from the "self" message, and pasted into "part 0". #pod #pod =item * #pod #pod The "self" is turned into a "multipart/mixed" message. #pod #pod =item * #pod #pod The new "part 0" is added to the "self", and I "part 1" is added. #pod #pod =back #pod #pod One of the nice side-effects is that you can create a text message #pod and then add zero or more attachments to it, much in the same way #pod that a user agent like Netscape allows you to do. #pod #pod =cut sub attach { my $self = shift; my $attrs = $self->{Attrs}; my $sub_attrs = $self->{SubAttrs}; ### Create new part, if necessary: my $part1 = ( ( @_ == 1 ) ? shift: ref($self)->new( Top => 0, @_ ) ); ### Do the "attach-to-singlepart" hack: if ( $attrs->{'content-type'} !~ m{^(multipart|message)/}i ) { ### Create part zero: my $part0 = ref($self)->new; ### Cut MIME stuff from self, and paste into part zero: foreach (qw(SubAttrs Attrs Data Path FH)) { $part0->{$_} = $self->{$_}; delete( $self->{$_} ); } $part0->top_level(0); ### clear top-level attributes ### Make self a top-level multipart: $attrs = $self->{Attrs} ||= {}; ### reset (sam: bug? this doesn't reset anything since Attrs is already a hash-ref) $sub_attrs = $self->{SubAttrs} ||= {}; ### reset $attrs->{'content-type'} = 'multipart/mixed'; $sub_attrs->{'content-type'}{'boundary'} = gen_boundary(); $attrs->{'content-transfer-encoding'} = '7bit'; $self->top_level(1); ### activate top-level attributes ### Add part 0: push @{ $self->{Parts} }, $part0; } ### Add the new part: push @{ $self->{Parts} }, $part1; $part1; } #------------------------------ #pod =item build [PARAMHASH] #pod #pod I #pod Create (or initialize) a MIME message object. #pod Normally, you'll use the following keys in PARAMHASH: #pod #pod * Data, FH, or Path (either one of these, or none if multipart) #pod * Type (e.g., "image/jpeg") #pod * From, To, and Subject (if this is the "top level" of a message) #pod #pod The PARAMHASH can contain the following keys: #pod #pod =over 4 #pod #pod =item (fieldname) #pod #pod Any field you want placed in the message header, taken from the #pod standard list of header fields (you don't need to worry about case): #pod #pod Approved Encrypted Received Sender #pod Bcc From References Subject #pod Cc Keywords Reply-To To #pod Comments Message-ID Resent-* X-* #pod Content-* MIME-Version Return-Path #pod Date Organization #pod #pod To give experienced users some veto power, these fields will be set #pod I the ones I set... so be careful: I #pod (like C) unless you know what you're doing! #pod #pod To specify a fieldname that's I in the above list, even one that's #pod identical to an option below, just give it with a trailing C<":">, #pod like C<"My-field:">. When in doubt, that I signals a mail #pod field (and it sort of looks like one too). #pod #pod =item Data #pod #pod I #pod The actual message data. This may be a scalar or a ref to an array of #pod strings; if the latter, the message consists of a simple concatenation #pod of all the strings in the array. #pod #pod =item Datestamp #pod #pod I #pod If given true (or omitted), we force the creation of a C field #pod stamped with the current date/time if this is a top-level message. #pod You may want this if using L. #pod If you don't want this to be done, either provide your own Date #pod or explicitly set this to false. #pod #pod =item Disposition #pod #pod I #pod The content disposition, C<"inline"> or C<"attachment">. #pod The default is C<"inline">. #pod #pod =item Encoding #pod #pod I #pod The content transfer encoding that should be used to encode your data: #pod #pod Use encoding: | If your message contains: #pod ------------------------------------------------------------ #pod 7bit | Only 7-bit text, all lines <1000 characters #pod 8bit | 8-bit text, all lines <1000 characters #pod quoted-printable | 8-bit text or long lines (more reliable than "8bit") #pod base64 | Largely non-textual data: a GIF, a tar file, etc. #pod #pod The default is taken from the Type; generally it is "binary" (no #pod encoding) for text/*, message/*, and multipart/*, and "base64" for #pod everything else. A value of C<"binary"> is generally I suitable #pod for sending anything but ASCII text files with lines under 1000 #pod characters, so consider using one of the other values instead. #pod #pod In the case of "7bit"/"8bit", long lines are automatically chopped to #pod legal length; in the case of "7bit", all 8-bit characters are #pod automatically I. This may not be what you want, so pick your #pod encoding well! For more info, see L<"A MIME PRIMER">. #pod #pod =item FH #pod #pod I #pod Filehandle containing the data, opened for reading. #pod See "ReadNow" also. #pod #pod =item Filename #pod #pod I #pod The name of the attachment. You can use this to supply a #pod recommended filename for the end-user who is saving the attachment #pod to disk. You only need this if the filename at the end of the #pod "Path" is inadequate, or if you're using "Data" instead of "Path". #pod You should I put path information in here (e.g., no "/" #pod or "\" or ":" characters should be used). #pod #pod =item Id #pod #pod I #pod Same as setting "content-id". #pod #pod =item Length #pod #pod I #pod Set the content length explicitly. Normally, this header is automatically #pod computed, but only under certain circumstances (see L<"Benign limitations">). #pod #pod =item Path #pod #pod I #pod Path to a file containing the data... actually, it can be any open()able #pod expression. If it looks like a path, the last element will automatically #pod be treated as the filename. #pod See "ReadNow" also. #pod #pod =item ReadNow #pod #pod I #pod If true, will open the path and slurp the contents into core now. #pod This is useful if the Path points to a command and you don't want #pod to run the command over and over if outputting the message several #pod times. B raised if the open fails. #pod #pod =item Top #pod #pod I #pod If defined, indicates whether or not this is a "top-level" MIME message. #pod The parts of a multipart message are I top-level. #pod Default is true. #pod #pod =item Type #pod #pod I #pod The MIME content type, or one of these special values (case-sensitive): #pod #pod "TEXT" means "text/plain" #pod "BINARY" means "application/octet-stream" #pod "AUTO" means attempt to guess from the filename, falling back #pod to 'application/octet-stream'. This is good if you have #pod MIME::Types on your system and you have no idea what #pod file might be used for the attachment. #pod #pod The default is C<"TEXT">, but it will be C<"AUTO"> if you set #pod $AUTO_CONTENT_TYPE to true (sorry, but you have to enable #pod it explicitly, since we don't want to break code which depends #pod on the old behavior). #pod #pod =back #pod #pod A picture being worth 1000 words (which #pod is of course 2000 bytes, so it's probably more of an "icon" than a "picture", #pod but I digress...), here are some examples: #pod #pod $msg = MIME::Lite->build( #pod From => 'yelling@inter.com', #pod To => 'stocking@fish.net', #pod Subject => "Hi there!", #pod Type => 'TEXT', #pod Encoding => '7bit', #pod Data => "Just a quick note to say hi!" #pod ); #pod #pod $msg = MIME::Lite->build( #pod From => 'dorothy@emerald-city.oz', #pod To => 'gesundheit@edu.edu.edu', #pod Subject => "A gif for U" #pod Type => 'image/gif', #pod Path => "/home/httpd/logo.gif" #pod ); #pod #pod $msg = MIME::Lite->build( #pod From => 'laughing@all.of.us', #pod To => 'scarlett@fiddle.dee.de', #pod Subject => "A gzipp'ed tar file", #pod Type => 'x-gzip', #pod Path => "gzip < /usr/inc/somefile.tar |", #pod ReadNow => 1, #pod Filename => "somefile.tgz" #pod ); #pod #pod To show you what's really going on, that last example could also #pod have been written: #pod #pod $msg = new MIME::Lite; #pod $msg->build( #pod Type => 'x-gzip', #pod Path => "gzip < /usr/inc/somefile.tar |", #pod ReadNow => 1, #pod Filename => "somefile.tgz" #pod ); #pod $msg->add(From => "laughing@all.of.us"); #pod $msg->add(To => "scarlett@fiddle.dee.de"); #pod $msg->add(Subject => "A gzipp'ed tar file"); #pod #pod =cut sub build { my $self = shift; my %params = @_; my @params = @_; my $key; ### Miko's note: reorganized to check for exactly one of Data, Path, or FH ( defined( $params{Data} ) + defined( $params{Path} ) + defined( $params{FH} ) <= 1 ) or Carp::croak "supply exactly zero or one of (Data|Path|FH).\n"; ### Create new instance, if necessary: ref($self) or $self = $self->new; ### CONTENT-TYPE.... ### ### Get content-type or content-type-macro: my $type = ( $params{Type} || ( $AUTO_CONTENT_TYPE ? 'AUTO' : 'TEXT' ) ); ### Interpret content-type-macros: if ( $type eq 'TEXT' ) { $type = 'text/plain'; } elsif ( $type eq 'HTML' ) { $type = 'text/html'; } elsif ( $type eq 'BINARY' ) { $type = 'application/octet-stream' } elsif ( $type eq 'AUTO' ) { $type = $self->suggest_type( $params{Path} ); } ### We now have a content-type; set it: $type = lc($type); my $attrs = $self->{Attrs}; my $sub_attrs = $self->{SubAttrs}; $attrs->{'content-type'} = $type; ### Get some basic attributes from the content type: my $is_multipart = ( $type =~ m{^(multipart)/}i ); ### Add in the multipart boundary: if ($is_multipart) { my $boundary = gen_boundary(); $sub_attrs->{'content-type'}{'boundary'} = $boundary; } ### CONTENT-ID... ### if ( defined $params{Id} ) { my $id = $params{Id}; $id = "<$id>" unless $id =~ /\A\s*<.*>\s*\z/; $attrs->{'content-id'} = $id; } ### DATA OR PATH... ### Note that we must do this *after* we get the content type, ### in case read_now() is invoked, since it needs the binmode(). ### Get data, as... ### ...either literal data: if ( defined( $params{Data} ) ) { $self->data( $params{Data} ); } ### ...or a path to data: elsif ( defined( $params{Path} ) ) { $self->path( $params{Path} ); ### also sets filename $self->read_now if $params{ReadNow}; } ### ...or a filehandle to data: ### Miko's note: this part works much like the path routine just above, elsif ( defined( $params{FH} ) ) { $self->fh( $params{FH} ); $self->read_now if $params{ReadNow}; ### implement later } ### FILENAME... (added by Ian Smith on 8/4/97) ### Need this to make sure the filename is added. The Filename ### attribute is ignored, otherwise. if ( defined( $params{Filename} ) ) { $self->filename( $params{Filename} ); } ### CONTENT-TRANSFER-ENCODING... ### ### Get it: my $enc = ( $params{Encoding} || ( $AUTO_ENCODE and $self->suggest_encoding($type) ) || 'binary' ); $attrs->{'content-transfer-encoding'} = lc($enc); ### Sanity check: if ( $type =~ m{^(multipart|message)/} ) { ( $enc =~ m{^(7bit|8bit|binary)\Z} ) or Carp::croak( "illegal MIME: " . "can't have encoding $enc with type $type\n" ); } ### CONTENT-DISPOSITION... ### Default is inline for single, none for multis: ### my $disp = ( $params{Disposition} or ( $is_multipart ? undef: 'inline' ) ); $attrs->{'content-disposition'} = $disp; ### CONTENT-LENGTH... ### my $length; if ( exists( $params{Length} ) ) { ### given by caller: $attrs->{'content-length'} = $params{Length}; } else { ### compute it ourselves $self->get_length; } ### Init the top-level fields: my $is_top = defined( $params{Top} ) ? $params{Top} : 1; $self->top_level($is_top); ### Datestamp if desired: my $ds_wanted = $params{Datestamp}; my $ds_defaulted = ( $is_top and !exists( $params{Datestamp} ) ); if ( ( $ds_wanted or $ds_defaulted ) and !exists( $params{Date} ) ) { require Email::Date::Format; $self->add( "date", Email::Date::Format::email_date() ); } ### Set message headers: my @paramz = @params; my $field; while (@paramz) { my ( $tag, $value ) = ( shift(@paramz), shift(@paramz) ); my $lc_tag = lc($tag); ### Get tag, if a tag: if ( $lc_tag =~ /^-(.*)/ ) { ### old style, backwards-compatibility $field = $1; } elsif ( $lc_tag =~ /^(.*):$/ ) { ### new style $field = $1; } elsif ( $KnownField{$lc_tag} or $lc_tag =~ m{^(content|resent|x)-.} ){ $field = $lc_tag; } else { ### not a field: next; } ### Add it: $self->add( $field, $value ); } ### Done! $self; } #pod =back #pod #pod =cut #============================== #============================== #pod =head2 Setting/getting headers and attributes #pod #pod =over 4 #pod #pod =cut #------------------------------ # # top_level ONOFF # # Set/unset the top-level attributes and headers. # This affects "MIME-Version", "X-Mailer", and "Date" sub top_level { my ( $self, $onoff ) = @_; my $attrs = $self->{Attrs}; if ($onoff) { $attrs->{'mime-version'} = '1.0'; my $uses = ( @Uses ? ( "(" . join( "; ", @Uses ) . ")" ) : '' ); $self->replace( 'X-Mailer' => "MIME::Lite $MIME::Lite::VERSION $uses" ) unless $VANILLA; } else { delete $attrs->{'mime-version'}; $self->delete('X-Mailer'); $self->delete('Date'); } } #------------------------------ #pod =item add TAG,VALUE #pod #pod I #pod Add field TAG with the given VALUE to the end of the header. #pod The TAG will be converted to all-lowercase, and the VALUE #pod will be made "safe" (returns will be given a trailing space). #pod #pod B any MIME fields you "add" will override any MIME #pod attributes I have when it comes time to output those fields. #pod Normally, you will use this method to add I fields: #pod #pod $msg->add("Subject" => "Hi there!"); #pod #pod Giving VALUE as an arrayref will cause all those values to be added. #pod This is only useful for special multiple-valued fields like "Received": #pod #pod $msg->add("Received" => ["here", "there", "everywhere"] #pod #pod Giving VALUE as the empty string adds an invisible placeholder #pod to the header, which can be used to suppress the output of #pod the "Content-*" fields or the special "MIME-Version" field. #pod When suppressing fields, you should use replace() instead of add(): #pod #pod $msg->replace("Content-disposition" => ""); #pod #pod I add() is probably going to be more efficient than C, #pod so you're better off using it for most applications if you are #pod certain that you don't need to delete() the field first. #pod #pod I the name comes from Mail::Header. #pod #pod =cut sub add { my $self = shift; my $tag = lc(shift); my $value = shift; ### If a dangerous option, warn them: Carp::carp "Explicitly setting a MIME header field ($tag) is dangerous:\n" . "use the attr() method instead.\n" if ( is_mime_field($tag) && !$QUIET ); ### Get array of clean values: my @vals = ( ( ref($value) and ( ref($value) eq 'ARRAY' ) ) ? @{$value} : ( $value . '' ) ); map { s/\n/\n /g } @vals; ### Add them: foreach (@vals) { push @{ $self->{Header} }, [ $tag, $_ ]; } } #------------------------------ #pod =item attr ATTR,[VALUE] #pod #pod I #pod Set MIME attribute ATTR to the string VALUE. #pod ATTR is converted to all-lowercase. #pod This method is normally used to set/get MIME attributes: #pod #pod $msg->attr("content-type" => "text/html"); #pod $msg->attr("content-type.charset" => "US-ASCII"); #pod $msg->attr("content-type.name" => "homepage.html"); #pod #pod This would cause the final output to look something like this: #pod #pod Content-type: text/html; charset=US-ASCII; name="homepage.html" #pod #pod Note that the special empty sub-field tag indicates the anonymous #pod first sub-field. #pod #pod Giving VALUE as undefined will cause the contents of the named #pod subfield to be deleted. #pod #pod Supplying no VALUE argument just returns the attribute's value: #pod #pod $type = $msg->attr("content-type"); ### returns "text/html" #pod $name = $msg->attr("content-type.name"); ### returns "homepage.html" #pod #pod =cut sub attr { my ( $self, $attr, $value ) = @_; my $attrs = $self->{Attrs}; $attr = lc($attr); ### Break attribute name up: my ( $tag, $subtag ) = split /\./, $attr; if (defined($subtag)) { $attrs = $self->{SubAttrs}{$tag} ||= {}; $tag = $subtag; } ### Set or get? if ( @_ > 2 ) { ### set: if ( defined($value) ) { $attrs->{$tag} = $value; } else { delete $attrs->{$tag}; } } ### Return current value: $attrs->{$tag}; } sub _safe_attr { my ( $self, $attr ) = @_; return defined $self->{Attrs}{$attr} ? $self->{Attrs}{$attr} : ''; } #------------------------------ #pod =item delete TAG #pod #pod I #pod Delete field TAG with the given VALUE to the end of the header. #pod The TAG will be converted to all-lowercase. #pod #pod $msg->delete("Subject"); #pod #pod I the name comes from Mail::Header. #pod #pod =cut sub delete { my $self = shift; my $tag = lc(shift); ### Delete from the header: my $hdr = []; my $field; foreach $field ( @{ $self->{Header} } ) { push @$hdr, $field if ( $field->[0] ne $tag ); } $self->{Header} = $hdr; $self; } #------------------------------ #pod =item field_order FIELD,...FIELD #pod #pod I #pod Change the order in which header fields are output for this object: #pod #pod $msg->field_order('from', 'to', 'content-type', 'subject'); #pod #pod When used as a class method, changes the default settings for #pod all objects: #pod #pod MIME::Lite->field_order('from', 'to', 'content-type', 'subject'); #pod #pod Case does not matter: all field names will be coerced to lowercase. #pod In either case, supply the empty array to restore the default ordering. #pod #pod =cut sub field_order { my $self = shift; if ( ref($self) ) { $self->{FieldOrder} = [ map { lc($_) } @_ ]; } else { @FieldOrder = map { lc($_) } @_; } } #------------------------------ #pod =item fields #pod #pod I #pod Return the full header for the object, as a ref to an array #pod of C<[TAG, VALUE]> pairs, where each TAG is all-lowercase. #pod Note that any fields the user has explicitly set will override the #pod corresponding MIME fields that we would otherwise generate. #pod So, don't say... #pod #pod $msg->set("Content-type" => "text/html; charset=US-ASCII"); #pod #pod unless you want the above value to override the "Content-type" #pod MIME field that we would normally generate. #pod #pod I I called this "fields" because the header() method of #pod Mail::Header returns something different, but similar enough to #pod be confusing. #pod #pod You can change the order of the fields: see L. #pod You really shouldn't need to do this, but some people have to #pod deal with broken mailers. #pod #pod =cut sub fields { my $self = shift; my @fields; my $attrs = $self->{Attrs}; my $sub_attrs = $self->{SubAttrs}; ### Get a lookup-hash of all *explicitly-given* fields: my %explicit = map { $_->[0] => 1 } @{ $self->{Header} }; ### Start with any MIME attributes not given explicitly: my $tag; foreach $tag ( sort keys %{ $self->{Attrs} } ) { ### Skip if explicit: next if ( $explicit{$tag} ); # get base attr value or skip if not available my $value = $attrs->{$tag}; defined $value or next; ### handle sub-attrs if available if (my $subs = $sub_attrs->{$tag}) { $value .= '; ' . join('; ', map { /\*$/ ? qq[$_=$subs->{$_}] : qq[$_="$subs->{$_}"] } sort keys %$subs); } # handle stripping \r\n now since we're not doing it in attr() # anymore $value =~ tr/\r\n//; ### Add to running fields; push @fields, [ $tag, $value ]; } ### Add remaining fields (note that we duplicate the array for safety): foreach ( @{ $self->{Header} } ) { push @fields, [ @{$_} ]; } ### Final step: ### If a suggested ordering was given, we "sort" by that ordering. ### The idea is that we give each field a numeric rank, which is ### (1000 * order(field)) + origposition. my @order = @{ $self->{FieldOrder} || [] }; ### object-specific @order or @order = @FieldOrder; ### no? maybe generic if (@order) { ### either? ### Create hash mapping field names to 1-based rank: my %rank = map { $order[$_] => ( 1 + $_ ) } ( 0 .. $#order ); ### Create parallel array to @fields, called @ranked. ### It contains fields tagged with numbers like 2003, where the ### 3 is the original 0-based position, and 2000 indicates that ### we wanted this type of field to go second. my @ranked = map { [ ( $_ + 1000 * ( $rank{ lc( $fields[$_][0] ) } || ( 2 + $#order ) ) ), $fields[$_] ] } ( 0 .. $#fields ); # foreach (@ranked) { # print STDERR "RANKED: $_->[0] $_->[1][0] $_->[1][1]\n"; # } ### That was half the Schwartzian transform. Here's the rest: @fields = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @ranked; } ### Done! return \@fields; } #------------------------------ #pod =item filename [FILENAME] #pod #pod I #pod Set the filename which this data will be reported as. #pod This actually sets both "standard" attributes. #pod #pod With no argument, returns the filename as dictated by the #pod content-disposition. #pod #pod =cut sub filename { my ( $self, $filename ) = @_; my $sub_attrs = $self->{SubAttrs}; if ( @_ > 1 ) { $sub_attrs->{'content-type'}{'name'} = $filename; $sub_attrs->{'content-disposition'}{'filename'} = $filename; } return $sub_attrs->{'content-disposition'}{'filename'}; } #------------------------------ #pod =item get TAG,[INDEX] #pod #pod I #pod Get the contents of field TAG, which might have been set #pod with set() or replace(). Returns the text of the field. #pod #pod $ml->get('Subject', 0); #pod #pod If the optional 0-based INDEX is given, then we return the INDEX'th #pod occurrence of field TAG. Otherwise, we look at the context: #pod In a scalar context, only the first (0th) occurrence of the #pod field is returned; in an array context, I occurrences are returned. #pod #pod I this should only be used with non-MIME fields. #pod Behavior with MIME fields is TBD, and will raise an exception for now. #pod #pod =cut sub get { my ( $self, $tag, $index ) = @_; $tag = lc($tag); Carp::croak "get: can't be used with MIME fields\n" if is_mime_field($tag); my @all = map { ( $_->[0] eq $tag ) ? $_->[1] : () } @{ $self->{Header} }; ( defined($index) ? $all[$index] : ( wantarray ? @all : $all[0] ) ); } #------------------------------ #pod =item get_length #pod #pod I #pod Recompute the content length for the message I, #pod setting the "content-length" attribute as a side-effect: #pod #pod $msg->get_length; #pod #pod Returns the length, or undefined if not set. #pod #pod I the content length can be difficult to compute, since it #pod involves assembling the entire encoded body and taking the length #pod of it (which, in the case of multipart messages, means freezing #pod all the sub-parts, etc.). #pod #pod This method only sets the content length to a defined value if the #pod message is a singlepart with C<"binary"> encoding, I the body is #pod available either in-core or as a simple file. Otherwise, the content #pod length is set to the undefined value. #pod #pod Since content-length is not a standard MIME field anyway (that's right, kids: #pod it's not in the MIME RFCs, it's an HTTP thing), this seems pretty fair. #pod #pod =cut #---- # Miko's note: I wasn't quite sure how to handle this, so I waited to hear # what you think. Given that the content-length isn't always required, # and given the performance cost of calculating it from a file handle, # I thought it might make more sense to add some sort of computelength # property. If computelength is false, then the length simply isn't # computed. What do you think? # # Eryq's reply: I agree; for now, we can silently leave out the content-type. sub get_length { my $self = shift; my $attrs = $self->{Attrs}; my $is_multipart = ( $attrs->{'content-type'} =~ m{^multipart/}i ); my $enc = lc( $attrs->{'content-transfer-encoding'} || 'binary' ); my $length; if ( !$is_multipart && ( $enc eq "binary" ) ) { ### might figure it out cheap: if ( defined( $self->{Data} ) ) { ### it's in core $length = length( $self->{Data} ); } elsif ( defined( $self->{FH} ) ) { ### it's in a filehandle ### no-op: it's expensive, so don't bother } elsif ( defined( $self->{Path} ) ) { ### it's a simple file! $length = ( -s $self->{Path} ) if ( -e $self->{Path} ); } } $attrs->{'content-length'} = $length; return $length; } #------------------------------ #pod =item parts #pod #pod I #pod Return the parts of this entity, and this entity only. #pod Returns empty array if this entity has no parts. #pod #pod This is B recursive! Parts can have sub-parts; use #pod parts_DFS() to get everything. #pod #pod =cut sub parts { my $self = shift; @{ $self->{Parts} || [] }; } #------------------------------ #pod =item parts_DFS #pod #pod I #pod Return the list of all MIME::Lite objects included in the entity, #pod starting with the entity itself, in depth-first-search order. #pod If this object has no parts, it alone will be returned. #pod #pod =cut sub parts_DFS { my $self = shift; return ( $self, map { $_->parts_DFS } $self->parts ); } #------------------------------ #pod =item preamble [TEXT] #pod #pod I #pod Get/set the preamble string, assuming that this object has subparts. #pod Set it to undef for the default string. #pod #pod =cut sub preamble { my $self = shift; $self->{Preamble} = shift if @_; $self->{Preamble}; } #------------------------------ #pod =item replace TAG,VALUE #pod #pod I #pod Delete all occurrences of fields named TAG, and add a new #pod field with the given VALUE. TAG is converted to all-lowercase. #pod #pod B the special MIME fields (MIME-version, Content-*): #pod if you "replace" a MIME field, the replacement text will override #pod the I MIME attributes when it comes time to output that field. #pod So normally you use attr() to change MIME fields and add()/replace() to #pod change I fields: #pod #pod $msg->replace("Subject" => "Hi there!"); #pod #pod Giving VALUE as the I will effectively I that #pod field from being output. This is the correct way to suppress #pod the special MIME fields: #pod #pod $msg->replace("Content-disposition" => ""); #pod #pod Giving VALUE as I will just cause all explicit values #pod for TAG to be deleted, without having any new values added. #pod #pod I the name of this method comes from Mail::Header. #pod #pod =cut sub replace { my ( $self, $tag, $value ) = @_; $self->delete($tag); $self->add( $tag, $value ) if defined($value); } #------------------------------ #pod =item scrub #pod #pod I #pod B #pod Recursively goes through the "parts" tree of this message and tries #pod to find MIME attributes that can be removed. #pod With an array argument, removes exactly those attributes; e.g.: #pod #pod $msg->scrub(['content-disposition', 'content-length']); #pod #pod Is the same as recursively doing: #pod #pod $msg->replace('Content-disposition' => ''); #pod $msg->replace('Content-length' => ''); #pod #pod =cut sub scrub { my ( $self, @a ) = @_; my ($expl) = @a; local $QUIET = 1; ### Scrub me: if ( !@a ) { ### guess ### Scrub length always: $self->replace( 'content-length', '' ); ### Scrub disposition if no filename, or if content-type has same info: if ( !$self->_safe_attr('content-disposition.filename') || $self->_safe_attr('content-type.name') ) { $self->replace( 'content-disposition', '' ); } ### Scrub encoding if effectively unencoded: if ( $self->_safe_attr('content-transfer-encoding') =~ /^(7bit|8bit|binary)$/i ) { $self->replace( 'content-transfer-encoding', '' ); } ### Scrub charset if US-ASCII: if ( $self->_safe_attr('content-type.charset') =~ /^(us-ascii)/i ) { $self->attr( 'content-type.charset' => undef ); } ### TBD: this is not really right for message/digest: if ( ( keys %{ $self->{Attrs}{'content-type'} } == 1 ) and ( $self->_safe_attr('content-type') eq 'text/plain' ) ) { $self->replace( 'content-type', '' ); } } elsif ( $expl and ( ref($expl) eq 'ARRAY' ) ) { foreach ( @{$expl} ) { $self->replace( $_, '' ); } } ### Scrub my kids: foreach ( @{ $self->{Parts} } ) { $_->scrub(@a); } } #pod =back #pod #pod =cut #============================== #============================== #pod =head2 Setting/getting message data #pod #pod =over 4 #pod #pod =cut #------------------------------ #pod =item binmode [OVERRIDE] #pod #pod I #pod With no argument, returns whether or not it thinks that the data #pod (as given by the "Path" argument of C) should be read using #pod binmode() (for example, when C is invoked). #pod #pod The default behavior is that any content type other than #pod C or C is binmode'd; this should in general work fine. #pod #pod With a defined argument, this method sets an explicit "override" #pod value. An undefined argument unsets the override. #pod The new current value is returned. #pod #pod =cut sub binmode { my $self = shift; $self->{Binmode} = shift if (@_); ### argument? set override return ( defined( $self->{Binmode} ) ? $self->{Binmode} : ( $self->{Attrs}{"content-type"} !~ m{^(text|message)/}i ) ); } #------------------------------ #pod =item data [DATA] #pod #pod I #pod Get/set the literal DATA of the message. The DATA may be #pod either a scalar, or a reference to an array of scalars (which #pod will simply be joined). #pod #pod I setting the data causes the "content-length" attribute #pod to be recomputed (possibly to nothing). #pod #pod =cut sub data { my $self = shift; if (@_) { $self->{Data} = ( ( ref( $_[0] ) eq 'ARRAY' ) ? join( '', @{ $_[0] } ) : $_[0] ); $self->get_length; } $self->{Data}; } #------------------------------ #pod =item fh [FILEHANDLE] #pod #pod I #pod Get/set the FILEHANDLE which contains the message data. #pod #pod Takes a filehandle as an input and stores it in the object. #pod This routine is similar to path(); one important difference is that #pod no attempt is made to set the content length. #pod #pod =cut sub fh { my $self = shift; $self->{FH} = shift if @_; $self->{FH}; } #------------------------------ #pod =item path [PATH] #pod #pod I #pod Get/set the PATH to the message data. #pod #pod I setting the path recomputes any existing "content-length" field, #pod and re-sets the "filename" (to the last element of the path if it #pod looks like a simple path, and to nothing if not). #pod #pod =cut sub path { my $self = shift; if (@_) { ### Set the path, and invalidate the content length: $self->{Path} = shift; ### Re-set filename, extracting it from path if possible: my $filename; if ( $self->{Path} and ( $self->{Path} !~ /\|$/ ) ) { ### non-shell path: ( $filename = $self->{Path} ) =~ s/^filename($filename); ### Reset the length: $self->get_length; } $self->{Path}; } #------------------------------ #pod =item resetfh [FILEHANDLE] #pod #pod I #pod Set the current position of the filehandle back to the beginning. #pod Only applies if you used "FH" in build() or attach() for this message. #pod #pod Returns false if unable to reset the filehandle (since not all filehandles #pod are seekable). #pod #pod =cut #---- # Miko's note: With the Data and Path, the same data could theoretically # be reused. However, file handles need to be reset to be reused, # so I added this routine. # # Eryq reply: beware... not all filehandles are seekable (think about STDIN)! sub resetfh { my $self = shift; seek( $self->{FH}, 0, 0 ); } #------------------------------ #pod =item read_now #pod #pod I #pod Forces data from the path/filehandle (as specified by C) #pod to be read into core immediately, just as though you had given it #pod literally with the C keyword. #pod #pod Note that the in-core data will always be used if available. #pod #pod Be aware that everything is slurped into a giant scalar: you may not want #pod to use this if sending tar files! The benefit of I reading in the data #pod is that very large files can be handled by this module if left on disk #pod until the message is output via C or C. #pod #pod =cut sub read_now { my $self = shift; local $/ = undef; if ( $self->{FH} ) { ### data from a filehandle: my $chunk; my @chunks; CORE::binmode( $self->{FH} ) if $self->binmode; while ( read( $self->{FH}, $chunk, 1024 ) ) { push @chunks, $chunk; } $self->{Data} = join '', @chunks; } elsif ( $self->{Path} ) { ### data from a path: open SLURP, $self->{Path} or Carp::croak "open $self->{Path}: $!\n"; CORE::binmode(SLURP) if $self->binmode; $self->{Data} = ; ### sssssssssssssslurp... close SLURP; ### ...aaaaaaaaahhh! } } #------------------------------ #pod =item sign PARAMHASH #pod #pod I #pod Sign the message. This forces the message to be read into core, #pod after which the signature is appended to it. #pod #pod =over 4 #pod #pod =item Data #pod #pod As in C: the literal signature data. #pod Can be either a scalar or a ref to an array of scalars. #pod #pod =item Path #pod #pod As in C: the path to the file. #pod #pod =back #pod #pod If no arguments are given, the default is: #pod #pod Path => "$ENV{HOME}/.signature" #pod #pod The content-length is recomputed. #pod #pod =cut sub sign { my $self = shift; my %params = @_; ### Default: @_ or $params{Path} = "$ENV{HOME}/.signature"; ### Force message in-core: defined( $self->{Data} ) or $self->read_now; ### Load signature: my $sig; if ( !defined( $sig = $params{Data} ) ) { ### not given explicitly: local $/ = undef; open SIG, $params{Path} or Carp::croak "open sig $params{Path}: $!\n"; $sig = ; ### sssssssssssssslurp... close SIG; ### ...aaaaaaaaahhh! } $sig = join( '', @$sig ) if ( ref($sig) and ( ref($sig) eq 'ARRAY' ) ); ### Append, following Internet conventions: $self->{Data} .= "\n-- \n$sig"; ### Re-compute length: $self->get_length; 1; } #------------------------------ # # =item suggest_encoding CONTENTTYPE # # I # Based on the CONTENTTYPE, return a good suggested encoding. # C and C types have their bodies scanned line-by-line # for 8-bit characters and long lines; lack of either means that the # message is 7bit-ok. Other types are chosen independent of their body: # # Major type: 7bit ok? Suggested encoding: # ------------------------------------------------------------ # text yes 7bit # no quoted-printable # unknown binary # # message yes 7bit # no binary # unknown binary # # multipart n/a binary (in case some parts are not ok) # # (other) n/a base64 # #=cut sub suggest_encoding { my ( $self, $ctype ) = @_; $ctype = lc($ctype); ### Consult MIME::Types, maybe: if ($HaveMimeTypes) { ### Mappings contain [suffix,mimetype,encoding] my @mappings = MIME::Types::by_mediatype($ctype); if ( scalar(@mappings) ) { ### Just pick the first one: my ( $suffix, $mimetype, $encoding ) = @{ $mappings[0] }; if ( $encoding && $encoding =~ /^(base64|binary|[78]bit|quoted-printable)$/i ) { return lc($encoding); ### sanity check } } } ### If we got here, then MIME::Types was no help. ### Extract major type: my ($type) = split '/', $ctype; if ( ( $type eq 'text' ) || ( $type eq 'message' ) ) { ### scan message body? return 'binary'; } else { return ( $type eq 'multipart' ) ? 'binary' : 'base64'; } } #------------------------------ # # =item suggest_type PATH # # I # Suggest the content-type for this attached path. # We always fall back to "application/octet-stream" if no good guess # can be made, so don't use this if you don't mean it! # sub suggest_type { my ( $self, $path ) = @_; ### If there's no path, bail: $path or return 'application/octet-stream'; ### Consult MIME::Types, maybe: if ($HaveMimeTypes) { # Mappings contain [mimetype,encoding]: my ( $mimetype, $encoding ) = MIME::Types::by_suffix($path); return $mimetype if ( $mimetype && $mimetype =~ /^\S+\/\S+$/ ); ### sanity check } ### If we got here, then MIME::Types was no help. ### The correct thing to fall back to is the most-generic content type: return 'application/octet-stream'; } #------------------------------ #pod =item verify_data #pod #pod I #pod Verify that all "paths" to attached data exist, recursively. #pod It might be a good idea for you to do this before a print(), to #pod prevent accidental partial output if a file might be missing. #pod Raises exception if any path is not readable. #pod #pod =cut sub verify_data { my $self = shift; ### Verify self: my $path = $self->{Path}; if ( $path and ( $path !~ /\|$/ ) ) { ### non-shell path: $path =~ s/^{Parts} } ) { $part->verify_data } 1; } #pod =back #pod #pod =cut #============================== #============================== #pod =head2 Output #pod #pod =over 4 #pod #pod =cut #------------------------------ #pod =item print [OUTHANDLE] #pod #pod I #pod Print the message to the given output handle, or to the currently-selected #pod filehandle if none was given. #pod #pod All OUTHANDLE has to be is a filehandle (possibly a glob ref), or #pod any object that responds to a print() message. #pod #pod =cut sub print { my ( $self, $out ) = @_; ### Coerce into a printable output handle: $out = MIME::Lite::IO_Handle->wrap($out); ### Output head, separator, and body: $self->verify_data if $AUTO_VERIFY; ### prevents missing parts! $out->print( $self->header_as_string ); $out->print( "\n" ); $self->print_body($out); } #------------------------------ # # print_for_smtp # # Instance method, private. # Print, but filter out the topmost "Bcc" field. # This is because qmail apparently doesn't do this for us! # sub print_for_smtp { my ( $self, $out ) = @_; ### Coerce into a printable output handle: $out = MIME::Lite::IO_Handle->wrap($out); ### Create a safe head: my @fields = grep { $_->[0] ne 'bcc' } @{ $self->fields }; my $header = $self->fields_as_string( \@fields ); ### Output head, separator, and body: $out->print( $header ); $out->print( "\n" ); $self->print_body( $out, '1' ); } #------------------------------ #pod =item print_body [OUTHANDLE] [IS_SMTP] #pod #pod I #pod Print the body of a message to the given output handle, or to #pod the currently-selected filehandle if none was given. #pod #pod All OUTHANDLE has to be is a filehandle (possibly a glob ref), or #pod any object that responds to a print() message. #pod #pod B raised if unable to open any of the input files, #pod or if a part contains no data, or if an unsupported encoding is #pod encountered. #pod #pod IS_SMPT is a special option to handle SMTP mails a little more #pod intelligently than other send mechanisms may require. Specifically this #pod ensures that the last byte sent is NOT '\n' (octal \012) if the last two #pod bytes are not '\r\n' (\015\012) as this will cause some SMTP servers to #pod hang. #pod #pod =cut sub print_body { my ( $self, $out, $is_smtp ) = @_; my $attrs = $self->{Attrs}; my $sub_attrs = $self->{SubAttrs}; ### Coerce into a printable output handle: $out = MIME::Lite::IO_Handle->wrap($out); ### Output either the body or the parts. ### Notice that we key off of the content-type! We expect fewer ### accidents that way, since the syntax will always match the MIME type. my $type = $attrs->{'content-type'}; if ( $type =~ m{^multipart/}i ) { my $boundary = $sub_attrs->{'content-type'}{'boundary'}; ### Preamble: $out->print( defined( $self->{Preamble} ) ? $self->{Preamble} : "This is a multi-part message in MIME format.\n" ); ### Parts: my $part; foreach $part ( @{ $self->{Parts} } ) { $out->print("\n--$boundary\n"); $part->print($out); } ### Epilogue: $out->print("\n--$boundary--\n\n"); } elsif ( $type =~ m{^message/} ) { my @parts = @{ $self->{Parts} }; ### It's a toss-up; try both data and parts: if ( @parts == 0 ) { $self->print_simple_body( $out, $is_smtp ) } elsif ( @parts == 1 ) { $parts[0]->print($out) } else { Carp::croak "can't handle message with >1 part\n"; } } else { $self->print_simple_body( $out, $is_smtp ); } 1; } #------------------------------ # # print_simple_body [OUTHANDLE] # # I # Print the body of a simple singlepart message to the given # output handle, or to the currently-selected filehandle if none # was given. # # Note that if you want to print "the portion after # the header", you don't want this method: you want # L. # # All OUTHANDLE has to be is a filehandle (possibly a glob ref), or # any object that responds to a print() message. # # B raised if unable to open any of the input files, # or if a part contains no data, or if an unsupported encoding is # encountered. # sub print_simple_body { my ( $self, $out, $is_smtp ) = @_; my $attrs = $self->{Attrs}; ### Coerce into a printable output handle: $out = MIME::Lite::IO_Handle->wrap($out); ### Get content-transfer-encoding: my $encoding = uc( $attrs->{'content-transfer-encoding'} ); warn "M::L >>> Encoding using $encoding, is_smtp=" . ( $is_smtp || 0 ) . "\n" if $MIME::Lite::DEBUG; ### Notice that we don't just attempt to slurp the data in from a file: ### by processing files piecemeal, we still enable ourselves to prepare ### very large MIME messages... ### Is the data in-core? If so, blit it out... if ( defined( $self->{Data} ) ) { DATA: { local $_ = $encoding; /^BINARY$/ and do { $is_smtp and $self->{Data} =~ s/(?!\r)\n\z/\r/; $out->print( $self->{Data} ); last DATA; }; /^8BIT$/ and do { $out->print( encode_8bit( $self->{Data} ) ); last DATA; }; /^7BIT$/ and do { $out->print( encode_7bit( $self->{Data} ) ); last DATA; }; /^QUOTED-PRINTABLE$/ and do { ### UNTAINT since m//mg on tainted data loops forever: my ($untainted) = ( $self->{Data} =~ m/\A(.*)\Z/s ); ### Encode it line by line: while ( $untainted =~ m{^(.*[\r\n]*)}smg ) { ### have to do it line by line... my $line = $1; # copy to avoid weird bug; rt 39334 $out->print( encode_qp($line) ); } last DATA; }; /^BASE64/ and do { $out->print( encode_base64( $self->{Data} ) ); last DATA; }; Carp::croak "unsupported encoding: `$_'\n"; } } ### Else, is the data in a file? If so, output piecemeal... ### Miko's note: this routine pretty much works the same with a path ### or a filehandle. the only difference in behaviour is that it does ### not attempt to open anything if it already has a filehandle elsif ( defined( $self->{Path} ) || defined( $self->{FH} ) ) { no strict 'refs'; ### in case FH is not an object my $DATA; ### Open file if necessary: if ( defined( $self->{Path} ) ) { $DATA = new FileHandle || Carp::croak "can't get new filehandle\n"; $DATA->open("$self->{Path}") or Carp::croak "open $self->{Path}: $!\n"; } else { $DATA = $self->{FH}; } CORE::binmode($DATA) if $self->binmode; ### Encode piece by piece: PATH: { local $_ = $encoding; /^BINARY$/ and do { my $last = ""; while ( read( $DATA, $_, 2048 ) ) { $out->print($last) if length $last; $last = $_; } if ( length $last ) { $is_smtp and $last =~ s/(?!\r)\n\z/\r/; $out->print($last); } last PATH; }; /^8BIT$/ and do { $out->print( encode_8bit($_) ) while (<$DATA>); last PATH; }; /^7BIT$/ and do { $out->print( encode_7bit($_) ) while (<$DATA>); last PATH; }; /^QUOTED-PRINTABLE$/ and do { $out->print( encode_qp($_) ) while (<$DATA>); last PATH; }; /^BASE64$/ and do { $out->print( encode_base64($_) ) while ( read( $DATA, $_, 45 ) ); last PATH; }; Carp::croak "unsupported encoding: `$_'\n"; } ### Close file: close $DATA if defined( $self->{Path} ); } else { Carp::croak "no data in this part\n"; } 1; } #------------------------------ #pod =item print_header [OUTHANDLE] #pod #pod I #pod Print the header of the message to the given output handle, #pod or to the currently-selected filehandle if none was given. #pod #pod All OUTHANDLE has to be is a filehandle (possibly a glob ref), or #pod any object that responds to a print() message. #pod #pod =cut sub print_header { my ( $self, $out ) = @_; ### Coerce into a printable output handle: $out = MIME::Lite::IO_Handle->wrap($out); ### Output the header: $out->print( $self->header_as_string ); 1; } #------------------------------ #pod =item as_string #pod #pod I #pod Return the entire message as a string, with a header and an encoded body. #pod #pod =cut sub as_string { my $self = shift; my $buf = ""; my $io = ( wrap MIME::Lite::IO_Scalar \$buf); $self->print($io); return $buf; } *stringify = \&as_string; ### backwards compatibility *stringify = \&as_string; ### ...twice to avoid warnings :) #------------------------------ #pod =item body_as_string #pod #pod I #pod Return the encoded body as a string. #pod This is the portion after the header and the blank line. #pod #pod I actually prepares the body by "printing" to a scalar. #pod Proof that you can hand the C methods any blessed object #pod that responds to a C message. #pod #pod =cut sub body_as_string { my $self = shift; my $buf = ""; my $io = ( wrap MIME::Lite::IO_Scalar \$buf); $self->print_body($io); return $buf; } *stringify_body = \&body_as_string; ### backwards compatibility *stringify_body = \&body_as_string; ### ...twice to avoid warnings :) #------------------------------ # # fields_as_string FIELDS # # PRIVATE! Return a stringified version of the given header # fields, where FIELDS is an arrayref like that returned by fields(). # sub fields_as_string { my ( $self, $fields ) = @_; my $out = ""; foreach (@$fields) { my ( $tag, $value ) = @$_; next if ( $value eq '' ); ### skip empties $tag =~ s/\b([a-z])/uc($1)/ge; ### make pretty $tag =~ s/^mime-/MIME-/i; ### even prettier if (length($value) > 72 && $value !~ /\n/) { $value = fold_header($value); } $out .= "$tag: $value\n"; } return $out; } sub fold_header { local $_ = shift; my $Eol = shift || "\n"; # Undo any existing folding s/\r?\n(\s)/$1/gms; # Pulled partly from Mail::Message::Field my $Folded = ''; while (1) { if (length($_) < 72) { $Folded .= $_; last; } # Prefer breaking at ; or , s/^(.{18,72}[;,])([ \t])// || # Otherwise any space is fine s/^(.{18,72})([ \t])// || # Hmmm, longer than 72 chars, find up to next whitespace s/^(.{72,}?)([ \t])// || # Ok, better just get everything s/^(.*)()//; $Folded .= $1 . $Eol . $2; } # Strip the trailing eol $Folded =~ s/${Eol}$//; return $Folded; } #------------------------------ #pod =item header_as_string #pod #pod I #pod Return the header as a string. #pod #pod =cut sub header_as_string { my $self = shift; $self->fields_as_string( $self->fields ); } *stringify_header = \&header_as_string; ### backwards compatibility *stringify_header = \&header_as_string; ### ...twice to avoid warnings :) #pod =back #pod #pod =cut #============================== #============================== #pod =head2 Sending #pod #pod =over 4 #pod #pod =cut #------------------------------ #pod =item send #pod #pod =item send HOW, HOWARGS... #pod #pod I #pod This is the principal method for sending mail, and for configuring #pod how mail will be sent. #pod #pod I with a HOW argument and optional HOWARGS, it sets #pod the default sending mechanism that the no-argument instance method #pod will use. The HOW is a facility name (B), #pod and the HOWARGS is interpreted by the facility. #pod The class method returns the previous HOW and HOWARGS as an array. #pod #pod MIME::Lite->send('sendmail', "d:\\programs\\sendmail.exe"); #pod ... #pod $msg = MIME::Lite->new(...); #pod $msg->send; #pod #pod I #pod (a HOW argument and optional HOWARGS), sends the message in the #pod requested manner; e.g.: #pod #pod $msg->send('sendmail', "d:\\programs\\sendmail.exe"); #pod #pod I sends the #pod message by the default mechanism set up by the class method. #pod Returns whatever the mail-handling routine returns: this #pod should be true on success, false/exception on error: #pod #pod $msg = MIME::Lite->new(From=>...); #pod $msg->send || die "you DON'T have mail!"; #pod #pod On Unix systems (or rather non-Win32 systems), the default #pod setting is equivalent to: #pod #pod MIME::Lite->send("sendmail", "/usr/lib/sendmail -t -oi -oem"); #pod #pod On Win32 systems the default setting is equivalent to: #pod #pod MIME::Lite->send("smtp"); #pod #pod The assumption is that on Win32 your site/lib/Net/libnet.cfg #pod file will be preconfigured to use the appropriate SMTP #pod server. See below for configuring for authentication. #pod #pod There are three facilities: #pod #pod =over 4 #pod #pod =item "sendmail", ARGS... #pod #pod Send a message by piping it into the "sendmail" command. #pod Uses the L method, giving it the ARGS. #pod This usage implements (and deprecates) the C method. #pod #pod =item "smtp", [HOSTNAME, [NAMEDPARMS] ] #pod #pod Send a message by SMTP, using optional HOSTNAME as SMTP-sending host. #pod L will be required. Uses the L #pod method. Any additional arguments passed in will also be passed through to #pod send_by_smtp. This is useful for things like mail servers requiring #pod authentication where you can say something like the following #pod #pod MIME::Lite->send('smtp', $host, AuthUser=>$user, AuthPass=>$pass); #pod #pod which will configure things so future uses of #pod #pod $msg->send(); #pod #pod do the right thing. #pod #pod =item "sub", \&SUBREF, ARGS... #pod #pod Sends a message MSG by invoking the subroutine SUBREF of your choosing, #pod with MSG as the first argument, and ARGS following. #pod #pod =back #pod #pod I let's say you're on an OS which lacks the usual Unix #pod "sendmail" facility, but you've installed something a lot like it, and #pod you need to configure your Perl script to use this "sendmail.exe" program. #pod Do this following in your script's setup: #pod #pod MIME::Lite->send('sendmail', "d:\\programs\\sendmail.exe"); #pod #pod Then, whenever you need to send a message $msg, just say: #pod #pod $msg->send; #pod #pod That's it. Now, if you ever move your script to a Unix box, all you #pod need to do is change that line in the setup and you're done. #pod All of your $msg-Esend invocations will work as expected. #pod #pod After sending, the method last_send_successful() can be used to determine #pod if the send was successful or not. #pod #pod =cut sub send { my $self = shift; my $meth = shift; if ( ref($self) ) { ### instance method: my ( $method, @args ); if (@_) { ### args; use them just this once $method = 'send_by_' . $meth; @args = @_; } else { ### no args; use defaults $method = "send_by_$Sender"; @args = @{ $SenderArgs{$Sender} || [] }; } $self->verify_data if $AUTO_VERIFY; ### prevents missing parts! Carp::croak "Unknown send method '$meth'" unless $self->can($method); return $self->$method(@args); } else { ### class method: if (@_) { my @old = ( $Sender, @{ $SenderArgs{$Sender} } ); $Sender = $meth; $SenderArgs{$Sender} = [@_]; ### remaining args return @old; } else { Carp::croak "class method send must have HOW... arguments\n"; } } } #------------------------------ #pod =item send_by_sendmail SENDMAILCMD #pod #pod =item send_by_sendmail PARAM=>VALUE, ARRAY, HASH... #pod #pod I #pod Send message via an external "sendmail" program #pod (this will probably only work out-of-the-box on Unix systems). #pod #pod Returns true on success, false or exception on error. #pod #pod You can specify the program and all its arguments by giving a single #pod string, SENDMAILCMD. Nothing fancy is done; the message is simply #pod piped in. #pod #pod However, if your needs are a little more advanced, you can specify #pod zero or more of the following PARAM/VALUE pairs (or a reference to hash #pod or array of such arguments as well as any combination thereof); a #pod Unix-style, taint-safe "sendmail" command will be constructed for you: #pod #pod =over 4 #pod #pod =item Sendmail #pod #pod Full path to the program to use. #pod Default is "/usr/lib/sendmail". #pod #pod =item BaseArgs #pod #pod Ref to the basic array of arguments we start with. #pod Default is C<["-t", "-oi", "-oem"]>. #pod #pod =item SetSender #pod #pod Unless this is I given as false, we attempt to automatically #pod set the C<-f> argument to the first address that can be extracted from #pod the "From:" field of the message (if there is one). #pod #pod I #pod Suppose we did I use C<-f>, and you gave an explicit "From:" #pod field in your message: in this case, the sendmail "envelope" would #pod indicate the I user your process was running under, as a way #pod of preventing mail forgery. Using the C<-f> switch causes the sender #pod to be set in the envelope as well. #pod #pod I #pod If sendmail doesn't regard you as a "trusted" user, it will permit #pod the C<-f> but also add an "X-Authentication-Warning" header to the message #pod to indicate a forged envelope. To avoid this, you can either #pod (1) have SetSender be false, or #pod (2) make yourself a trusted user by adding a C configuration #pod command to your I file #pod (e.g.: C if the script is running as user "eryq"). #pod #pod =item FromSender #pod #pod If defined, this is identical to setting SetSender to true, #pod except that instead of looking at the "From:" field we use #pod the address given by this option. #pod Thus: #pod #pod FromSender => 'me@myhost.com' #pod #pod =back #pod #pod After sending, the method last_send_successful() can be used to determine #pod if the send was successful or not. #pod #pod =cut sub _unfold_stupid_params { my $self = shift; my %p; STUPID_PARAM: for (my $i = 0; $i < @_; $i++) { ## no critic Loop my $item = $_[$i]; if (not ref $item) { $p{ $item } = $_[ ++$i ]; } elsif (UNIVERSAL::isa($item, 'HASH')) { $p{ $_ } = $item->{ $_ } for keys %$item; } elsif (UNIVERSAL::isa($item, 'ARRAY')) { for (my $j = 0; $j < @$item; $j += 2) { $p{ $item->[ $j ] } = $item->[ $j + 1 ]; } } } return %p; } sub send_by_sendmail { my $self = shift; my $return; if ( @_ == 1 and !ref $_[0] ) { ### Use the given command... my $sendmailcmd = shift @_; Carp::croak "No sendmail command available" unless $sendmailcmd; ### Do it: local *SENDMAIL; open SENDMAIL, "|$sendmailcmd" or Carp::croak "open |$sendmailcmd: $!\n"; $self->print( \*SENDMAIL ); close SENDMAIL; $return = ( ( $? >> 8 ) ? undef: 1 ); } else { ### Build the command... my %p = $self->_unfold_stupid_params(@_); $p{Sendmail} = $SENDMAIL unless defined $p{Sendmail}; ### Start with the command and basic args: my @cmd = ( $p{Sendmail}, @{ $p{BaseArgs} || [ '-t', '-oi', '-oem' ] } ); # SetSender default is true $p{SetSender} = 1 unless defined $p{SetSender}; ### See if we are forcibly setting the sender: $p{SetSender} ||= defined( $p{FromSender} ); ### Add the -f argument, unless we're explicitly told NOT to: if ( $p{SetSender} ) { my $from = $p{FromSender} || ( $self->get('From') )[0]; if ($from) { my ($from_addr) = extract_only_addrs($from); push @cmd, "-f$from_addr" if $from_addr; } } ### Open the command in a taint-safe fashion: my $pid = open SENDMAIL, "|-"; defined($pid) or die "open of pipe failed: $!\n"; if ( !$pid ) { ### child exec(@cmd) or die "can't exec $p{Sendmail}: $!\n"; ### NOTREACHED } else { ### parent $self->print( \*SENDMAIL ); close SENDMAIL || die "error closing $p{Sendmail}: $! (exit $?)\n"; $return = 1; } } return $self->{last_send_successful} = $return; } #------------------------------ #pod =item send_by_smtp HOST, ARGS... #pod #pod =item send_by_smtp REF, HOST, ARGS #pod #pod I #pod Send message via SMTP, using Net::SMTP -- which will be required for this #pod feature. #pod #pod HOST is the name of SMTP server to connect to, or undef to have #pod L use the defaults in Libnet.cfg. #pod #pod ARGS are a list of key value pairs which may be selected from the list #pod below. Many of these are just passed through to specific #pod L commands and you should review that module for #pod details. #pod #pod Please see L #pod #pod =over 4 #pod #pod =item Hello #pod #pod =item LocalAddr #pod #pod =item LocalPort #pod #pod =item Timeout #pod #pod =item Port #pod #pod =item ExactAddresses #pod #pod =item Debug #pod #pod See L for details. #pod #pod =item Size #pod #pod =item Return #pod #pod =item Bits #pod #pod =item Transaction #pod #pod =item Envelope #pod #pod See L for details. #pod #pod =item SkipBad #pod #pod If true doesn't throw an error when multiple email addresses are provided #pod and some are not valid. See L #pod for details. #pod #pod =item AuthUser #pod #pod Authenticate with L using this username. #pod #pod =item AuthPass #pod #pod Authenticate with L using this password. #pod #pod =item NoAuth #pod #pod Normally if AuthUser and AuthPass are defined MIME::Lite will attempt to #pod use them with the L command to #pod authenticate the connection, however if this value is true then no #pod authentication occurs. #pod #pod =item To #pod #pod Sets the addresses to send to. Can be a string or a reference to an #pod array of strings. Normally this is extracted from the To: (and Cc: and #pod Bcc: fields if $AUTO_CC is true). #pod #pod This value overrides that. #pod #pod =item From #pod #pod Sets the email address to send from. Normally this value is extracted #pod from the Return-Path: or From: field of the mail itself (in that order). #pod #pod This value overrides that. #pod #pod =back #pod #pod I #pod True on success, croaks with an error message on failure. #pod #pod After sending, the method last_send_successful() can be used to determine #pod if the send was successful or not. #pod #pod =cut # Derived from work by Andrew McRae. Version 0.2 anm 09Sep97 # Copyright 1997 Optimation New Zealand Ltd. # May be modified/redistributed under the same terms as Perl. # external opts my @_mail_opts = qw( Size Return Bits Transaction Envelope ); my @_recip_opts = qw( SkipBad Notify ); my @_net_smtp_opts = qw( Hello LocalAddr LocalPort Timeout AuthUser AuthPass SSL Port ExactAddresses Debug ); # internal: qw( NoAuth AuthUser AuthPass To From Host); sub __opts { my $args=shift; return map { exists $args->{$_} ? ( $_ => $args->{$_} ) : () } @_; } sub send_by_smtp { require Net::SMTP; my ($self,$hostname,%args) = @_; # We may need the "From:" and "To:" headers to pass to the # SMTP mailer also. $self->{last_send_successful}=0; my @hdr_to = extract_only_addrs( scalar $self->get('To') ); if ($AUTO_CC) { foreach my $field (qw(Cc Bcc)) { push @hdr_to, extract_only_addrs($_) for $self->get($field); } } Carp::croak "send_by_smtp: nobody to send to for host '$hostname'?!\n" unless @hdr_to; $args{To} ||= \@hdr_to; $args{From} ||= extract_only_addrs( scalar $self->get('Return-Path') ); $args{From} ||= extract_only_addrs( scalar $self->get('From') ) ; # Create SMTP client. # MIME::Lite::SMTP is just a wrapper giving a print method # to the SMTP object. my %opts = __opts(\%args, @_net_smtp_opts); my $smtp = MIME::Lite::SMTP->new( $hostname, %opts ) or Carp::croak "SMTP Failed to connect to mail server: $!\n"; # Possibly authenticate if ( defined $args{AuthUser} and defined $args{AuthPass} and !$args{NoAuth} ) { if ($smtp->supports('AUTH',500,["Command unknown: 'AUTH'"])) { $smtp->auth( $args{AuthUser}, $args{AuthPass} ) or die "SMTP auth() command failed: $!\n" . $smtp->message . "\n"; } else { die "SMTP auth() command not supported on $hostname\n"; } } # Send the mail command %opts = __opts( \%args, @_mail_opts); $smtp->mail( $args{From}, %opts ? \%opts : () ) or die "SMTP mail() command failed: $!\n" . $smtp->message . "\n"; # Send the recipients command %opts = __opts( \%args, @_recip_opts); $smtp->recipient( @{ $args{To} }, %opts ? \%opts : () ) or die "SMTP recipient() command failed: $!\n" . $smtp->message . "\n"; # Send the data $smtp->data() or die "SMTP data() command failed: $!\n" . $smtp->message . "\n"; $self->print_for_smtp($smtp); # Finish the mail $smtp->dataend() or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" . "Last server message was:" . $smtp->message . "This probably represents a problem with newline encoding "; # terminate the session $smtp->quit; return $self->{last_send_successful} = 1; } #pod =item send_by_testfile FILENAME #pod #pod I #pod Print message to a file (namely FILENAME), which will default to #pod mailer.testfile #pod If file exists, message will be appended. #pod #pod =cut sub send_by_testfile { my $self = shift; ### Use the default filename... my $filename = 'mailer.testfile'; if ( @_ == 1 and !ref $_[0] ) { ### Use the given filename if given... $filename = shift @_; Carp::croak "no filename given to send_by_testfile" unless $filename; } ### Do it: local *FILE; open FILE, ">> $filename" or Carp::croak "open $filename: $!\n"; $self->print( \*FILE ); close FILE; my $return = ( ( $? >> 8 ) ? undef: 1 ); return $self->{last_send_successful} = $return; } #pod =item last_send_successful #pod #pod This method will return TRUE if the last send() or send_by_XXX() method call was #pod successful. It will return defined but false if it was not successful, and undefined #pod if the object had not been used to send yet. #pod #pod =cut sub last_send_successful { my $self = shift; return $self->{last_send_successful}; } ### Provided by Andrew McRae. Version 0.2 anm 09Sep97 ### Copyright 1997 Optimation New Zealand Ltd. ### May be modified/redistributed under the same terms as Perl. ### Aditional changes by Yves. ### Until 3.01_03 this was send_by_smtp() sub send_by_smtp_simple { my ( $self, @args ) = @_; $self->{last_send_successful} = 0; ### We need the "From:" and "To:" headers to pass to the SMTP mailer: my $hdr = $self->fields(); my $from_header = $self->get('From'); my ($from) = extract_only_addrs($from_header); warn "M::L>>> $from_header => $from" if $MIME::Lite::DEBUG; my $to = $self->get('To'); ### Sanity check: defined($to) or Carp::croak "send_by_smtp: missing 'To:' address\n"; ### Get the destinations as a simple array of addresses: my @to_all = extract_only_addrs($to); if ($AUTO_CC) { foreach my $field (qw(Cc Bcc)) { my $value = $self->get($field); push @to_all, extract_only_addrs($value) if defined($value); } } ### Create SMTP client: require Net::SMTP; my $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to connect to mail server: $!\n"); $smtp->mail($from) or Carp::croak( "SMTP MAIL command failed: $!\n" . $smtp->message . "\n" ); $smtp->to(@to_all) or Carp::croak( "SMTP RCPT command failed: $!\n" . $smtp->message . "\n" ); $smtp->data() or Carp::croak( "SMTP DATA command failed: $!\n" . $smtp->message . "\n" ); ### MIME::Lite can print() to anything with a print() method: $self->print_for_smtp($smtp); $smtp->dataend() or Carp::croak( "Net::CMD (Net::SMTP) DATAEND command failed.\n" . "Last server message was:" . $smtp->message . "This probably represents a problem with newline encoding " ); $smtp->quit; $self->{last_send_successful} = 1; 1; } #------------------------------ # # send_by_sub [\&SUBREF, [ARGS...]] # # I # Send the message via an anonymous subroutine. # sub send_by_sub { my ( $self, $subref, @args ) = @_; $self->{last_send_successful} = &$subref( $self, @args ); } #------------------------------ #pod =item sendmail COMMAND... #pod #pod I #pod Declare the sender to be "sendmail", and set up the "sendmail" command. #pod I #pod #pod =cut sub sendmail { my $self = shift; $self->send( 'sendmail', join( ' ', @_ ) ); } #pod =back #pod #pod =cut #============================== #============================== #pod =head2 Miscellaneous #pod #pod =over 4 #pod #pod =cut #------------------------------ #pod =item quiet ONOFF #pod #pod I #pod Suppress/unsuppress all warnings coming from this module. #pod #pod MIME::Lite->quiet(1); ### I know what I'm doing #pod #pod I recommend that you include that comment as well. And while #pod you type it, say it out loud: if it doesn't feel right, then maybe #pod you should reconsider the whole line. C<;-)> #pod #pod =cut sub quiet { my $class = shift; $QUIET = shift if @_; $QUIET; } #pod =back #pod #pod =cut #============================================================ package MIME::Lite::SMTP 3.038; #============================================================ # This class just adds a print() method to Net::SMTP. # Notice that we don't use/require it until it's needed! use strict; use vars qw( @ISA ); @ISA = qw(Net::SMTP); # some of the below is borrowed from Data::Dumper my %esc = ( "\a" => "\\a", "\b" => "\\b", "\t" => "\\t", "\n" => "\\n", "\f" => "\\f", "\r" => "\\r", "\e" => "\\e", ); sub _hexify { local $_ = shift; my @split = m/(.{1,16})/gs; foreach my $split (@split) { ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc{$1}/sg; $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; print STDERR "M::L >>> $split : $txt\n"; } } sub print { my $smtp = shift; $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); $smtp->datasend(@_) or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed.\n" . "Last server message was:" . $smtp->message . "This probably represents a problem with newline encoding " ); } #============================================================ package MIME::Lite::IO_Handle 3.038; #============================================================ ### Wrap a non-object filehandle inside a blessed, printable interface: ### Does nothing if the given $fh is already a blessed object. sub wrap { my ( $class, $fh ) = @_; no strict 'refs'; ### Get default, if necessary: $fh or $fh = select; ### no filehandle means selected one ref($fh) or $fh = \*$fh; ### scalar becomes a globref ### Stop right away if already a printable object: return $fh if ( ref($fh) and ( ref($fh) ne 'GLOB' ) ); ### Get and return a printable interface: bless \$fh, $class; ### wrap it in a printable interface } ### Print: sub print { my $self = shift; print {$$self} @_; } #============================================================ package MIME::Lite::IO_Scalar 3.038; #============================================================ ### Wrap a scalar inside a blessed, printable interface: sub wrap { my ( $class, $scalarref ) = @_; defined($scalarref) or $scalarref = \""; bless $scalarref, $class; } ### Print: sub print { ${$_[0]} .= join( '', @_[1..$#_] ); 1; } #============================================================ package MIME::Lite::IO_ScalarArray 3.038; #============================================================ ### Wrap an array inside a blessed, printable interface: sub wrap { my ( $class, $arrayref ) = @_; defined($arrayref) or $arrayref = []; bless $arrayref, $class; } ### Print: sub print { my $self = shift; push @$self, @_; 1; } 1; =pod =encoding UTF-8 =head1 NAME MIME::Lite - low-calorie MIME generator =head1 VERSION version 3.038 =head1 WAIT! MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else. =head1 SYNOPSIS Create and send using the default send method for your OS a single-part message: use MIME::Lite; ### Create a new single-part message, to send a GIF file: $msg = MIME::Lite->new( From => 'me@myhost.com', To => 'you@yourhost.com', Cc => 'some@other.com, some@more.com', Subject => 'Helloooooo, nurse!', Type => 'image/gif', Encoding => 'base64', Path => 'hellonurse.gif' ); $msg->send; # send via default Create a multipart message (i.e., one with attachments) and send it via SMTP ### Create a new multipart message: $msg = MIME::Lite->new( From => 'me@myhost.com', To => 'you@yourhost.com', Cc => 'some@other.com, some@more.com', Subject => 'A message with 2 parts...', Type => 'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach( Type => 'TEXT', Data => "Here's the GIF file you wanted" ); $msg->attach( Type => 'image/gif', Path => 'aaa000123.gif', Filename => 'logo.gif', Disposition => 'attachment' ); ### use Net::SMTP to do the sending $msg->send('smtp','some.host', Debug=>1 ); Output a message: ### Format as a string: $str = $msg->as_string; ### Print to a filehandle (say, a "sendmail" stream): $msg->print(\*SENDMAIL); Send a message: ### Send in the "best" way (the default is to use "sendmail"): $msg->send; ### Send a specific way: $msg->send('type',@args); Specify default send method: MIME::Lite->send('smtp','some.host',Debug=>0); with authentication MIME::Lite->send('smtp','some.host', AuthUser=>$user, AuthPass=>$pass); using SSL MIME::Lite->send('smtp','some.host', SSL => 1, Port => 465 ); =head1 DESCRIPTION In the never-ending quest for great taste with fewer calories, we proudly present: I. MIME::Lite is intended as a simple, standalone module for generating (not parsing!) MIME messages... specifically, it allows you to output a simple, decent single- or multi-part message with text or binary attachments. It does not require that you have the Mail:: or MIME:: modules installed, but will work with them if they are. You can specify each message part as either the literal data itself (in a scalar or array), or as a string which can be given to open() to get a readable filehandle (e.g., "new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'Helloooooo, nurse!', Data =>"How's it goin', eh?" ); =head2 Create a simple message containing just an image $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'Helloooooo, nurse!', Type =>'image/gif', Encoding =>'base64', Path =>'hellonurse.gif' ); =head2 Create a multipart message ### Create the multipart "container": $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed' ); ### Add the text message part: ### (Note that "attach" has same arguments as "new"): $msg->attach( Type =>'TEXT', Data =>"Here's the GIF file you wanted" ); ### Add the image part: $msg->attach( Type =>'image/gif', Path =>'aaa000123.gif', Filename =>'logo.gif', Disposition => 'attachment' ); =head2 Attach a GIF to a text message This will create a multipart message exactly as above, but using the "attach to singlepart" hack: ### Start with a simple text message: $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'TEXT', Data =>"Here's the GIF file you wanted" ); ### Attach a part... the make the message a multipart automatically: $msg->attach( Type =>'image/gif', Path =>'aaa000123.gif', Filename =>'logo.gif' ); =head2 Attach a pre-prepared part to a message ### Create a standalone part: $part = MIME::Lite->new( Top => 0, Type =>'text/html', Data =>'

Hello

', ); $part->attr('content-type.charset' => 'UTF-8'); $part->add('X-Comment' => 'A message for you'); ### Attach it to any message: $msg->attach($part); =head2 Print a message to a filehandle ### Write it to a filehandle: $msg->print(\*STDOUT); ### Write just the header: $msg->print_header(\*STDOUT); ### Write just the encoded body: $msg->print_body(\*STDOUT); =head2 Print a message into a string ### Get entire message as a string: $str = $msg->as_string; ### Get just the header: $str = $msg->header_as_string; ### Get just the encoded body: $str = $msg->body_as_string; =head2 Send a message ### Send in the "best" way (the default is to use "sendmail"): $msg->send; =head2 Send an HTML document... with images included! $msg = MIME::Lite->new( To =>'you@yourhost.com', Subject =>'HTML with in-line images!', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ Here's my image: }, ); $msg->attach( Type => 'image/gif', Id => 'myimage.gif', Path => '/path/to/somefile.gif', ); $msg->send(); =head2 Change how messages are sent ### Do something like this in your 'main': if ($I_DONT_HAVE_SENDMAIL) { MIME::Lite->send('smtp', $host, Timeout=>60, AuthUser=>$user, AuthPass=>$pass); } ### Now this will do the right thing: $msg->send; ### will now use Net::SMTP as shown above =head1 PUBLIC INTERFACE =head2 Global configuration To alter the way the entire module behaves, you have the following methods/options: =over 4 =item MIME::Lite->field_order() When used as a L, this changes the default order in which headers are output for I messages. However, please consider using the instance method variant instead, so you won't stomp on other message senders in the same application. =item MIME::Lite->quiet() This L can be used to suppress/unsuppress all warnings coming from this module. =item MIME::Lite->send() When used as a L, this can be used to specify a different default mechanism for sending message. The initial default is: MIME::Lite->send("sendmail", "/usr/lib/sendmail -t -oi -oem"); However, you should consider the similar but smarter and taint-safe variant: MIME::Lite->send("sendmail"); Or, for non-Unix users: MIME::Lite->send("smtp"); =item $MIME::Lite::AUTO_CC If true, automatically send to the Cc/Bcc addresses for send_by_smtp(). Default is B. =item $MIME::Lite::AUTO_CONTENT_TYPE If true, try to automatically choose the content type from the file name in C/C. In other words, setting this true changes the default C from C<"TEXT"> to C<"AUTO">. Default is B, since we must maintain backwards-compatibility with prior behavior. B consider keeping it false, and just using Type 'AUTO' when you build() or attach(). =item $MIME::Lite::AUTO_ENCODE If true, automatically choose the encoding from the content type. Default is B. =item $MIME::Lite::AUTO_VERIFY If true, check paths to attachments right before printing, raising an exception if any path is unreadable. Default is B. =item $MIME::Lite::PARANOID If true, we won't attempt to use MIME::Base64, MIME::QuotedPrint, or MIME::Types, even if they're available. Default is B. Please consider keeping it false, and trusting these other packages to do the right thing. =back =head2 Construction =over 4 =item new [PARAMHASH] I Create a new message object. If any arguments are given, they are passed into C; otherwise, just the empty object is created. =item attach PART =item attach PARAMHASH... I Add a new part to this message, and return the new part. If you supply a single PART argument, it will be regarded as a MIME::Lite object to be attached. Otherwise, this method assumes that you are giving in the pairs of a PARAMHASH which will be sent into C to create the new part. One of the possibly-quite-useful hacks thrown into this is the "attach-to-singlepart" hack: if you attempt to attach a part (let's call it "part 1") to a message that doesn't have a content-type of "multipart" or "message", the following happens: =over 4 =item * A new part (call it "part 0") is made. =item * The MIME attributes and data (but I the other headers) are cut from the "self" message, and pasted into "part 0". =item * The "self" is turned into a "multipart/mixed" message. =item * The new "part 0" is added to the "self", and I "part 1" is added. =back One of the nice side-effects is that you can create a text message and then add zero or more attachments to it, much in the same way that a user agent like Netscape allows you to do. =item build [PARAMHASH] I Create (or initialize) a MIME message object. Normally, you'll use the following keys in PARAMHASH: * Data, FH, or Path (either one of these, or none if multipart) * Type (e.g., "image/jpeg") * From, To, and Subject (if this is the "top level" of a message) The PARAMHASH can contain the following keys: =over 4 =item (fieldname) Any field you want placed in the message header, taken from the standard list of header fields (you don't need to worry about case): Approved Encrypted Received Sender Bcc From References Subject Cc Keywords Reply-To To Comments Message-ID Resent-* X-* Content-* MIME-Version Return-Path Date Organization To give experienced users some veto power, these fields will be set I the ones I set... so be careful: I (like C) unless you know what you're doing! To specify a fieldname that's I in the above list, even one that's identical to an option below, just give it with a trailing C<":">, like C<"My-field:">. When in doubt, that I signals a mail field (and it sort of looks like one too). =item Data I The actual message data. This may be a scalar or a ref to an array of strings; if the latter, the message consists of a simple concatenation of all the strings in the array. =item Datestamp I If given true (or omitted), we force the creation of a C field stamped with the current date/time if this is a top-level message. You may want this if using L. If you don't want this to be done, either provide your own Date or explicitly set this to false. =item Disposition I The content disposition, C<"inline"> or C<"attachment">. The default is C<"inline">. =item Encoding I The content transfer encoding that should be used to encode your data: Use encoding: | If your message contains: ------------------------------------------------------------ 7bit | Only 7-bit text, all lines <1000 characters 8bit | 8-bit text, all lines <1000 characters quoted-printable | 8-bit text or long lines (more reliable than "8bit") base64 | Largely non-textual data: a GIF, a tar file, etc. The default is taken from the Type; generally it is "binary" (no encoding) for text/*, message/*, and multipart/*, and "base64" for everything else. A value of C<"binary"> is generally I suitable for sending anything but ASCII text files with lines under 1000 characters, so consider using one of the other values instead. In the case of "7bit"/"8bit", long lines are automatically chopped to legal length; in the case of "7bit", all 8-bit characters are automatically I. This may not be what you want, so pick your encoding well! For more info, see L<"A MIME PRIMER">. =item FH I Filehandle containing the data, opened for reading. See "ReadNow" also. =item Filename I The name of the attachment. You can use this to supply a recommended filename for the end-user who is saving the attachment to disk. You only need this if the filename at the end of the "Path" is inadequate, or if you're using "Data" instead of "Path". You should I put path information in here (e.g., no "/" or "\" or ":" characters should be used). =item Id I Same as setting "content-id". =item Length I Set the content length explicitly. Normally, this header is automatically computed, but only under certain circumstances (see L<"Benign limitations">). =item Path I Path to a file containing the data... actually, it can be any open()able expression. If it looks like a path, the last element will automatically be treated as the filename. See "ReadNow" also. =item ReadNow I If true, will open the path and slurp the contents into core now. This is useful if the Path points to a command and you don't want to run the command over and over if outputting the message several times. B raised if the open fails. =item Top I If defined, indicates whether or not this is a "top-level" MIME message. The parts of a multipart message are I top-level. Default is true. =item Type I The MIME content type, or one of these special values (case-sensitive): "TEXT" means "text/plain" "BINARY" means "application/octet-stream" "AUTO" means attempt to guess from the filename, falling back to 'application/octet-stream'. This is good if you have MIME::Types on your system and you have no idea what file might be used for the attachment. The default is C<"TEXT">, but it will be C<"AUTO"> if you set $AUTO_CONTENT_TYPE to true (sorry, but you have to enable it explicitly, since we don't want to break code which depends on the old behavior). =back A picture being worth 1000 words (which is of course 2000 bytes, so it's probably more of an "icon" than a "picture", but I digress...), here are some examples: $msg = MIME::Lite->build( From => 'yelling@inter.com', To => 'stocking@fish.net', Subject => "Hi there!", Type => 'TEXT', Encoding => '7bit', Data => "Just a quick note to say hi!" ); $msg = MIME::Lite->build( From => 'dorothy@emerald-city.oz', To => 'gesundheit@edu.edu.edu', Subject => "A gif for U" Type => 'image/gif', Path => "/home/httpd/logo.gif" ); $msg = MIME::Lite->build( From => 'laughing@all.of.us', To => 'scarlett@fiddle.dee.de', Subject => "A gzipp'ed tar file", Type => 'x-gzip', Path => "gzip < /usr/inc/somefile.tar |", ReadNow => 1, Filename => "somefile.tgz" ); To show you what's really going on, that last example could also have been written: $msg = new MIME::Lite; $msg->build( Type => 'x-gzip', Path => "gzip < /usr/inc/somefile.tar |", ReadNow => 1, Filename => "somefile.tgz" ); $msg->add(From => "laughing@all.of.us"); $msg->add(To => "scarlett@fiddle.dee.de"); $msg->add(Subject => "A gzipp'ed tar file"); =back =head2 Setting/getting headers and attributes =over 4 =item add TAG,VALUE I Add field TAG with the given VALUE to the end of the header. The TAG will be converted to all-lowercase, and the VALUE will be made "safe" (returns will be given a trailing space). B any MIME fields you "add" will override any MIME attributes I have when it comes time to output those fields. Normally, you will use this method to add I fields: $msg->add("Subject" => "Hi there!"); Giving VALUE as an arrayref will cause all those values to be added. This is only useful for special multiple-valued fields like "Received": $msg->add("Received" => ["here", "there", "everywhere"] Giving VALUE as the empty string adds an invisible placeholder to the header, which can be used to suppress the output of the "Content-*" fields or the special "MIME-Version" field. When suppressing fields, you should use replace() instead of add(): $msg->replace("Content-disposition" => ""); I add() is probably going to be more efficient than C, so you're better off using it for most applications if you are certain that you don't need to delete() the field first. I the name comes from Mail::Header. =item attr ATTR,[VALUE] I Set MIME attribute ATTR to the string VALUE. ATTR is converted to all-lowercase. This method is normally used to set/get MIME attributes: $msg->attr("content-type" => "text/html"); $msg->attr("content-type.charset" => "US-ASCII"); $msg->attr("content-type.name" => "homepage.html"); This would cause the final output to look something like this: Content-type: text/html; charset=US-ASCII; name="homepage.html" Note that the special empty sub-field tag indicates the anonymous first sub-field. Giving VALUE as undefined will cause the contents of the named subfield to be deleted. Supplying no VALUE argument just returns the attribute's value: $type = $msg->attr("content-type"); ### returns "text/html" $name = $msg->attr("content-type.name"); ### returns "homepage.html" =item delete TAG I Delete field TAG with the given VALUE to the end of the header. The TAG will be converted to all-lowercase. $msg->delete("Subject"); I the name comes from Mail::Header. =item field_order FIELD,...FIELD I Change the order in which header fields are output for this object: $msg->field_order('from', 'to', 'content-type', 'subject'); When used as a class method, changes the default settings for all objects: MIME::Lite->field_order('from', 'to', 'content-type', 'subject'); Case does not matter: all field names will be coerced to lowercase. In either case, supply the empty array to restore the default ordering. =item fields I Return the full header for the object, as a ref to an array of C<[TAG, VALUE]> pairs, where each TAG is all-lowercase. Note that any fields the user has explicitly set will override the corresponding MIME fields that we would otherwise generate. So, don't say... $msg->set("Content-type" => "text/html; charset=US-ASCII"); unless you want the above value to override the "Content-type" MIME field that we would normally generate. I I called this "fields" because the header() method of Mail::Header returns something different, but similar enough to be confusing. You can change the order of the fields: see L. You really shouldn't need to do this, but some people have to deal with broken mailers. =item filename [FILENAME] I Set the filename which this data will be reported as. This actually sets both "standard" attributes. With no argument, returns the filename as dictated by the content-disposition. =item get TAG,[INDEX] I Get the contents of field TAG, which might have been set with set() or replace(). Returns the text of the field. $ml->get('Subject', 0); If the optional 0-based INDEX is given, then we return the INDEX'th occurrence of field TAG. Otherwise, we look at the context: In a scalar context, only the first (0th) occurrence of the field is returned; in an array context, I occurrences are returned. I this should only be used with non-MIME fields. Behavior with MIME fields is TBD, and will raise an exception for now. =item get_length I Recompute the content length for the message I, setting the "content-length" attribute as a side-effect: $msg->get_length; Returns the length, or undefined if not set. I the content length can be difficult to compute, since it involves assembling the entire encoded body and taking the length of it (which, in the case of multipart messages, means freezing all the sub-parts, etc.). This method only sets the content length to a defined value if the message is a singlepart with C<"binary"> encoding, I the body is available either in-core or as a simple file. Otherwise, the content length is set to the undefined value. Since content-length is not a standard MIME field anyway (that's right, kids: it's not in the MIME RFCs, it's an HTTP thing), this seems pretty fair. =item parts I Return the parts of this entity, and this entity only. Returns empty array if this entity has no parts. This is B recursive! Parts can have sub-parts; use parts_DFS() to get everything. =item parts_DFS I Return the list of all MIME::Lite objects included in the entity, starting with the entity itself, in depth-first-search order. If this object has no parts, it alone will be returned. =item preamble [TEXT] I Get/set the preamble string, assuming that this object has subparts. Set it to undef for the default string. =item replace TAG,VALUE I Delete all occurrences of fields named TAG, and add a new field with the given VALUE. TAG is converted to all-lowercase. B the special MIME fields (MIME-version, Content-*): if you "replace" a MIME field, the replacement text will override the I MIME attributes when it comes time to output that field. So normally you use attr() to change MIME fields and add()/replace() to change I fields: $msg->replace("Subject" => "Hi there!"); Giving VALUE as the I will effectively I that field from being output. This is the correct way to suppress the special MIME fields: $msg->replace("Content-disposition" => ""); Giving VALUE as I will just cause all explicit values for TAG to be deleted, without having any new values added. I the name of this method comes from Mail::Header. =item scrub I B Recursively goes through the "parts" tree of this message and tries to find MIME attributes that can be removed. With an array argument, removes exactly those attributes; e.g.: $msg->scrub(['content-disposition', 'content-length']); Is the same as recursively doing: $msg->replace('Content-disposition' => ''); $msg->replace('Content-length' => ''); =back =head2 Setting/getting message data =over 4 =item binmode [OVERRIDE] I With no argument, returns whether or not it thinks that the data (as given by the "Path" argument of C) should be read using binmode() (for example, when C is invoked). The default behavior is that any content type other than C or C is binmode'd; this should in general work fine. With a defined argument, this method sets an explicit "override" value. An undefined argument unsets the override. The new current value is returned. =item data [DATA] I Get/set the literal DATA of the message. The DATA may be either a scalar, or a reference to an array of scalars (which will simply be joined). I setting the data causes the "content-length" attribute to be recomputed (possibly to nothing). =item fh [FILEHANDLE] I Get/set the FILEHANDLE which contains the message data. Takes a filehandle as an input and stores it in the object. This routine is similar to path(); one important difference is that no attempt is made to set the content length. =item path [PATH] I Get/set the PATH to the message data. I setting the path recomputes any existing "content-length" field, and re-sets the "filename" (to the last element of the path if it looks like a simple path, and to nothing if not). =item resetfh [FILEHANDLE] I Set the current position of the filehandle back to the beginning. Only applies if you used "FH" in build() or attach() for this message. Returns false if unable to reset the filehandle (since not all filehandles are seekable). =item read_now I Forces data from the path/filehandle (as specified by C) to be read into core immediately, just as though you had given it literally with the C keyword. Note that the in-core data will always be used if available. Be aware that everything is slurped into a giant scalar: you may not want to use this if sending tar files! The benefit of I reading in the data is that very large files can be handled by this module if left on disk until the message is output via C or C. =item sign PARAMHASH I Sign the message. This forces the message to be read into core, after which the signature is appended to it. =over 4 =item Data As in C: the literal signature data. Can be either a scalar or a ref to an array of scalars. =item Path As in C: the path to the file. =back If no arguments are given, the default is: Path => "$ENV{HOME}/.signature" The content-length is recomputed. =item verify_data I Verify that all "paths" to attached data exist, recursively. It might be a good idea for you to do this before a print(), to prevent accidental partial output if a file might be missing. Raises exception if any path is not readable. =back =head2 Output =over 4 =item print [OUTHANDLE] I Print the message to the given output handle, or to the currently-selected filehandle if none was given. All OUTHANDLE has to be is a filehandle (possibly a glob ref), or any object that responds to a print() message. =item print_body [OUTHANDLE] [IS_SMTP] I Print the body of a message to the given output handle, or to the currently-selected filehandle if none was given. All OUTHANDLE has to be is a filehandle (possibly a glob ref), or any object that responds to a print() message. B raised if unable to open any of the input files, or if a part contains no data, or if an unsupported encoding is encountered. IS_SMPT is a special option to handle SMTP mails a little more intelligently than other send mechanisms may require. Specifically this ensures that the last byte sent is NOT '\n' (octal \012) if the last two bytes are not '\r\n' (\015\012) as this will cause some SMTP servers to hang. =item print_header [OUTHANDLE] I Print the header of the message to the given output handle, or to the currently-selected filehandle if none was given. All OUTHANDLE has to be is a filehandle (possibly a glob ref), or any object that responds to a print() message. =item as_string I Return the entire message as a string, with a header and an encoded body. =item body_as_string I Return the encoded body as a string. This is the portion after the header and the blank line. I actually prepares the body by "printing" to a scalar. Proof that you can hand the C methods any blessed object that responds to a C message. =item header_as_string I Return the header as a string. =back =head2 Sending =over 4 =item send =item send HOW, HOWARGS... I This is the principal method for sending mail, and for configuring how mail will be sent. I with a HOW argument and optional HOWARGS, it sets the default sending mechanism that the no-argument instance method will use. The HOW is a facility name (B), and the HOWARGS is interpreted by the facility. The class method returns the previous HOW and HOWARGS as an array. MIME::Lite->send('sendmail', "d:\\programs\\sendmail.exe"); ... $msg = MIME::Lite->new(...); $msg->send; I (a HOW argument and optional HOWARGS), sends the message in the requested manner; e.g.: $msg->send('sendmail', "d:\\programs\\sendmail.exe"); I sends the message by the default mechanism set up by the class method. Returns whatever the mail-handling routine returns: this should be true on success, false/exception on error: $msg = MIME::Lite->new(From=>...); $msg->send || die "you DON'T have mail!"; On Unix systems (or rather non-Win32 systems), the default setting is equivalent to: MIME::Lite->send("sendmail", "/usr/lib/sendmail -t -oi -oem"); On Win32 systems the default setting is equivalent to: MIME::Lite->send("smtp"); The assumption is that on Win32 your site/lib/Net/libnet.cfg file will be preconfigured to use the appropriate SMTP server. See below for configuring for authentication. There are three facilities: =over 4 =item "sendmail", ARGS... Send a message by piping it into the "sendmail" command. Uses the L method, giving it the ARGS. This usage implements (and deprecates) the C method. =item "smtp", [HOSTNAME, [NAMEDPARMS] ] Send a message by SMTP, using optional HOSTNAME as SMTP-sending host. L will be required. Uses the L method. Any additional arguments passed in will also be passed through to send_by_smtp. This is useful for things like mail servers requiring authentication where you can say something like the following MIME::Lite->send('smtp', $host, AuthUser=>$user, AuthPass=>$pass); which will configure things so future uses of $msg->send(); do the right thing. =item "sub", \&SUBREF, ARGS... Sends a message MSG by invoking the subroutine SUBREF of your choosing, with MSG as the first argument, and ARGS following. =back I let's say you're on an OS which lacks the usual Unix "sendmail" facility, but you've installed something a lot like it, and you need to configure your Perl script to use this "sendmail.exe" program. Do this following in your script's setup: MIME::Lite->send('sendmail', "d:\\programs\\sendmail.exe"); Then, whenever you need to send a message $msg, just say: $msg->send; That's it. Now, if you ever move your script to a Unix box, all you need to do is change that line in the setup and you're done. All of your $msg-Esend invocations will work as expected. After sending, the method last_send_successful() can be used to determine if the send was successful or not. =item send_by_sendmail SENDMAILCMD =item send_by_sendmail PARAM=>VALUE, ARRAY, HASH... I Send message via an external "sendmail" program (this will probably only work out-of-the-box on Unix systems). Returns true on success, false or exception on error. You can specify the program and all its arguments by giving a single string, SENDMAILCMD. Nothing fancy is done; the message is simply piped in. However, if your needs are a little more advanced, you can specify zero or more of the following PARAM/VALUE pairs (or a reference to hash or array of such arguments as well as any combination thereof); a Unix-style, taint-safe "sendmail" command will be constructed for you: =over 4 =item Sendmail Full path to the program to use. Default is "/usr/lib/sendmail". =item BaseArgs Ref to the basic array of arguments we start with. Default is C<["-t", "-oi", "-oem"]>. =item SetSender Unless this is I given as false, we attempt to automatically set the C<-f> argument to the first address that can be extracted from the "From:" field of the message (if there is one). I Suppose we did I use C<-f>, and you gave an explicit "From:" field in your message: in this case, the sendmail "envelope" would indicate the I user your process was running under, as a way of preventing mail forgery. Using the C<-f> switch causes the sender to be set in the envelope as well. I If sendmail doesn't regard you as a "trusted" user, it will permit the C<-f> but also add an "X-Authentication-Warning" header to the message to indicate a forged envelope. To avoid this, you can either (1) have SetSender be false, or (2) make yourself a trusted user by adding a C configuration command to your I file (e.g.: C if the script is running as user "eryq"). =item FromSender If defined, this is identical to setting SetSender to true, except that instead of looking at the "From:" field we use the address given by this option. Thus: FromSender => 'me@myhost.com' =back After sending, the method last_send_successful() can be used to determine if the send was successful or not. =item send_by_smtp HOST, ARGS... =item send_by_smtp REF, HOST, ARGS I Send message via SMTP, using Net::SMTP -- which will be required for this feature. HOST is the name of SMTP server to connect to, or undef to have L use the defaults in Libnet.cfg. ARGS are a list of key value pairs which may be selected from the list below. Many of these are just passed through to specific L commands and you should review that module for details. Please see L =over 4 =item Hello =item LocalAddr =item LocalPort =item Timeout =item Port =item ExactAddresses =item Debug See L for details. =item Size =item Return =item Bits =item Transaction =item Envelope See L for details. =item SkipBad If true doesn't throw an error when multiple email addresses are provided and some are not valid. See L for details. =item AuthUser Authenticate with L using this username. =item AuthPass Authenticate with L using this password. =item NoAuth Normally if AuthUser and AuthPass are defined MIME::Lite will attempt to use them with the L command to authenticate the connection, however if this value is true then no authentication occurs. =item To Sets the addresses to send to. Can be a string or a reference to an array of strings. Normally this is extracted from the To: (and Cc: and Bcc: fields if $AUTO_CC is true). This value overrides that. =item From Sets the email address to send from. Normally this value is extracted from the Return-Path: or From: field of the mail itself (in that order). This value overrides that. =back I True on success, croaks with an error message on failure. After sending, the method last_send_successful() can be used to determine if the send was successful or not. =item send_by_testfile FILENAME I Print message to a file (namely FILENAME), which will default to mailer.testfile If file exists, message will be appended. =item last_send_successful This method will return TRUE if the last send() or send_by_XXX() method call was successful. It will return defined but false if it was not successful, and undefined if the object had not been used to send yet. =item sendmail COMMAND... I Declare the sender to be "sendmail", and set up the "sendmail" command. I =back =head2 Miscellaneous =over 4 =item quiet ONOFF I Suppress/unsuppress all warnings coming from this module. MIME::Lite->quiet(1); ### I know what I'm doing I recommend that you include that comment as well. And while you type it, say it out loud: if it doesn't feel right, then maybe you should reconsider the whole line. C<;-)> =back =head1 NOTES =head2 How do I prevent "Content" headers from showing up in my mail reader? Apparently, some people are using mail readers which display the MIME headers like "Content-disposition", and they want MIME::Lite not to generate them "because they look ugly". Sigh. Y'know, kids, those headers aren't just there for cosmetic purposes. They help ensure that the message is I correctly by mail readers. But okay, you asked for it, you got it... here's how you can suppress the standard MIME headers. Before you send the message, do this: $msg->scrub; You can scrub() any part of a multipart message independently; just be aware that it works recursively. Before you scrub, note the rules that I follow: =over 4 =item Content-type You can safely scrub the "content-type" attribute if, and only if, the part is of type "text/plain" with charset "us-ascii". =item Content-transfer-encoding You can safely scrub the "content-transfer-encoding" attribute if, and only if, the part uses "7bit", "8bit", or "binary" encoding. You are far better off doing this if your lines are under 1000 characters. Generally, that means you I scrub it for plain text, and you can I scrub this for images, etc. =item Content-disposition You can safely scrub the "content-disposition" attribute if you trust the mail reader to do the right thing when it decides whether to show an attachment inline or as a link. Be aware that scrubbing both the content-disposition and the content-type means that there is no way to "recommend" a filename for the attachment! B there are reports of brain-dead MUAs out there that do the wrong thing if you I the content-disposition. If your attachments keep showing up inline or vice-versa, try scrubbing this attribute. =item Content-length You can always scrub "content-length" safely. =back =head2 How do I give my attachment a [different] recommended filename? By using the Filename option (which is different from Path!): $msg->attach(Type => "image/gif", Path => "/here/is/the/real/file.GIF", Filename => "logo.gif"); You should I put path information in the Filename. =head2 Working with UTF-8 and other character sets All text that is added to your mail message should be properly encoded. MIME::Lite doesn't do this for you. For instance, if you want to send your mail in UTF-8, where C<$to>, C<$subject> and C<$text> have these values: =over =item * To: "RamEn NuEez Efoo@bar.comE" =item * Subject: "EAquE estE!" =item * Text: "EQuieres ganar muchos E's?" =back use MIME::Lite; use Encode qw(encode encode_utf8 ); my $to = "Ram\363n Nu\361ez "; my $subject = "\241Aqu\355 est\341!"; my $text = "\277Quieres ganar muchos \x{20ac}'s?"; ### Create a new message encoded in UTF-8: my $msg = MIME::Lite->new( From => 'me@myhost.com', To => encode( 'MIME-Header', $to ), Subject => encode( 'MIME-Header', $subject ), Data => encode_utf8($text) ); $msg->attr( 'content-type' => 'text/plain; charset=utf-8' ); $msg->send; B =over =item * The above example assumes that the values you want to encode are in Perl's "internal" form, i.e. the strings contain decoded UTF-8 characters, not the bytes that represent those characters. See L, L, L and L for more. =item * If, for the body of the email, you want to use a character set other than UTF-8, then you should encode appropriately, and set the correct C, eg: ... Data => encode('iso-8859-15',$text) ... $msg->attr( 'content-type' => 'text/plain; charset=iso-8859-15' ); =item * For the message headers, L only support UTF-8, but most modern mail clients should be able to handle this. It is not a problem to have your headers in a different encoding from the message body. =back =head2 Benign limitations This is "lite", after all... =over 4 =item * There's no parsing. Get MIME-tools if you need to parse MIME messages. =item * MIME::Lite messages are currently I interchangeable with either Mail::Internet or MIME::Entity objects. This is a completely separate module. =item * A content-length field is only inserted if the encoding is binary, the message is a singlepart, and all the document data is available at C time by virtue of residing in a simple path, or in-core. Since content-length is not a standard MIME field anyway (that's right, kids: it's not in the MIME RFCs, it's an HTTP thing), this seems pretty fair. =item * MIME::Lite alone cannot help you lose weight. You must supplement your use of MIME::Lite with a healthy diet and exercise. =back =head2 Cheap and easy mailing I thought putting in a default "sendmail" invocation wasn't too bad an idea, since a lot of Perlers are on UNIX systems. (As of version 3.02 this is default only on Non-Win32 boxen. On Win32 boxen the default is to use SMTP and the defaults specified in the site/lib/Net/libnet.cfg) The out-of-the-box configuration is: MIME::Lite->send('sendmail', "/usr/lib/sendmail -t -oi -oem"); By the way, these arguments to sendmail are: -t Scan message for To:, Cc:, Bcc:, etc. -oi Do NOT treat a single "." on a line as a message terminator. As in, "-oi vey, it truncated my message... why?!" -oem On error, mail back the message (I assume to the appropriate address, given in the header). When mail returns, circle is complete. Jai Guru Deva -oem. Note that these are the same arguments you get if you configure to use the smarter, taint-safe mailing: MIME::Lite->send('sendmail'); If you get "X-Authentication-Warning" headers from this, you can forgo diddling with the envelope by instead specifying: MIME::Lite->send('sendmail', SetSender=>0); And, if you're not on a Unix system, or if you'd just rather send mail some other way, there's always SMTP, which these days probably requires authentication so you probably need to say MIME::Lite->send('smtp', "smtp.myisp.net", AuthUser=>"YourName",AuthPass=>"YourPass" ); Or you can set up your own subroutine to call. In any case, check out the L method. =head1 WARNINGS =head2 Good-vs-bad email addresses with send_by_smtp() If using L, be aware that unless you explicitly provide the email addresses to send to and from you will be forcing MIME::Lite to extract email addresses out of a possible list provided in the C, C, and C fields. This is tricky stuff, and as such only the following sorts of addresses will work reliably: username full.name@some.host.com "Name, Full" B MIME::Lite was never intended to be a Mail User Agent, so please don't expect a full implementation of RFC-822. Restrict yourself to the common forms of Internet addresses described herein, and you should be fine. If this is not feasible, then consider using MIME::Lite to I your message only, and using Net::SMTP explicitly to I your message. B As of MIME::Lite v3.02 the mail name extraction routines have been beefed up considerably. Furthermore if Mail::Address is provided then name extraction is done using that. Accordingly the above advice is now less true than it once was. Funky email names I work properly now. However the disclaimer remains. Patches welcome. :-) =head2 Formatting of headers delayed until print() This class treats a MIME header in the most abstract sense, as being a collection of high-level attributes. The actual RFC-822-style header fields are not constructed until it's time to actually print the darn thing. =head2 Encoding of data delayed until print() When you specify message bodies (in L or L) -- whether by B, B, or B -- be warned that we don't attempt to open files, read filehandles, or encode the data until L is invoked. In the past, this created some confusion for users of sendmail who gave the wrong path to an attachment body, since enough of the print() would succeed to get the initial part of the message out. Nowadays, $AUTO_VERIFY is used to spot-check the Paths given before the mail facility is employed. A whisker slower, but tons safer. Note that if you give a message body via FH, and try to print() a message twice, the second print() will not do the right thing unless you explicitly rewind the filehandle. You can get past these difficulties by using the B option, provided that you have enough memory to handle your messages. =head2 MIME attributes are separate from header fields! B the MIME attributes are stored and manipulated separately from the message header fields; when it comes time to print the header out, I That means that this: ### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ### $msg->add("Content-type", "text/html; charset=US-ASCII"); will set the exact C<"Content-type"> field in the header I write, I I as an escape hatch in case the code that normally formats MIME header fields isn't doing what you need. And, like any escape hatch, it's got an alarm on it: MIME::Lite will warn you if you attempt to C or C any MIME header field. Use C instead. =head2 Beware of lines consisting of a single dot Julian Haight noted that MIME::Lite allows you to compose messages with lines in the body consisting of a single ".". This is true: it should be completely harmless so long as "sendmail" is used with the -oi option (see L<"Cheap and easy mailing">). However, I don't know if using Net::SMTP to transfer such a message is equally safe. Feedback is welcomed. My perspective: I don't want to magically diddle with a user's message unless absolutely positively necessary. Some users may want to send files with "." alone on a line; my well-meaning tinkering could seriously harm them. =head2 Infinite loops may mean tainted data! Stefan Sautter noticed a bug in 2.106 where a m//gc match was failing due to tainted data, leading to an infinite loop inside MIME::Lite. I am attempting to correct for this, but be advised that my fix will silently untaint the data (given the context in which the problem occurs, this should be benign: I've labelled the source code with UNTAINT comments for the curious). So: don't depend on taint-checking to save you from outputting tainted data in a message. =head2 Don't tweak the global configuration Global configuration variables are bad, and should go away. Until they do, please follow the hints with each setting on how I to change it. =head1 A MIME PRIMER =head2 Content types The "Type" parameter of C is a I. This is the actual type of data you are sending. Generally this is a string of the form C<"majortype/minortype">. Here are the major MIME types. A more-comprehensive listing may be found in RFC-2046. =over 4 =item application Data which does not fit in any of the other categories, particularly data to be processed by some type of application program. C, C, C... =item audio Audio data. C