dslinux/user/perl/ext/MIME/Base64 Base64.pm Base64.xs Changes Makefile.PL QuotedPrint.pm README

cayenne dslinux_cayenne at user.in-berlin.de
Tue Dec 5 05:26:53 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/ext/MIME/Base64
In directory antilope:/tmp/cvs-serv7729/ext/MIME/Base64

Added Files:
	Base64.pm Base64.xs Changes Makefile.PL QuotedPrint.pm README 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: Makefile.PL ---
require 5.006;
use ExtUtils::MakeMaker;

my @makefileopts;
if (grep { $_ eq 'PERL_CORE=1' } @ARGV) {
    push @makefileopts, MAN3PODS => {};
}
if ($] >= 5.008) {
    push @makefileopts, INSTALLDIRS => 'perl';
}

WriteMakefile(
    NAME	 => 'MIME::Base64',
    VERSION_FROM => 'Base64.pm',
    dist         => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    @makefileopts,
);

--- NEW FILE: QuotedPrint.pm ---
package MIME::QuotedPrint;

# $Id: QuotedPrint.pm,v 1.1 2006-12-05 04:26:50 dslinux_cayenne Exp $

use strict;
use vars qw(@ISA @EXPORT $VERSION);

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(encode_qp decode_qp);

$VERSION = "3.07";

use MIME::Base64;  # will load XS version of {en,de}code_qp()

*encode = \&encode_qp;
*decode = \&decode_qp;

1;

__END__

=head1 NAME

MIME::QuotedPrint - Encoding and decoding of quoted-printable strings

=head1 SYNOPSIS

 use MIME::QuotedPrint;

 $encoded = encode_qp($decoded);
 $decoded = decode_qp($encoded);

=head1 DESCRIPTION

This module provides functions to encode and decode strings into and from the
quoted-printable encoding specified in RFC 2045 - I<MIME (Multipurpose
Internet Mail Extensions)>.  The quoted-printable encoding is intended
to represent data that largely consists of bytes that correspond to
printable characters in the ASCII character set.  Each non-printable
character (as defined by English Americans) is represented by a
triplet consisting of the character "=" followed by two hexadecimal
digits.

The following functions are provided:

=over 4

=item encode_qp($str)

=item encode_qp($str, $eol)

=item encode_qp($str, $eol, $binmode)

This function returns an encoded version of the string ($str) given as
argument.

The second argument ($eol) is the line-ending sequence to use.  It is
optional and defaults to "\n".  Every occurrence of "\n" is replaced
with this string, and it is also used for additional "soft line
breaks" to ensure that no line end up longer than 76 characters.  Pass
it as "\015\012" to produce data suitable for external consumption.
The string "\r\n" produces the same result on many platforms, but not
all.

The third argument ($binmode) will select binary mode if passed as a
TRUE value.  In binary mode "\n" will be encoded in the same way as
any other non-printable character.  This ensures that a decoder will
end up with exactly the same string whatever line ending sequence it
uses.  In general it is preferable to use the base64 encoding for
binary data; see L<MIME::Base64>.

An $eol of "" (the empty string) is special.  In this case, no "soft
line breaks" are introduced and binary mode is effectively enabled so
that any "\n" in the original data is encoded as well.

=item decode_qp($str);

This function returns the plain text version of the string given
as argument.  The lines of the result are "\n" terminated, even if
the $str argument contains "\r\n" terminated lines.

=back


If you prefer not to import these routines into your namespace, you can
call them as:

  use MIME::QuotedPrint ();
  $encoded = MIME::QuotedPrint::encode($decoded);
  $decoded = MIME::QuotedPrint::decode($encoded);

Perl v5.8 and better allow extended Unicode characters in strings.
Such strings cannot be encoded directly, as the quoted-printable
encoding is only defined for single-byte characters.  The solution is
to use the Encode module to select the byte encoding you want.  For
example:

    use MIME::QuotedPrint qw(encode_qp);
    use Encode qw(encode);

    $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n"));
    print $encoded;

=head1 COPYRIGHT

Copyright 1995-1997,2002-2004 Gisle Aas.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 SEE ALSO

L<MIME::Base64>

=cut

--- NEW FILE: Base64.xs ---
/* $Id: Base64.xs,v 1.1 2006-12-05 04:26:50 dslinux_cayenne Exp $

Copyright 1997-2004 Gisle Aas

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.


The tables and some of the code that used to be here was borrowed from
metamail, which comes with this message:

  Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)

  Permission to use, copy, modify, and distribute this material
  for any purpose and without fee is hereby granted, provided
  that the above copyright notice and this permission notice
  appear in all copies, and that the name of Bellcore not be
  used in advertising or publicity pertaining to this
  material without the specific, prior written permission
  of an authorized representative of Bellcore.	BELLCORE
  MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.

*/


#ifdef __cplusplus
extern "C" {
#endif
#define PERL_NO_GET_CONTEXT     /* we want efficiency */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif

#ifndef PATCHLEVEL
#    include <patchlevel.h>
#    if !(defined(PERL_VERSION) || (SUBVERSION > 0 && defined(PATCHLEVEL)))
#        include <could_not_find_Perl_patchlevel.h>
#    endif
#endif

#if PATCHLEVEL <= 4 && !defined(PL_dowarn)
   #define PL_dowarn dowarn
#endif

#ifdef G_WARN_ON
   #define DOWARN (PL_dowarn & G_WARN_ON)
#else
   #define DOWARN PL_dowarn
#endif


#define MAX_LINE  76 /* size of encoded lines */

static const char basis_64[] =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

#define XX      255	/* illegal base64 char */
#define EQ      254	/* padding */
#define INVALID XX

static const unsigned char index_64[256] = {
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63,
    52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,EQ,XX,XX,
    XX, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
    15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX,
    XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
    41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX,

    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};

#ifdef SvPVbyte
#   if PERL_REVISION == 5 && PERL_VERSION < 7
       /* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
#       undef SvPVbyte
#       define SvPVbyte(sv, lp) \
          ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
           ? ((lp = SvCUR(sv)), SvPVX(sv)) : my_sv_2pvbyte(aTHX_ sv, &lp))
       static char *
       my_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
       {   
           sv_utf8_downgrade(sv,0);
           return SvPV(sv,*lp);
       }
#   endif
#else
#   define SvPVbyte SvPV
#endif

#ifndef isXDIGIT
#   define isXDIGIT isxdigit
#endif

#ifndef NATIVE_TO_ASCII
#   define NATIVE_TO_ASCII(ch) (ch)
#endif

MODULE = MIME::Base64		PACKAGE = MIME::Base64

SV*
encode_base64(sv,...)
	SV* sv
	PROTOTYPE: $;$

	PREINIT:
	char *str;     /* string to encode */
	SSize_t len;   /* length of the string */
	char *eol;     /* the end-of-line sequence to use */
	STRLEN eollen; /* length of the EOL sequence */
	char *r;       /* result string */
	STRLEN rlen;   /* length of result string */
	unsigned char c1, c2, c3;
	int chunk;

	CODE:
#if PERL_REVISION == 5 && PERL_VERSION >= 6
	sv_utf8_downgrade(sv, FALSE);
#endif
	str = SvPV(sv, rlen); /* SvPV(sv, len) gives warning for signed len */
	len = (SSize_t)rlen;

	/* set up EOL from the second argument if present, default to "\n" */
	if (items > 1 && SvOK(ST(1))) {
	    eol = SvPV(ST(1), eollen);
	} else {
	    eol = "\n";
	    eollen = 1;
	}

	/* calculate the length of the result */
	rlen = (len+2) / 3 * 4;	 /* encoded bytes */
	if (rlen) {
	    /* add space for EOL */
	    rlen += ((rlen-1) / MAX_LINE + 1) * eollen;
	}

	/* allocate a result buffer */
	RETVAL = newSV(rlen ? rlen : 1);
	SvPOK_on(RETVAL);	
	SvCUR_set(RETVAL, rlen);
	r = SvPVX(RETVAL);

	/* encode */
	for (chunk=0; len > 0; len -= 3, chunk++) {
	    if (chunk == (MAX_LINE/4)) {
		char *c = eol;
		char *e = eol + eollen;
		while (c < e)
		    *r++ = *c++;
		chunk = 0;
	    }
	    c1 = *str++;
	    c2 = len > 1 ? *str++ : '\0';
	    *r++ = basis_64[c1>>2];
	    *r++ = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)];
	    if (len > 2) {
		c3 = *str++;
		*r++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
		*r++ = basis_64[c3 & 0x3F];
	    } else if (len == 2) {
		*r++ = basis_64[(c2 & 0xF) << 2];
		*r++ = '=';
	    } else { /* len == 1 */
		*r++ = '=';
		*r++ = '=';
	    }
	}
	if (rlen) {
	    /* append eol to the result string */
	    char *c = eol;
	    char *e = eol + eollen;
	    while (c < e)
		*r++ = *c++;
	}
	*r = '\0';  /* every SV in perl should be NUL-terminated */

	OUTPUT:
	RETVAL

SV*
decode_base64(sv)
	SV* sv
	PROTOTYPE: $

	PREINIT:
	STRLEN len;
	register unsigned char *str = (unsigned char*)SvPVbyte(sv, len);
	unsigned char const* end = str + len;
	char *r;
	unsigned char c[4];

	CODE:
	{
	    /* always enough, but might be too much */
	    STRLEN rlen = len * 3 / 4;
	    RETVAL = newSV(rlen ? rlen : 1);
	}
        SvPOK_on(RETVAL);
        r = SvPVX(RETVAL);

	while (str < end) {
	    int i = 0;
            do {
		unsigned char uc = index_64[NATIVE_TO_ASCII(*str++)];
		if (uc != INVALID)
		    c[i++] = uc;

		if (str == end) {
		    if (i < 4) {
			if (i && DOWARN)
			    warn("Premature end of base64 data");
			if (i < 2) goto thats_it;
			if (i == 2) c[2] = EQ;
			c[3] = EQ;
		    }
		    break;
		}
            } while (i < 4);
	
	    if (c[0] == EQ || c[1] == EQ) {
		if (DOWARN) warn("Premature padding of base64 data");
		break;
            }
	    /* printf("c0=%d,c1=%d,c2=%d,c3=%d\n", c[0],c[1],c[2],c[3]);*/

	    *r++ = (c[0] << 2) | ((c[1] & 0x30) >> 4);

	    if (c[2] == EQ)
		break;
	    *r++ = ((c[1] & 0x0F) << 4) | ((c[2] & 0x3C) >> 2);

	    if (c[3] == EQ)
		break;
	    *r++ = ((c[2] & 0x03) << 6) | c[3];
	}

      thats_it:
	SvCUR_set(RETVAL, r - SvPVX(RETVAL));
	*r = '\0';

	OUTPUT:
	RETVAL


MODULE = MIME::Base64		PACKAGE = MIME::QuotedPrint

#define qp_isplain(c) ((c) == '\t' || (((c) >= ' ' && (c) <= '~') && (c) != '='))

SV*
encode_qp(sv,...)
	SV* sv
	PROTOTYPE: $;$$

	PREINIT:
	char *eol;
	STRLEN eol_len;
	int binary;
	STRLEN sv_len;
	STRLEN linelen;
	char *beg;
	char *end;
	char *p;
	char *p_beg;
	STRLEN p_len;

	CODE:
#if PERL_REVISION == 5 && PERL_VERSION >= 6
	sv_utf8_downgrade(sv, FALSE);
#endif
	/* set up EOL from the second argument if present, default to "\n" */
	if (items > 1 && SvOK(ST(1))) {
	    eol = SvPV(ST(1), eol_len);
	} else {
	    eol = "\n";
	    eol_len = 1;
	}

	binary = (items > 2 && SvTRUE(ST(2)));

	beg = SvPV(sv, sv_len);
	end = beg + sv_len;

	RETVAL = newSV(sv_len + 1);
	sv_setpv(RETVAL, "");
	linelen = 0;

	p = beg;
	while (1) {
	    p_beg = p;

	    /* skip past as much plain text as possible */
	    while (p < end && qp_isplain(*p)) {
	        p++;
	    }
	    if (p == end || *p == '\n') {
		/* whitespace at end of line must be encoded */
		while (p > p_beg && (*(p - 1) == '\t' || *(p - 1) == ' '))
		    p--;
	    }

	    p_len = p - p_beg;
	    if (p_len) {
	        /* output plain text (with line breaks) */
	        if (eol_len) {
		    STRLEN max_last_line = (p == end || *p == '\n')
					      ? MAX_LINE         /* .......\n */
					      : ((p + 1) == end || *(p + 1) == '\n')
	                                        ? MAX_LINE - 3   /* ....=XX\n */
	                                        : MAX_LINE - 4;  /* ...=XX=\n */
		    while (p_len + linelen > max_last_line) {
			STRLEN len = MAX_LINE - 1 - linelen;
			if (len > p_len)
			    len = p_len;
			sv_catpvn(RETVAL, p_beg, len);
			p_beg += len;
			p_len -= len;
			sv_catpvn(RETVAL, "=", 1);
			sv_catpvn(RETVAL, eol, eol_len);
		        linelen = 0;
		    }
                }
		if (p_len) {
	            sv_catpvn(RETVAL, p_beg, p_len);
	            linelen += p_len;
		}
	    }

	    if (p == end) {
		break;
            }
	    else if (*p == '\n' && eol_len && !binary) {
	        sv_catpvn(RETVAL, eol, eol_len);
	        p++;
		linelen = 0;
	    }
	    else {
		/* output escaped char (with line breaks) */
	        assert(p < end);
		if (eol_len && linelen > MAX_LINE - 4) {
		    sv_catpvn(RETVAL, "=", 1);
		    sv_catpvn(RETVAL, eol, eol_len);
		    linelen = 0;
		}
	        sv_catpvf(RETVAL, "=%02X", (unsigned char)*p);
	        p++;
	        linelen += 3;
	    }

	    /* optimize reallocs a bit */
	    if (SvLEN(RETVAL) > 80 && SvLEN(RETVAL) - SvCUR(RETVAL) < 3) {
		STRLEN expected_len = (SvCUR(RETVAL) * sv_len) / (p - beg);
     		SvGROW(RETVAL, expected_len);
	    }
        }

	if (SvCUR(RETVAL) && eol_len && linelen) {
	    sv_catpvn(RETVAL, "=", 1);
	    sv_catpvn(RETVAL, eol, eol_len);
	}

	OUTPUT:
	RETVAL

SV*
decode_qp(sv)
	SV* sv
	PROTOTYPE: $

        PREINIT:
	STRLEN len;
	char *str = SvPVbyte(sv, len);
	char const* end = str + len;
	char *r;
	char *whitespace = 0;

        CODE:
	RETVAL = newSV(len ? len : 1);
        SvPOK_on(RETVAL);
        r = SvPVX(RETVAL);
	while (str < end) {
	    if (*str == ' ' || *str == '\t') {
		if (!whitespace)
		    whitespace = str;
		str++;
	    }
	    else if (*str == '\r' && (str + 1) < end && str[1] == '\n') {
		str++;
	    }
	    else if (*str == '\n') {
		whitespace = 0;
		*r++ = *str++;
	    }
	    else {
		if (whitespace) {
		    while (whitespace < str) {
			*r++ = *whitespace++;
		    }
		    whitespace = 0;
                }
            	if (*str == '=') {
		    if ((str + 2) < end && isXDIGIT(str[1]) && isXDIGIT(str[2])) {
	                char buf[3];
                        str++;
	                buf[0] = *str++;
		        buf[1] = *str++;
	                buf[2] = '\0';
		        *r++ = (char)strtol(buf, 0, 16);
	            }
		    else {
		        /* look for soft line break */
		        char *p = str + 1;
		        while (p < end && (*p == ' ' || *p == '\t'))
		            p++;
		        if (p < end && *p == '\n')
		     	    str = p + 1;
		        else if ((p + 1) < end && *p == '\r' && *(p + 1) == '\n')
		            str = p + 2;
		        else
		            *r++ = *str++; /* give up */
		    }
		}
		else {
		    *r++ = *str++;
		}
	    }
	}
	if (whitespace) {
	    while (whitespace < str) {
		*r++ = *whitespace++;
	    }
        }
	*r = '\0';
	SvCUR_set(RETVAL, r - SvPVX(RETVAL));

        OUTPUT:
	RETVAL


MODULE = MIME::Base64		PACKAGE = MIME::Base64

--- NEW FILE: README ---
This package contains a base64 encoder/decoder and a quoted-printable
encoder/decoder.  These encoding methods are specified in RFC 2045 -
MIME (Multipurpose Internet Mail Extensions).

The base64 encoding is designed to represent arbitrary sequences of
octets in a form that need not be humanly readable. A 65-character
subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be
represented per printable character.

The quoted-printable encoding is intended to represent data that
largely consists of bytes that correspond to printable characters in
the ASCII character set.  Each non-printable character is represented by
a triplet consisting of the character "=" followed by two hexadecimal
digits.

In order to install and use this package you will need Perl version
5.6 or better.  Installation as usual:

   perl Makefile.PL
   make
   make test
   make install

Copyright 1995-1999,2001-2004 Gisle Aas <gisle at ActiveState.com>

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

--- NEW FILE: Changes ---
2005-11-30   Gisle Aas <gisle at ActiveState.com>

   Release 3.07

   Use a Makefile.PL that is also suitable for core perl.



2005-11-26   Gisle Aas <gisle at ActiveState.com>

   Release 3.06

   Documentation tweaks.

   use XSLoader; perl-5.6 now required.

   Some consting from bleadperl.

   Unbundled the {en,de}code-{base64,qp} utility scripts.
   These are now found in the MIME-Base64-Scripts package.



2004-09-20   Gisle Aas <gisle at ActiveState.com>

   Release 3.05

   Steve Hay <steve.hay at uk.radan.com> found the warn test broken
   on Windows and provided a fix.



2004-09-18   Gisle Aas <gisle at ActiveState.com>

   Release 3.04
   
   Fixed the bad-sv.t test script to actually contain the
   correct expected result as of v3.02.



2004-08-25   Gisle Aas <gisle at ActiveState.com>

   Release 3.03

   Forgot to increment version number in MIME::QuotedPrint even
   if its interface changed in 3.02.  As a result you will now
   need to require MIME::QuotedPrint 3.03 if you want to ensure
   it provides the binmode interface.



2004-08-24   Gisle Aas <gisle at ActiveState.com>

   Release 3.02

   The encode_qp() function now takes an optional third argument
   to select binary encoding mode.
   <https://rt.cpan.org/Ticket/Display.html?id=7456>

   The result of encode_qp($non_empty, $eol) will now always be
   $eol terminated.  If the string to encode does not end with "\n"
   then a soft line break is appended to the result.  As an example
   encode_qp("foo") used to be encoded as "foo", but now encodes as
   "foo=\n".



2004-03-29   Gisle Aas <gisle at ActiveState.com>

   Release 3.01

   By compiling the extension with PERL_NO_GET_CONTEXT we can
   make it slightly faster on a threaded perl.  No change on a
   regular perl.  Patch provided by Beau E. Cox <beau at beaucox.com>.

   Fixed missing ";" with assert.   Patch provided by
   Brendan O'Dea <bod at debian.org>.



2004-01-14   Gisle Aas <gisle at ActiveState.com>

   Release 3.00

   Drop the pure Perl implementations of the encoders and
   decoders.  They are bloat that hides real problems in
   the XS implementations.  I will re-release them separately
   in the new MIME-Base64-Perl distribution.

   The 'gcc -Wall' fix in 2.22 broke support for perl5.005,
   as the isXDIGIT() macro is not available in that perl.
   This problem has now been fixed.



2004-01-08   Gisle Aas <gisle at ActiveState.com>

   Release 2.23

   Documentation fixes by Paul Croome <Paul.Croome at softwareag.com>.



2004-01-08   Gisle Aas <gisle at ActiveState.com>

   Release 2.22

   Fix 'gcc -Wall' complaints.



2003-10-09   Gisle Aas <gisle at ActiveState.com>

   Release 2.21

   Documentation tweaks.

   Don't rely on SvEND(sv) == '\0' as discussed in the perl5-porters
   mailing list thread that starts with
   http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2003-10/msg00258.html

   Should now pass test suite even without XS support.

   Perl v5.005 or better is now required.



2003-05-13   Gisle Aas <gisle at ActiveState.com>

   Release 2.20

   decode_qp() recognize soft whitespace when there is whitespace
   between the '=' and the '\n'.



2003-05-13   Gisle Aas <gisle at ActiveState.com>

   Release 2.19

   decode_qp() did eat up all trailing whitespace in the string decoded.
   Only whitespace in front of "\n" should go.

   Win32 fix for t/warn.t by Reini Urban <rurban at x-ray.at>.



2003-03-09   Gisle Aas <gisle at ActiveState.com>

   Release 2.18

   Fix up INSTALLDIRS for perl-5.8 and newer.



2003-03-09   Gisle Aas <gisle at ActiveState.com>

   Release 2.17

   Make it reliable to disable base64 decoding warnings by
   resetting $^W in recent perls.  Would really like to be
   able to do real lexical warnings but the current mechanism
   does not seems suitable for XS code.

   Passing "" as $eol to encode_qp() disable soft line
   breaks as well.

   Sync up with changes in bleadperl:
       - safer patchlevel.h include
       - bad cast



2003-01-05   Gisle Aas <gisle at ActiveState.com>

   Release 2.16

   Fixed the encode_qp() line breaking code.  It sometimes
   made lines longer than 76 chars and it could even get into
   an infinite loop on certain inputs.



2003-01-03   Gisle Aas <gisle at ActiveState.com>

   Release 2.15

   Fixed the XS based decode_qp() for strings where a =XX
   sequence was followed by digits.

   Faster encode_qp() for long strings with lots of chars
   that need escaping.

   The old_decode_base64() function introduced in 2.13
   was returning undef for empty input on olders perls.
   This problem has been fixed.



2003-01-01   Gisle Aas <gisle at ActiveState.com>

   Release 2.14

   MIME::QuotedPrint functions now also implemented using XS
   which make them faster.  2-3 times faster when encoding line by
   line and as much as 200 times faster on long binary input.  There
   is probably some breakage on non-ASCII systems from this.

   The encode_qp() function now takes an $eol argument in the
   same way as encode_base64() does.

   Slight change in behaviour: the decode_qp() function now turns
   \r\n terminated lines into \n terminated lines.  This makes is
   more likely that encode_qp(decode_qp()) round-trip properly.

   Included {en,de}code-{base64,qp} utility scripts.



2002-12-27   Gisle Aas <gisle at ActiveState.com>

   Release 2.13

   Sync up with bleadperl:
       - Documentation update
       - EBCDIC support
       - Whitespace tweaks
       - Improved Unicode support
       - Test suite tweaks

   Improved version of the old_{en,de}code_base64 functions
   contributed by Paul Szabo <psz at maths.usyd.edu.au>.



2001-02-23   Gisle Aas <gisle at ActiveState.com>

   Release 2.12

   Speed up pure perl base64 encoder/decoder by using join/map instead
   of while loop.  Contributed by Arno Beckmann <arno at gmx.de>

   Doc update contributed by Jerrad Pierce <belg4mit at CALLOWAY.MIT.EDU>

   Downgrade UTF8 strings before starting to encode.



1999-02-27   Gisle Aas <gisle at aas.no>

   Release 2.11

   Fixed bogus "Premature end of base64 data" warning.  Bug spotted
   by Dwayne Jacques Fontenot.

   Workaround for Redhat shipping trial releases of perl.



1998-12-18   Gisle Aas <aas at sn.no>

   Release 2.10

   A tweak that should make compilation with some old perl5.00[23]
   perls better.

   A cast that make some compilers more happy.



1998-11-13   Gisle Aas <aas at sn.no>

   Release 2.09

   The 2.08 release did not compile with perl5.005_53, because
   all simple globals now need to be prefixed with "PL_".



1998-10-22   Gisle Aas <aas at sn.no>

   Release 2.08

   Found another tweak to speed up decode_base64() with another 3%.

   Improved MIME::Base64 documentation a little.



1998-10-21   Gisle Aas <aas at sn.no>

   Release 2.07

   Faster and smarter C implementation of the decode_base64()
   function.  The new decode_base64() was 25% faster when tested
   on Linux, i586, gcc -O2.



1998-07-15   Gisle Aas <aas at sn.no>

   Release 2.06

   The decode_base64() implemented in pure perl will only carp
   (not croak) if length of data to decode is not a multiple 4.  This
   actually made 'make test' fail after 'rm Base64.xs'.



1998-01-27   Gisle Aas <aas at sn.no>

   Release 2.05

   The decode_base64() would previously allocate a too short buffer for the
   result string when the trailing "==" padding was missing in the string to
   be decoded.

   The encode_base64() now allocate one byte less space in the result
   strings returned.



1997-12-02   Gisle Aas <aas at sn.no>

   Release 2.04

   Documentation expanded a bit.



1997-07-10   Gisle Aas <aas at sn.no>

   Release 2.03

   Decode_base64() doesn't croak on premature ended data any more.
   A warning is generated instead if running under -w.
   


1997-06-27   Gisle Aas <aas at sn.no>

   Release 2.02

   QuotedPrint fix by Roderick Schertler <roderick at argon.org>:

      - Long lines were not broken unless they're at the beginning
        of the text

      - Lines near but not over 76 chars were broken when they
        shouldn't be



1997-06-13   Gisle Aas <aas at sn.no>

   Release 2.01

   Base64.xs: Avoid type convertion warnings with some compilers

   Minor documentation updates



1997-04-24   Gisle Aas <aas at sn.no>

   Release 2.00, based on libwww-perl-5.08.


--- NEW FILE: Base64.pm ---
package MIME::Base64;

# $Id: Base64.pm,v 1.1 2006-12-05 04:26:50 dslinux_cayenne Exp $

use strict;
use vars qw(@ISA @EXPORT $VERSION);

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(encode_base64 decode_base64);

$VERSION = '3.07';

require XSLoader;
XSLoader::load('MIME::Base64', $VERSION);

*encode = \&encode_base64;
*decode = \&decode_base64;

1;

__END__

=head1 NAME

MIME::Base64 - Encoding and decoding of base64 strings

=head1 SYNOPSIS

 use MIME::Base64;

 $encoded = encode_base64('Aladdin:open sesame');
 $decoded = decode_base64($encoded);

=head1 DESCRIPTION

This module provides functions to encode and decode strings into and from the
base64 encoding specified in RFC 2045 - I<MIME (Multipurpose Internet
Mail Extensions)>. The base64 encoding is designed to represent
arbitrary sequences of octets in a form that need not be humanly
readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used,
enabling 6 bits to be represented per printable character.

The following functions are provided:

=over 4

=item encode_base64($str)

=item encode_base64($str, $eol);

Encode data by calling the encode_base64() function.  The first
argument is the string to encode.  The second argument is the
line-ending sequence to use.  It is optional and defaults to "\n".  The
returned encoded string is broken into lines of no more than 76
characters each and it will end with $eol unless it is empty.  Pass an
empty string as second argument if you do not want the encoded string
to be broken into lines.

=item decode_base64($str)

Decode a base64 string by calling the decode_base64() function.  This
function takes a single argument which is the string to decode and
returns the decoded data.

Any character not part of the 65-character base64 subset is
silently ignored.  Characters occurring after a '=' padding character
are never decoded.

If the length of the string to decode, after ignoring
non-base64 chars, is not a multiple of 4 or if padding occurs too early,
then a warning is generated if perl is running under C<-w>.

=back

If you prefer not to import these routines into your namespace, you can
call them as:

    use MIME::Base64 ();
    $encoded = MIME::Base64::encode($decoded);
    $decoded = MIME::Base64::decode($encoded);

=head1 DIAGNOSTICS

The following warnings can be generated if perl is invoked with the
C<-w> switch:

=over 4

=item Premature end of base64 data

The number of characters to decode is not a multiple of 4.  Legal
base64 data should be padded with one or two "=" characters to make
its length a multiple of 4.  The decoded result will be the same
whether the padding is present or not.

=item Premature padding of base64 data

The '=' padding character occurs as the first or second character
in a base64 quartet.

=back

The following exception can be raised:

=over 4

=item Wide character in subroutine entry

The string passed to encode_base64() contains characters with code
above 255.  The base64 encoding is only defined for single-byte
characters.  Use the Encode module to select the byte encoding you
want.

=back

=head1 EXAMPLES

If you want to encode a large file, you should encode it in chunks
that are a multiple of 57 bytes.  This ensures that the base64 lines
line up and that you do not end up with padding in the middle. 57
bytes of data fills one complete base64 line (76 == 57*4/3):

   use MIME::Base64 qw(encode_base64);

   open(FILE, "/var/log/wtmp") or die "$!";
   while (read(FILE, $buf, 60*57)) {
       print encode_base64($buf);
   }

or if you know you have enough memory

   use MIME::Base64 qw(encode_base64);
   local($/) = undef;  # slurp
   print encode_base64(<STDIN>);

The same approach as a command line:

   perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' <file

Decoding does not need slurp mode if every line contains a multiple
of four base64 chars:

   perl -MMIME::Base64 -ne 'print decode_base64($_)' <file

Perl v5.8 and better allow extended Unicode characters in strings.
Such strings cannot be encoded directly, as the base64
encoding is only defined for single-byte characters.  The solution is
to use the Encode module to select the byte encoding you want.  For
example:

    use MIME::Base64 qw(encode_base64);
    use Encode qw(encode);

    $encoded = encode_base64(encode("UTF-8", "\x{FFFF}\n"));
    print $encoded;

=head1 COPYRIGHT

Copyright 1995-1999, 2001-2004 Gisle Aas.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

Distantly based on LWP::Base64 written by Martijn Koster
<m.koster at nexor.co.uk> and Joerg Reichelt <j.reichelt at nexor.co.uk> and
code posted to comp.lang.perl <3pd2lp$6gf at wsinti07.win.tue.nl> by Hans
Mulder <hansm at wsinti07.win.tue.nl>

The XS implementation uses code from metamail.  Copyright 1991 Bell
Communications Research, Inc. (Bellcore)

=head1 SEE ALSO

L<MIME::QuotedPrint>

=cut




More information about the dslinux-commit mailing list