[perl] Base64
Salman P. S. L.
correo@salmansl.es
Wed, 24 Feb 1999 14:51:09 +0100
A ver si esto te puede servir de algo, no me preguntes como funciona, pues
me pierdo totalmente
la llamada se hace como:
=================
foreach $strName ('USERFILE1','USERFILE2') {
unless($in{$strName}){next;}
# Trim the filename.
my($strFilename) = $incfn{$strName};
$strFilename =~ s/^(.*[\\\/])([^\\\/])/$2/;
$strAttachment = '--' . $strBoundary . $strEOL;
$strAttachment .=
"Content-Type: application/octet-stream;
name=\"$strFilename\"$strEOL";
$strAttachment .= "Content-Transfer-Encoding: base64$strEOL";
$strAttachment .=
"Content-Disposition: attachment;
filename=\"$strFilename\"$strEOL";
$strAttachment .= $strEOL;
$strAttachment .= EncodeBase64($in{$strName},$strEOL);
SendSMTPLine(\*SOCKET,$strAttachment);
}
=================
======================
# This routine is the inverse of DecodeBase64, it encodes attachments.
sub EncodeBase64 {
my($strAttachmentRaw,$strEOL) = @_;
my($strAttachmentBase64);
pos($strAttachmentRaw) = 0;
while($strAttachmentRaw =~ /(.{1,45})/gs)
{
$strAttachmentBase64 .= substr(pack('u', $1), 1);
chop($strAttachmentBase64);
}
$strAttachmentBase64 =~ tr/` -_/AA-Za-z0-9+\//;
# Fix padding at the end:
my $strPad = (3 - length($strAttachmentRaw) % 3) % 3;
$strAttachmentBase64 =~ s/.{$strPad}$/'=' x $strPad/e if $strPad;
# Wrap lines.
$strAttachmentBase64 =~ s/(.{1,76})/$1$strEOL/g;
return $strAttachmentBase64;
}
========================================================
Saludos
Salvador
-----Mensaje original-----
De: Alejandra Carrillo <alejandrav@spin.com.mx>
Para: perl@tlali.iztacala.unam.mx <perl@tlali.iztacala.unam.mx>
Fecha: martes 23 de febrero de 1999 21:51
Asunto: [perl] Base64
Hola, bueno ahora me toca dar lata a mi, resulta que estoy
haciendo un lector de mail para "Web", he tenido algunos
problemitas pero nada que no haya podido solucionar excepto
que cuando "grabo" un archivo que viene como "Attachment"
y viene codificado en BASE64 no lo convierte del todo bien,
estoy utilizando la librería/odulo MIME::Base64, ¿alguien
ha tenido alguna experiencia en esto?
Tanto los encabezados como el mensaje si vienen codificados
en Base64 sí los decodifica bien.
¿Se tendra que grabar el archivo de alguna forma en especial
si el attachment es un ejecutable o binario?
Ciao,
Alejandra.
http://spin.com.mx/~alejandrav
--------- Pie de mensaje --------------------------------
Visite: http://tlali.iztacala.unam.mx/~randrade/perl.shtml
Cancelar inscripcion:
mail to: majordomo@tlali.iztacala.unam.mx
text : cancelacion perl
--------- Pie de mensaje --------------------------------
Visite: http://tlali.iztacala.unam.mx/~randrade/perl.shtml
Cancelar inscripcion:
mail to: majordomo@tlali.iztacala.unam.mx
text : cancelacion perl