Mail-IMAPTalk-4.04000755000765000024 013002546016 13104 5ustar00robnstaff000000000000README100644000765000024 57513002546016 14034 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04 This archive contains the distribution Mail-IMAPTalk, version 4.04: IMAP client interface with lots of features This software is copyright (c) 2003-2016 by FastMail. 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.007. LICENSE100644000765000024 4366013002546016 14223 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04This software is copyright (c) 2003-2016 by FastMail. 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) 2003-2016 by FastMail. 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. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA 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 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2003-2016 by FastMail. This is free software, licensed under: The 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. - "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 ftp.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) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting 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. 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 whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Changes100644000765000024 745013002546016 14466 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04Revision history for Perl extension Mail::IMAPTalk. 4.04 2016-10-22 13:16:42+11:00 Australia/Melbourne - Fix authentication to non-SASL-IR servers - Use AUTHENTICATE for login when necessary - Improve handling of headers with high-bit-set octet - Use correct UTF-8 decoder - Allow SELECT by SPECIAL-USE flag (Cyrus feature) 4.03 Wed Mar 23 11:50 2016 - Bump version and update copyright - add AuthzUser to allow admin override login - add UseCompress to use COMPRESS=DEFLATE support if available 4.01 Mon Jul 20 12:15 2015 - Bump version and update copyright - Remove long command timer - Misc parser and fixes - Avoid / in generated message-id - More improvements to find_message function - Add cyrus IMAP extension commands - Support extended-list options to list command - Avoid undef warning on missing foldermode response - Handle unexpected capability response - Add ability to enable tracing when you "use" the module - Replace multigetannotation with multigetmetadata - Add IMAP myrights command - Add IMAP id command - Use release_socket to close connection - Update root folder and Inbox vs INBOX handling - Choose socket library to use, add SSL socket support - Better formatting of email strings from envelope structure 3.01 Tue Jul 10 11:00 2012 - Bumping major version again because of fetch response format changes (Content-Disposition and annotation changes) - Documentation updates. Update to SORT RFC, update to latest ACL RFC - Update get_response_code docs - Alert reponse is remainder of line, put that in the response code Hack around fact alert response is the remainder of the line after the ], it's not an argument inside the [...], but make it look that way because makes API easier to just call get_response_code - Deal with annoying ANSI_X3.4-1968 encoded headers - Handle servers which don't return any untagged sort/search results, but OK response - Add a Pedantic mode to the parser Will die if a line with an unexpected tag appears when parsing responses. Useful for test suite writers. - Fix parsing of server welcome banner - Always increase CmdId, and rethrow error in pedantic mode - Handle buggy multiple spaces in XIMAPPROXY response - Doc updates and misc fixes - Make Mail::IMAPTalk work on perl 5.8 - Add per-command parse mode, and parsing for annotations - Document unicode folders and remove old warnings - Improve find_message - Typo fixes, remove need for Carp - use RFC2047 not RFC1522 - Atoms can have } in them - Allow reporting errors for multigetannotation - Add IDLE command support - Break Content-Disposition into separate parts like Content-Type (NOTE: This changes the result of fetches and is backwards incompatible) - Improve find_message - Handle literals that fail better (eg no + go ahead response) - Strip newlines if server returns them (it should have unfolded) - Allow release_socket() to take an error flag - Show correct system error on system errors 2.01 Fri Jul 15 17:00 2011 - Pushing to CPAN. Updating major version number because of dozens of small incompatible changes 1.04 Mon Feb 8 13:55 2011 - hundreds of changes and improvements while being used internally by Fastmail - now making a project on github 1.03 Thu Sep 29 17:58 2005 - improved find_message() - added check/subscribe/unsubscribe (thanks Shriman Gurung) - documentation cleanup (thanks Shriman Gurung) - extra option to clear tracing variable before each command - fix weird perl memory/performance issue when parsing long ID lists 1.02 Tue Sep 2 10:48 2004 - fix literal continuation response check 1.01 Tue Aug 26 11:48 2004 - add utf-8 decoding support - add annotatemore support 1.00 Tue Feb 3 17:48 2004 - initial release META.yml100644000765000024 1460613002546016 14465 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04--- abstract: 'IMAP client interface with lots of features' author: - 'Rob Mueller ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.007, 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: Mail-IMAPTalk requires: Authen::SASL: '0' Data::Dumper: '0' Digest: '0' Encode: '0' Encode::IMAPUTF7: '0' Exporter: '0' Fcntl: '0' IO::Handle: '0' IO::Select: '0' IO::Socket: '0' MIME::Base64: '0' Socket: '0' constant: '0' strict: '0' warnings: '0' resources: bugtracker: https://github.com/robn/mail-imaptalk/issues homepage: https://github.com/robn/mail-imaptalk repository: https://github.com/robn/mail-imaptalk.git version: '4.04' x_Dist_Zilla: perl: version: '5.024000' plugins: - class: Dist::Zilla::Plugin::PruneCruft name: '@Filter/PruneCruft' version: '6.007' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Filter/ManifestSkip' version: '6.007' - class: Dist::Zilla::Plugin::MetaYAML name: '@Filter/MetaYAML' version: '6.007' - class: Dist::Zilla::Plugin::License name: '@Filter/License' version: '6.007' - class: Dist::Zilla::Plugin::Readme name: '@Filter/Readme' version: '6.007' - class: Dist::Zilla::Plugin::ExtraTests name: '@Filter/ExtraTests' version: '6.007' - class: Dist::Zilla::Plugin::ExecDir name: '@Filter/ExecDir' version: '6.007' - class: Dist::Zilla::Plugin::ShareDir name: '@Filter/ShareDir' version: '6.007' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Filter/MakeMaker' version: '6.007' - class: Dist::Zilla::Plugin::Manifest name: '@Filter/Manifest' version: '6.007' - class: Dist::Zilla::Plugin::TestRelease name: '@Filter/TestRelease' version: '6.007' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Filter/ConfirmRelease' version: '6.007' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Filter/UploadToCPAN' version: '6.007' - class: Dist::Zilla::Plugin::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - Makefile.PL exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . name: GatherDir version: '6.007' - class: Dist::Zilla::Plugin::AutoPrereqs name: AutoPrereqs version: '6.007' - class: Dist::Zilla::Plugin::PkgVersion name: PkgVersion version: '6.007' - class: Dist::Zilla::Plugin::MetaConfig name: MetaConfig version: '6.007' - class: Dist::Zilla::Plugin::MetaJSON name: MetaJSON version: '6.007' - class: Dist::Zilla::Plugin::NextRelease name: NextRelease version: '6.007' - class: Dist::Zilla::Plugin::GithubMeta name: GithubMeta version: '0.54' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - .travis.yml - Changes - Makefile.PL - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . name: '@Git/Check' version: '2.039' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%v%n%n%c Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - .travis.yml - Changes - Makefile.PL - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Commit' version: '2.039' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '4.04' tag_format: '%v' tag_message: v%v Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Tag' version: '2.039' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: repo_root: . name: '@Git/Push' version: '2.039' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: MarkdownInRoot version: '0.161170' - class: Dist::Zilla::Plugin::CopyFilesFromBuild name: CopyFilesFromBuild version: '0.161350' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.007' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.007' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.007' x_serialization_backend: 'YAML::Tiny version 1.69' MANIFEST100644000765000024 25613002546016 14301 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.007. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Mail/IMAPTalk.pm dist.ini100644000765000024 115113002546016 14627 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04name = Mail-IMAPTalk author = Rob Mueller license = Perl_5 copyright_holder = FastMail copyright_year = 2003-2016 version = 4.04 [@Filter] -bundle = @Basic -remove = GatherDir [GatherDir] exclude_filename = Makefile.PL [AutoPrereqs] [PkgVersion] die_on_existing_version = 1 die_on_line_insertion = 1 [MetaConfig] [MetaJSON] [NextRelease] [GithubMeta] issues = 1 [@Git] tag_format = %v allow_dirty = .travis.yml allow_dirty = dist.ini allow_dirty = Changes allow_dirty = Makefile.PL [ReadmeAnyFromPod / MarkdownInRoot] filename = README.md [CopyFilesFromBuild] copy = Makefile.PL META.json100644000765000024 2402113002546016 14625 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04{ "abstract" : "IMAP client interface with lots of features", "author" : [ "Rob Mueller " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Mail-IMAPTalk", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Authen::SASL" : "0", "Data::Dumper" : "0", "Digest" : "0", "Encode" : "0", "Encode::IMAPUTF7" : "0", "Exporter" : "0", "Fcntl" : "0", "IO::Handle" : "0", "IO::Select" : "0", "IO::Socket" : "0", "MIME::Base64" : "0", "Socket" : "0", "constant" : "0", "strict" : "0", "warnings" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/robn/mail-imaptalk/issues" }, "homepage" : "https://github.com/robn/mail-imaptalk", "repository" : { "type" : "git", "url" : "https://github.com/robn/mail-imaptalk.git", "web" : "https://github.com/robn/mail-imaptalk" } }, "version" : "4.04", "x_Dist_Zilla" : { "perl" : { "version" : "5.024000" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Filter/PruneCruft", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Filter/ManifestSkip", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Filter/MetaYAML", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Filter/License", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@Filter/Readme", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Filter/ExtraTests", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Filter/ExecDir", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Filter/ShareDir", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Filter/MakeMaker", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Filter/Manifest", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Filter/TestRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Filter/ConfirmRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Filter/UploadToCPAN", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "Makefile.PL" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." } }, "name" : "GatherDir", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "AutoPrereqs", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "PkgVersion", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "MetaConfig", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "MetaJSON", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "NextRelease", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "GithubMeta", "version" : "0.54" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ ".travis.yml", "Changes", "Makefile.PL", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@Git/Check", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ ".travis.yml", "Changes", "Makefile.PL", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Commit", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "4.04", "tag_format" : "%v", "tag_message" : "v%v" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Tag", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@Git/Push", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "MarkdownInRoot", "version" : "0.161170" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromBuild", "name" : "CopyFilesFromBuild", "version" : "0.161350" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.007" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.007" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.007" } }, "x_serialization_backend" : "Cpanel::JSON::XS version 3.0217" } Makefile.PL100644000765000024 275413002546016 15147 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "IMAP client interface with lots of features", "AUTHOR" => "Rob Mueller ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Mail-IMAPTalk", "LICENSE" => "perl", "NAME" => "Mail::IMAPTalk", "PREREQ_PM" => { "Authen::SASL" => 0, "Data::Dumper" => 0, "Digest" => 0, "Encode" => 0, "Encode::IMAPUTF7" => 0, "Exporter" => 0, "Fcntl" => 0, "IO::Handle" => 0, "IO::Select" => 0, "IO::Socket" => 0, "MIME::Base64" => 0, "Socket" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 }, "VERSION" => "4.04", "test" => { "TESTS" => "" } ); my %FallbackPrereqs = ( "Authen::SASL" => 0, "Data::Dumper" => 0, "Digest" => 0, "Encode" => 0, "Encode::IMAPUTF7" => 0, "Exporter" => 0, "Fcntl" => 0, "IO::Handle" => 0, "IO::Select" => 0, "IO::Socket" => 0, "MIME::Base64" => 0, "Socket" => 0, "constant" => 0, "strict" => 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); Mail000755000765000024 013002546016 14455 5ustar00robnstaff000000000000Mail-IMAPTalk-4.04/libIMAPTalk.pm100755000765000024 44032313002546016 16566 0ustar00robnstaff000000000000Mail-IMAPTalk-4.04/lib/Mailpackage Mail::IMAPTalk; $Mail::IMAPTalk::VERSION = '4.04'; =head1 NAME Mail::IMAPTalk - IMAP client interface with lots of features =head1 SYNOPSIS use Mail::IMAPTalk; $IMAP = Mail::IMAPTalk->new( Server => $IMAPServer, Username => 'foo', Password => 'bar', ) || die "Failed to connect/login to IMAP server"; # Append message to folder open(my $F, 'rfc822msg.txt'); $IMAP->append($FolderName, $F) || die $@; close($F); # Select folder and get first unseen message $IMAP->select($FolderName) || die $@; $MsgId = $IMAP->search('not', 'seen')->[0]; # Get message envelope and print some details $MsgEV = $IMAP->fetch($MsgId, 'envelope')->{$MsgId}->{envelope}; print "From: " . $MsgEv->{From}; print "To: " . $MsgEv->{To}; print "Subject: " . $MsgEv->{Subject}; # Get message body structure $MsgBS = $IMAP->fetch($MsgId, 'bodystructure')->{$MsgId}->{bodystructure}; # Find imap part number of text part of message $MsgTxtHash = Mail::IMAPTalk::find_message($MsgBS); $MsgPart = $MsgTxtHash->{text}->{'IMAP-Partnum'}; # Retrieve message text body $MsgTxt = $IMAP->fetch($MsgId, "body[$MsgPart]")->{$MsgId}->{body}; $IMAP->logout(); =head1 DESCRIPTION This module communicates with an IMAP server. Each IMAP server command is mapped to a method of this object. Although other IMAP modules exist on CPAN, this has several advantages over other modules. =over 4 =item * It parses the more complex IMAP structures like envelopes and body structures into nice Perl data structures. =item * It correctly supports atoms, quoted strings and literals at any point. Some parsers in other modules aren't fully IMAP compatiable and may break at odd times with certain messages on some servers. =item * It allows large return values (eg. attachments on a message) to be read directly into a file, rather than into memory. =item * It includes some helper functions to find the actual text/plain or text/html part of a message out of a complex MIME structure. It also can find a list of attachements, and CID links for HTML messages with attached images. =item * It supports decoding of MIME headers to Perl utf-8 strings automatically, so you don't have to deal with MIME encoded headers (enabled optionally). =back While the IMAP protocol does allow for asynchronous running of commands, this module is designed to be used in a synchronous manner. That is, you issue a command by calling a method, and the command will block until the appropriate response is returned. The method will then return the parsed results from the given command. =cut # Export {{{ require Exporter; @ISA = qw(Exporter); %EXPORT_TAGS = ( Default => [ qw(get_body_part find_message build_cid_map generate_cid) ] ); Exporter::export_ok_tags('Default'); my $AlwaysTrace = 0; sub import { # Test for special case if need UTF8 support our $AlreadyLoadedEncode; my $Class = shift(@_); my %Parameters = map { $_ => 1 } @_; if (delete($Parameters{':utf8support'})) { if (!$AlreadyLoadedEncode) { eval "use Encode qw(decode);"; eval "use Encode::Detect::Detector qw(detect);"; $AlreadyLoadedEncode = 1; } } if (delete($Parameters{':trace'})) { $AlwaysTrace = 1; } @_ = ($Class, keys(%Parameters)); goto &Exporter::import; } # }}} # Use modules {{{ use Fcntl qw(:DEFAULT); use Socket; use IO::Select; use IO::Handle; use IO::Socket; use Digest; use Data::Dumper; # Choose the best socket class to use (all of these are sub-classes of IO::Socket) my $DefSocketClass; BEGIN { for (qw(IO::Socket::IP IO::Socket::INET6 IO::Socket::INET)) { if (eval "use $_; 1;") { $DefSocketClass = $_; last; } } } # Use Time::HiRes if available to handle select restarts eval 'use Time::HiRes qw(time);'; use strict; use warnings; # }}} =head1 CLASS OVERVIEW The object methods have been broken in several sections. =head2 Sections =over 4 =item CONSTANTS Lists the available constants the class uses. =item CONSTRUCTOR Explains all the options available when constructing a new instance of the C class. =item CONNECTION CONTROL METHODS These are methods which control the overall IMAP connection object, such as logging in and logging out, how results are parsed, how folder names and message id's are treated, etc. =item IMAP FOLDER COMMAND METHODS These are methods to inspect, add, delete and rename IMAP folders on the server. =item IMAP MESSAGE COMMAND METHODS These are methods to retrieve, delete, move and add messages to/from IMAP folders. =item HELPER METHODS These are extra methods that users of this class might find useful. They generally do extra parsing on returned structures to provide higher level functionality. =item INTERNAL METHODS These are methods used internally by the C object to get work done. They may be useful if you need to extend the class yourself. Note that internal methods will always 'die' if they encounter any errors. =item INTERNAL SOCKET FUNCTIONS These are functions used internally by the C object to read/write data to/from the IMAP connection socket. The class does its own buffering so if you want to read/write to the IMAP socket, you should use these functions. =item INTERNAL PARSING FUNCTIONS These are functions used to parse the results returned from the IMAP server into Perl style data structures. =back =head2 Method results All methods return undef on failure. There are four main modes of failure: =over 4 =item 1. An error occurred reading/writing to a socket. Maybe the server closed it, or you're not connected to any server. =item 2. An error occurred parsing the response of an IMAP command. This is usually only a problem if your IMAP server returns invalid data. =item 3. An IMAP command didn't return an 'OK' response. =item 4. The socket read operation timed out waiting for a response from the server. =back In each case, some readable form of error text is placed in $@, or you can call the C method. For commands which return responses (e.g. fetch, getacl, etc), the result is returned. See each command for details of the response result. For commands with no response but which succeed (e.g. setacl, rename, etc) the result 'ok' is generally returned. =head2 Method parameters All methods which send data to the IMAP server (e.g. C, C, etc) have their arguments processed before they are sent. Arguments may be specified in several ways: =over 4 =item B The value is first checked and quoted if required. Values containing [\000\012\015] are turned into literals, values containing [\000-\040\{\} \%\*\"] are quoted by surrounding with a "..." pair (any " themselves are turned into \"). undef is turned into NIL =item B The contents of the file is sent as an IMAP literal. Note that because IMAPTalk has to know the length of the file being sent, this must be a true file reference that can be seeked and not just some stream. The entire file will be sent regardless of the current seek point. =item B The string/data in the referenced item should be sent as is, no quoting will occur, and the data won't be sent as quoted or as a literal regardless of the contents of the string/data. =item B Emits an opening bracket, and then each item in the array separated by a space, and finally a closing bracket. Each item in the array is processed by the same methods, so can be a scalar, file ref, scalar ref, another array ref, etc. =item B The hash reference should contain only 1 item. The key is a text string which specifies what to do with the value item of the hash. =over 4 =item * 'Literal' The string/data in the value is sent as an IMAP literal regardless of the actual data in the string/data. =item * 'Quote' The string/data in the value is sent as an IMAP quoted string regardless of the actual data in the string/data. =back Examples: # Password is automatically quoted to "nasty%*\"passwd" $IMAP->login("joe", 'nasty%*"passwd'); # Append $MsgTxt as string $IMAP->append("inbox", { Literal => $MsgTxt }) # Append MSGFILE contents as new message $IMAP->append("inbox", \*MSGFILE ]) =back =cut =head1 CONSTANTS These constants relate to the standard 4 states that an IMAP connection can be in. They are passed and returned from the C method. See RFC 3501 for more details about IMAP connection states. =over 4 =item I Current not connected to any server. =item I Connected to a server, but not logged in. =item I Connected and logged into a server, but not current folder. =item I Connected, logged in and have 'select'ed a current folder. =back =cut # Constants for the possible states the connection can be in {{{ # Object not connected use constant Unconnected => 0; # connected; not logged in use constant Connected => 1; # logged in; no mailbox selected use constant Authenticated => 2; # mailbox selected use constant Selected => 3; # What a link break is on the network connection use constant LB => "\015\012"; use constant LBLEN => length(LB); # Regexps used to determine if header is MIME encoded (we remove . from # especials because of dumb ANSI_X3.4-1968 encoding) my $RFC2047Token = qr/[^\x00-\x1f\(\)\<\>\@\,\;\:\"\/\[\]\?\=\ ]+/; my $RFC2047Encoded = qr/=\?$RFC2047Token\?$RFC2047Token\?[^\?]*\?=/; my $NonAsciiData = qr/[\x1b\x80-\xff]/; # Anything with high-bits or ESC # Known untagged responses my %UntaggedResponses = map { $_ => 1 } qw(exists expunge recent); # Default responses my %RespDefaults = ('annotation' => 'hash', 'metadata' => 'hash', 'fetch' => 'hash', 'list' => 'array', 'lsub' => 'array', 'sort' => 'array', 'search' => 'array'); # }}} =head1 CONSTRUCTOR =over 4 =cut =item Inew(%Options)> Creates new Mail::IMAPTalk object. The following options are supported. =item B =over 4 =item B The hostname or IP address to connect to. This must be supplied unless the B option is supplied. =item B The port number on the host to connect to. Defaults to 143 if not supplied or 993 if not supplied and UseSSL is true. =item B If true, use an IO::Socket::SSL connection. All other SSL_* arguments are passed to the IO::Socket::SSL constructor. =item B An existing socket to use as the connection to the IMAP server. If you supply the B option, you should not supply a B or B option. This is useful if you want to create an SSL socket connection using IO::Socket::SSL and then pass in the connected socket to the new() call. It's also useful in conjunction with the C method described below for reusing the same socket beyond the lifetime of the IMAPTalk object. See a description in the section C method for more information. You must have write flushing enabled for any socket you pass in here so that commands will actually be sent, and responses received, rather than just waiting and eventually timing out. you can do this using the Perl C call and $| ($AUTOFLUSH) variable as shown below. my $ofh = select($Socket); $| = 1; select ($ofh); =item B For historical reasons, when reading from a socket, the module sets the socket to non-blocking and does a select(). If you're using an SSL socket that doesn't work, so you have to set UseBlocking to true to use blocking reads instead. =item B If you supply a C option, you can specify the IMAP state the socket is currently in, namely one of 'Unconnected', 'Connected', 'Authenticated' or 'Selected'. This defaults to 'Connected' if not supplied and the C option is supplied. =item B If supplied and true, and a socket is supplied via the C option, checks that a greeting line is supplied by the server and reads the greeting line. =item B For historical reasons, the special name "INBOX" is rewritten as Inbox because it looks nicer on the way out, and back on the way in. If you want to preserve the name INBOX on the outside, set this flag to true. =item B If you have the Compress::Zlib package installed, and the server supports compress, then setting this flag to true will cause compression to be enabled immediately after login. =back =item B =over 4 =item B The username to connect to the IMAP server as. If not supplied, no login is attempted and the IMAP object is left in the B state. If supplied, you must also supply the B option and a login is attempted. If the login fails, the connection is closed and B is returned. If you want to do something with a connection even if the login fails, don't pass a B option, but instead use the B method described below. =item B The password to use to login to the account. =item B If the server supports it, access the server as this user rather than the authenticate user. =back See the C method for more information. =item B =over 4 =item B Control whether message ids are message uids or not. This is 1 (on) by default because generally that's how most people want to use it. This affects most commands that require/use/return message ids (e.g. B, B, B, etc) =item B If supplied, sets the root folder prefix. This is the same as calling C with the value passed. If no value is supplied, C is called with no value. See the C method for more details. =item B If supplied, sets the folder name text string separator character. Passed as the second parameter to the C method. =item B If supplied, passed along with RootFolder to the C method. =back Examples: $imap = Mail::IMAPTalk->new( Server => 'foo.com', Port => 143, Username => 'joebloggs', Password => 'mypassword', Separator => '.', RootFolder => 'INBOX', ) || die "Connection to foo.com failed. Reason: $@"; $imap = Mail::IMAPTalk->new( Socket => $SSLSocket, State => Mail::IMAPTalk::Authenticated, Uid => 0 ) || die "Could not query on existing socket. Reason: $@"; =cut sub new { my $Proto = shift; my $Class = ref($Proto) || $Proto; my %Args = @_; # Two main possible new() modes. Either connect to server # or use existing socket passed $Args{Server} || $Args{Socket} || die "No 'Server' or 'Socket' specified"; $Args{Server} && $Args{Socket} && die "Can not specify 'Server' and 'Socket' simultaneously"; # Set ourself to empty to start with my $Self = {}; bless ($Self, $Class); # Empty buffer $Self->{ReadBuf} = ''; # Create new socket to server my $Socket; if ($Args{Server}) { # Set starting state $Self->state(Unconnected); my %SocketOpts; my $DefaultPort = 143; my $SocketClass = $DefSocketClass; if (my $SSLOpt = $Args{UseSSL}) { $SSLOpt = $SSLOpt eq '1' ? '' : " qw($SSLOpt)"; eval "use IO::Socket::SSL$SSLOpt; 1;" || return undef; $SocketClass = "IO::Socket::SSL"; $DefaultPort = 993; $SocketOpts{$_} = $Args{$_} for grep { /^SSL_/ } keys %Args; } $SocketOpts{PeerHost} = $Self->{Server} = $Args{Server} || die "No Server name given"; $SocketOpts{PeerPort} = $Self->{Port} = $Args{Port} || $DefaultPort; $Socket = ${SocketClass}->new(%SocketOpts) || return undef; # Force flushing after every write to the socket my $ofh = select($Socket); $| = 1; select ($ofh); # Set to connected state $Self->state(Connected); } # We have an existing socket else { # Copy socket $Socket = $Args{Socket}; delete $Args{Socket}; # Set state $Self->state(exists $Args{State} ? $Args{State} : Connected); } $Self->{Socket} = $Socket; # Save socket for later use and create IO::Select $Self->{Select} = IO::Select->new(); $Self->{Select}->add($Socket); $Self->{LocalFD} = fileno($Socket); $Self->{UseBlocking} = $Args{UseBlocking}; $Self->{Pedantic} = $Args{Pedantic}; $Self->{PreserveINBOX} = $Args{PreserveINBOX}; $Self->{UseCompress} = $Args{UseCompress}; # Do this now, so we trace greeting line as well $Self->set_tracing($AlwaysTrace); # Process greeting if ($Args{Server} || $Args{ExpectGreeting}) { $Self->{CmdId} = "*"; my ($CompletionResp, $DataResp) = $Self->_parse_response(''); return undef if $CompletionResp !~ /^ok/i; } # Start counter when sending commands $Self->{CmdId} = 1; # Set base modes $Self->uid(exists($Args{Uid}) ? $Args{Uid} : 1); $Self->parse_mode(Envelope => 1, BodyStructure => 1, Annotation => 1); $Self->{CurrentFolder} = ''; $Self->{CurrentFolderMode} = ''; # Login first if specified if ($Args{Username}) { # If login fails, just return undef $Self->login(@Args{'Username', 'Password', 'AsUser'}) || return undef; } # Set root folder and separator (if supplied) $Self->set_root_folder( $Args{RootFolder}, $Args{Separator}, $Args{AltRootRegexp}); return $Self; } =back =cut =head1 CONNECTION CONTROL METHODS =over 4 =cut =item I Attempt to login user specified username and password. The actual authentication may be done using the C or C commands, depending on what the server advertises support for. If C<$AsUser> is supplied, an attempt will be made to login on behalf of that user. =cut sub login { my $Self = shift; my ($User, $Pwd, $AsUser) = @_; my $PwdArr = { 'Quote' => $Pwd }; # Clear cached capability responses and the like delete $Self->{Cache}; # If we don't to authenticate on behalf of a user and the server can support # the standard IMAP LOGIN command, then just use that if (!$AsUser && !$Self->capability->{logindisabled}) { $Self->_imap_cmd("login", 0, "", $User, $PwdArr) || return undef; } # Otherwise we'll need to do a true SASL auth else { require Authen::SASL; require MIME::Base64; my @Mechanisms = map { m/auth=(.+)/ ? uc $1 : () } keys %{$Self->capability}; my $SendFirst = $Self->capability->{'sasl-ir'}; my $SASL = Authen::SASL->new( mechanism => join(' ', @Mechanisms), callback => { user => $User, pass => $Pwd, authname => $AsUser, }, ); my $SASLClient = eval { $SASL->client_new }; if ($@) { die "IMAPTalk: Couldn't create SASL client: $@" } my $InitialResponse = $SASLClient->client_start; unless (defined $InitialResponse) { die "IMAPTalk: Couldn't start SASL handshake: ".$SASL->error; } my $PostCommand = sub { $Self->{ReadLine} = undef; if ($InitialResponse && !$SendFirst) { # Need to send initial response (SASL-IR not available) my $Resp = $Self->_next_atom(); if (!$Resp || $Resp ne '+') { die "IMAPTalk: Did not get '+' response"; } # Consume anything left on the wire. Shouldn't be necessary, but... $Self->_remaining_atoms(); $Self->_imap_socket_out(MIME::Base64::encode_base64($InitialResponse, '') . LB); } while ($SASLClient->need_step) { # The server response will either be '+ ' or ' NO'. So # we read the line and if its not a SASL challenge, we put the whole # line back onto the buffer and bail, letting the normal command # response handler deal with it. my $Line = $Self->_imap_socket_read_line; unless ($Line =~ m/^\+/) { substr($Self->{ReadBuf}, 0, 0, $Line . LB); $Self->{ReadLine} = undef; last; } # It's a challenge line, put it on the regular line buffer so we can # use the atom parser $Self->{ReadLine} = $Line; # Consume the leading '+' $Self->_next_atom(); # A SASL challenge. Decode and take a step my ($EncChallenge) = @{$Self->_remaining_atoms()}; my $Challenge = MIME::Base64::decode_base64($EncChallenge); my $Response = $SASLClient->client_step($Challenge); unless (defined $Response) { die "IMAPTalk: Couldn't continue SASL handshake: ".$SASL->error; } $Self->_imap_socket_out(MIME::Base64::encode_base64($Response, '') . LB); } }; my %ParseMode = (PostCommand => $PostCommand); $Self->_imap_cmd( \%ParseMode, "authenticate", 0, '', $SASLClient->mechanism, ($SendFirst && $InitialResponse) ? MIME::Base64::encode_base64($InitialResponse, '') : ()) || return undef; } if ($Self->{UseCompress} && $Self->_require_capability('compress=deflate') && require 'Compress/Zlib.pm') { if ($Self->_imap_cmd("compress", 0, "", "deflate")) { my $error; ($Self->{CompressDeflate}, $error) = Compress::Zlib::deflateInit(-WindowBits => -Compress::Zlib::MAX_WBITS()); die "FAILED TO INIT DEFLATE $error" if $error; ($Self->{CompressInflate}, $error) = Compress::Zlib::inflateInit(-WindowBits => -Compress::Zlib::MAX_WBITS()); die "FAILED TO INIT INFLATE $error" if $error; } } # Set to authenticated if successful $Self->state(Authenticated); return 1; } =item I Log out of IMAP server. This usually closes the servers connection as well. =cut sub logout { my $Self = shift; # Callback to say we're switching folders $Self->cb_switch_folder($Self->{CurrentFolder}, ''); $Self->_imap_cmd('logout', 0, ''); # Returns the socket, which we immediately discard to close $Self->release_socket(1); return 1; } =item I Set/get the current IMAP connection state. Returned or passed value should be one of the constants (Unconnected, Connected, Authenticated, Selected). =cut sub state { my $Self = shift; $Self->{State} = $_[0] if defined $_[0]; return (defined($Self->{State}) ? $Self->{State} : ''); } =item I Get/set the UID status of all UID possible IMAP commands. If set to 1, all commands that can take a UID are set to 'UID Mode', where any ID sent to IMAPTalk is assumed to be a UID. =cut sub uid { $_[0]->{Uid} = $_[1]; return 1; } =item I This method returns the IMAP servers capability command results. The result is a hash reference of (lc(Capability) => 1) key value pairs. This means you can do things like: if ($IMAP->capability()->{quota}) { ... } to test if the server has the QUOTA capability. If you just want a list of capabilities, use the Perl 'keys' function to get a list of keys from the returned hash reference. =cut sub capability { my $Self = shift; # If we've already executed the capability command once, just return the results return $Self->{Cache}->{capability} if exists $Self->{Cache}->{capability}; # Otherwise execute capability command my $Capability = $Self->_imap_cmd("capability", 0, "capability"); # Better be a hash-ref... ($Capability && ref($Capability) eq 'HASH') || return {}; # Save for any future queries and return return ($Self->{Cache}->{capability} = $Capability); } =item I Returns the result of the IMAP servers namespace command. =cut sub namespace { my $Self = shift; # If we've already executed the capability command once, just return the results return $Self->{Cache}->{namespace} if exists $Self->{Cache}->{namespace}; $Self->_require_capability('namespace') || return undef; # Otherwise execute capability command my $Namespace = $Self->_imap_cmd("namespace", 0, "namespace"); # Save for any future queries and return return ($Self->{Cache}->{namespace} = $Namespace); } =item I Perform the standard IMAP 'noop' command which does nothing. =cut sub noop { my $Self = shift; return $Self->_imap_cmd("noop", 0, "", @_); } =item I Enabled the given imap extension =cut sub enable { my $Self = shift; my $Feature = shift; # If we've already executed the enable command once, just return the results return $Self->{Cache}->{enable}->{$Feature} if exists $Self->{Cache}->{enable}->{$Feature}; $Self->_require_capability($Feature) || return undef; my $Result = $Self->_imap_cmd("enable", 0, "enabled", $Feature); $Self->{Cache}->{enable} = $Result; return $Result && $Result->{$Feature}; } =item I Returns true if the current socket connection is still open (e.g. the socket hasn't been closed this end or the other end due to a timeout). =cut sub is_open { my $Self = shift; $Self->_trace("A: is_open test\n") if $Self->{Trace}; while (1) { # Ensure no data was left in our own read buffer if ($Self->{ReadLine}) { $Self->_trace("A: unexpected data in read buffer - '" .$Self->{ReadLine}. "'\n") if $Self->{Trace}; die "IMAPTalk: Unexpected data in read buffer '" . $Self->{ReadLine} . "'"; } $Self->{ReadLine} = undef; # See if there's any data to read local $Self->{Timeout} = 0; # If no sockets with data, must be blocked, so must be connected my $Atom = eval { $Self->_next_atom(); }; # If a timeout, socket is still connected and open if ($@ && ($@ =~ /timed out/)) { $Self->_trace("A: is_open test received timeout, still open\n") if $Self->{Trace}; return 1; } # Other error, assume it's closed if ($@) { $Self->_trace("A: is_open test received error - $@\n") if $Self->{Trace}; $Self->{Socket}->close() if $Self->{Socket}; $Self->{Socket} = undef; delete $Self->{CompressInflate}; delete $Self->{CompressDeflate}; $Self->state(Unconnected); return undef; } # There was something, find what it was $Atom = $Self->_remaining_line(); $Self->_trace("A: is_open test returned data - '$Atom'\n") if $Self->{Trace}; $Atom || die "IMAPTalk: Unexpected response while checking connection - $Atom"; # If it's a bye, we're being closed if ($Atom =~ /^bye/i) { $Self->_trace("A: is_open test received 'bye' response\n") if $Self->{Trace}; $Self->{Socket}->close(); $Self->{Socket} = undef; delete $Self->{CompressInflate}; delete $Self->{CompressDeflate}; $Self->state(Unconnected); return undef; } # Otherwise it was probably some sort of alert, # check again } } =item I Change the root folder prefix. Some IMAP servers require that all user folders/mailboxes live under a root folder prefix (current versions of B for example use 'INBOX' for personal folders and 'user' for other users folders). If no value is specified, it sets it to ''. You might want to use the B method to find out what roots are available. Setting this affects all commands that take a folder argument. Basically if the foldername begins with root folder prefix, it's left as is, otherwise the root folder prefix and separator char are prefixed to the folder name. The AltRootRegexp is a regexp that if the start of the folder name matches, does not have $RootFolder preprended. You can use this to protect other namespaces in your IMAP server. Examples: # This is what cyrus uses $IMAP->set_root_folder('INBOX', '.', qr/^user/); # Selects 'Inbox' (because 'Inbox' eq 'inbox' case insensitive) $IMAP->select('Inbox'); # Selects 'INBOX.blah' $IMAP->select('blah'); # Selects 'INBOX.Inbox.fred' #IMAP->select('Inbox.fred'); # Selects 'user.john' (because 'user' is alt root) #IMAP->select('user.john'); # Selects 'user.john' =cut sub set_root_folder { my ($Self, $RootFolder, $Separator, $AltRootRegexp) = @_; $RootFolder = '' if !defined($RootFolder); $Separator = '.' if !defined($Separator); # Strip off the Separator, if the IMAP-Server already appended it $RootFolder =~ s/\Q$Separator\E$//; $Self->{RootFolder} = $RootFolder; $Self->{AltRootRegexp} = $AltRootRegexp; $Self->{Separator} = $Separator; # We map canonical IMAP INBOX to nicer looking Inbox, # but have to be careful if the root is INBOX as well # INBOX -> Inbox (done in _fix_folder_name) # INBOX.blah -> blah # INBOX.inbox -> INBOX.inbox # INBOX.Inbox -> INBOX.Inbox # INBOX.inbox.inbox -> INBOX.inbox.inbox # INBOX.Inbox.blah -> Inbox.blah # user.xyz -> user.xyz # RootFolderMatch # If folder passed in doesn't match this, then prepend $RootFolder . $Separator # eg prepend inbox. if folder !/^inbox(\.inbox)*$|^user$|^user\./ # UnrootFolderMatch # If folder returned matches this, strip $RootFolder . $Separator # eg strip inbox. if folder /^inbox\.(?!inbox(\.inbox)*)/ my ($RootFolderMatch, $UnrootFolderMatch); if ($RootFolder) { # Note the /i on the end to make this case-insensitive $RootFolderMatch = qr/\Q${RootFolder}\E(?:\Q${Separator}${RootFolder}\E)*/i; $UnrootFolderMatch = qr/^\Q${RootFolder}${Separator}\E(?!${RootFolderMatch}$)/; if ($AltRootRegexp) { $RootFolderMatch = qr/^${RootFolderMatch}$|^(?:${AltRootRegexp}(?:\Q${Separator}\E|$))/; } else { $RootFolderMatch = qr/^${RootFolderMatch}$/; } } @$Self{qw(RootFolderMatch UnrootFolderMatch)} = ($RootFolderMatch, $UnrootFolderMatch); return 1; } =item I<_set_separator($Separator)> Checks if the given separator is the same as the one we used before. If not, it calls set_root_folder to recreate the settings with the new Separator. =cut sub _set_separator { my ($Self, $Separator) = @_; #Nothing to do, if we have the same Separator as before return 1 if (defined($Separator) && ($Self->{Separator} eq $Separator)); return $Self->set_root_folder($Self->{RootFolder}, $Separator, $Self->{AltRootRegexp}); } =item I Sets the mode whether to read literals as file handles or scalars. You should pass a filehandle here that any literal will be read into. To turn off literal reads into a file handle, pass a 0. Examples: # Read rfc822 text of message 3 into file # (note that the file will have /r/n line terminators) open(F, ">messagebody.txt"); $IMAP->literal_handle_control(\*F); $IMAP->fetch(3, 'rfc822'); $IMAP->literal_handle_control(0); =cut sub literal_handle_control { my $Self = shift; $Self->{LiteralControl} = $_[0] if defined $_[0]; return $Self->{LiteralControl} ? 1 : 0; } =item I Release IMAPTalk's ownership of the current socket it's using so it's not disconnected on DESTROY. This returns the socket, and makes sure that the IMAPTalk object doesn't hold a reference to it any more and the connection state is set to "Unconnected". This means you can't call any methods on the IMAPTalk object any more. If the socket is being released and being closed, then $Close is set to true. =cut sub release_socket { my $Self = shift; # Remove from the select object $Self->{Select}->remove($Self->{Socket}) if ref($Self->{Select}); my $Socket = $Self->{Socket}; # Delete any knowledge of the socket in our instance delete $Self->{Socket}; delete $Self->{Select}; delete $Self->{CompressInflate}; delete $Self->{CompressDeflate}; $Self->_trace("A: Release socket, fileno=" . fileno($Socket) . "\n") if $Self->{Trace}; # Set into no connection state $Self->state(Mail::IMAPTalk::Unconnected); return $Socket; } =item I Returns a text string which describes the last error that occurred. =cut sub get_last_error { my $Self = shift; return $Self->{LastError}; } =item I Returns the last completion response to the tagged command. This is either the string "ok", "no" or "bad" (always lower case) =cut sub get_last_completion_response { my $Self = shift; return $Self->{LastRespCode}; } =item I Returns the extra response data generated by a previous call. This is most often used after calling B