| Email-MIME-CreateHTML documentation | Contained in the Email-MIME-CreateHTML distribution. |
Email::MIME::CreateHTML::Resolver::Filesystem - finds resources via the filesystem
my $o = new Email::MIME::CreateHTML::Resolver::Filesystem(\%args) my ($content,$filename,$mimetype,$xfer_encoding) = $o->get_resource($uri)
This is used by Email::MIME::CreateHTML to load resources.
%args can contain:
Base directory used to resolve relative filepaths passed to get_resource.
- Currently the MIME type is deduced from the file extension via MIME::Types; given we have the content available, more sophisticated strategies are probably possible
$Revision: 1.6 $ on $Date: 2006/08/24 21:41:38 $ by $Author: johna $
Tony Hennessy, Simon Flack and John Alden
(c) BBC 2005,2006. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
| Email-MIME-CreateHTML documentation | Contained in the Email-MIME-CreateHTML distribution. |
############################################################################### # Purpose : Load resources from the filesystem # Author : John Alden # Created : Aug 2006 # CVS : $Header: /home/cvs/software/cvsroot/email/lib/Email/MIME/CreateHTML/Resolver/Filesystem.pm,v 1.6 2006/08/24 21:41:38 johna Exp $ ############################################################################### package Email::MIME::CreateHTML::Resolver::Filesystem; use strict; use URI::file; use File::Slurp::WithinPolicy 'read_file'; use MIME::Types; use File::Spec; use vars qw($VERSION); $VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/; sub new { my ($class, $options) = @_; $options ||= {}; my $self = {%$options}; return bless($self, $class); } #Simple/secure resource loader from local filesystem sub get_resource { my ($self, $uri) = @_; my $base = $self->{base}; #Handle file:// URIs if necessary my ($path, $base_dir) = map {defined && m|^file://|? URI::file->new($_)->file() : $_} ($uri, $base); #Allow for base dir my $fullpath = defined($base_dir) ? File::Spec->catfile($base_dir,$path) : $path; #Read in the file my $content = read_file($fullpath); my ($volume,$directories,$filename) = File::Spec->splitpath( $path ); #Deduce MIME type/transfer encoding (currently using extension) #We may want to improve the sophistication of this (e.g. making use of $content) my ($mimetype,$encoding) = MIME::Types::by_suffix($filename); return ($content,$filename,$mimetype,$encoding); } 1;