I am able to do mail attachment with text files. but with pgp encrypted files, it truncates data after it encounters 00 bit. I tried to encode it with base64 but then it doesn't give me original message. On internet, at last I found something like RFC 3156 which provides OpenPGP encrypted mail attachment. The problem is, as I am newbie with email attachment, I don't understand how to attach my pgp encrypted file in mail. CAN ANYBODY PLEASE PROVIDE ME AN EXAMPLE OR CLASS BY WHICH I CAN POSSIBLY UNDERSTAND WHAT TO DO?
CODE
$this->errstr = "";
if (empty($data)) {
$this->errstr = "No data to be attached";
return 0;
}
if (trim($contenttype) == '') $contenttype = OCTET;
if (trim($encoding) == '') $encoding = BASE64;
if ($encoding == BIT7)
{$emsg = $data;}
elseif ($encoding == QP)
{$emsg = $$this->qp_func($data);}
elseif ($encoding == BASE64) {
if (!$this->base64_func) # Check if there is user-defined function
{
$emsg = base64_encode($data);
//$emsg = chunk_split(base64_encode($data));
// echo"<BR><BR>ENCODED DATA:<br>$emsg<BR>";
//$long_str = str_replace( "\r\n", "", $emsg );
//$decoded= base64_decode($emsg);
//echo "<BR><BR>DECODED DATA:<br>$decoded<BR>";
}
else
{$emsg = $this->base64_func($data);}
}
//protocol="application/pgp-encrypted"
//put protocol in pgp attachment header.
//if ($contenttype==PGP)
//Check if content-type is text/plain and if charset is not specified append default CHARSET
if (preg_match("!^".TEXT."!i", $contenttype) && !preg_match("!;charset=!i", $contenttype))
$contenttype .= ";\r\n\tcharset=".CHARSET;
$msg = sprintf("Content-Type: %s Content-Transfer-Encoding: %s%s%s%s",
$contenttype.CRLF,
$encoding.CRLF,
((($description) && (BODY != $description))?"Content-Description: $description".CRLF:""),
($disp?"Content-Disposition: $disp".CRLF:""),
CRLF.$emsg.CRLF);
BODY==$description? $this->mimeparts[0] = $msg: $this->mimeparts[] = $msg;
return sizeof($this->mimeparts);
}
/* ---------------------------------------------------------
private:
Construct mail message header from info already given.
This is a very important function. It shows how exactly
the MIME message is constructed.
--------------------------------------------------------- */
function build_message() {
$this->errstr = "";
$msg = "";
$boundary = 'PM'.chr(rand(65, 91)).'------'.md5(uniqid(rand())); # Boundary marker
$nparts = sizeof($this->mimeparts);
// Case 1: Attachment list is there. Therefore MIME Message header must have multipart/mixed
if (is_array($this->mimeparts) && ($nparts > 1)):
$c_ver = "MIME-Version: 1.0".CRLF;
$c_type = 'Content-Type: multipart/mixed;'.CRLF."\tboundary=\"$boundary\"".CRLF;
$c_enc = "Content-Transfer-Encoding: ".BIT7.CRLF;
$c_desc = $c_desc?"Content-Description: $c_desc".CRLF:"";
$warning = CRLF.WARNING.CRLF.CRLF;
// Since we are here, it means we do have attachments => body must become an attachment too.
if (!empty($this->body)) {
$this->attach($this->body, BODY, TEXT, BIT7);
}
// Now create the MIME parts of the email!
for ($i=0; $i < $nparts; $i++) {
if (!empty($this->mimeparts[$i]))
$msg .= CRLF.'--'.$boundary.CRLF.$this->mimeparts[$i].CRLF;
}
$msg .= '--'.$boundary.'--'.CRLF;
$msg = $c_ver.$c_type.$c_enc.$c_desc.$warning.$msg;
else:
if (!empty($this->body)) $msg .= $this->body.CRLF.CRLF;
endif;
[mod edit] added code tags