Welcome to Dream.In.Code
Become a PHP Expert!

Join 149,879 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,338 people online right now. Registration is fast and FREE... Join Now!




Need an OpenPGP encrypted mail example :?:

 
Closed TopicStart new topic

Need an OpenPGP encrypted mail example :?:, I am newbie with email attachment in php, I need an example code or an

raunak.vaghela
15 Jan, 2007 - 04:10 PM
Post #1

New D.I.C Head
*

Joined: 10 Jan, 2007
Posts: 3


My Contributions
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
User is offlineProfile CardPM
+Quote Post

snoj
RE: Need An OpenPGP Encrypted Mail Example :?:
15 Jan, 2007 - 06:16 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
There is no need to post twice.

Closed.
User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 1/8/09 11:56AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month