<commit_before><?php
/**
 * Describes an email attachment, when found they are attached to sb_Email objects
 *
 * @author: <NAME> and <NAME>
 * @package: email
 * @version 2.2 07/09/2007 06/17/09
 *
 */
class sb_Email_Attachment{

	/**
	 * The extension of the attachment file
	 *
	 * @var string
	 */
	public $extension='';

	/**
	 * The file name of the file attachment e.g. gif, jpg, png, wav, mp3, etc
	 *
	 * @var string
	 */
	public $name='';

	/**
	 * The path to the attachment on the local drive after reading or before writing
	 *
	 * @var string
	 */
	public $filepath='';

	/**
	 * The encoding type of the attchment
	 *
	 * 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
	 *
	 * @var integer
	 */
	public $encoding;

	/**
	 * The subtype of the attachment
	 *
	 * JPEG, WAV, HTML, PLAIN, etc
	 *
	 * @var string
	 */
	public $subtype;

	/**
	 * The type of the attachment
	 *
	 * type 0 = text, 1 = multipart, 2 = message, 3 = application, 4 = audio, 5= image, 6= video, 7 = other
	 *
	 * @var interger
	 */
	public $type;

	/**
	 * The file size in K
	 *
	 * @var float
	 */
	public $sizeK;

	/**
	 * The binary content of the attachment
	 *
	 * @var string
	 */
	public $contents;

	/**
	 * The mime type of the attachment, used when sending
	 *
	 * @var string e.g. image/jpeg
	 */
	public $mime_type;

    /**
     * Zips the attachment before sending and sets the proper mime type
     */
    public function zip(){

        if(empty($this->filepath)){
            throw(new Exception("Must set sb_Email_Attachment::file_path before zipping attachment"));
        }

        if(empty($this->name)){
            $this->name = basename($this->filepath);
        }

        $zip = new ZipArchive();
        $zipfile_path = ROOT."/private/cache/compression/".md5(microtime(true)).'_'.$this->name.".zip";

        @mkdir(dirname($zipfile_path), 0755, true);
        if ($zip->open($zipfile_path, ZIPARCHIVE::CREATE)!==TRUE) {
            throw(new Exception("cannot open <$zipfile_path>\n"));
        }

        $zip->addFromString($this->name, file_get_contents($this->filepath));

        $zip->close();

        $this->name .= '.zip';

         //this is the content, in this case I am ready the blob data from a saved image file but you could easily replace this with blob data from a database.  The mime type will be added based on the extension using sb_Files::extension_to_mime.  For bizarre mime-types that are not in sb_Files::extension_to_mime you can override this by setting the mime-type manually $myAttachment->mime_type ='bizarre/weird';
        $this->contents = file_get_contents($zipfile_path);

        //remove the tmp zip file
        unlink($zipfile_path);

        //add mime type for zip files, sb_Files should handle this after 1.41
        $this->mime_type ='application/x-zip-compressed';

    }

    /**
     * Encrypts the extension with PGP using gpg extension for php http://pecl.php.net/package/gnupg
     * @author <NAME>
     * @param string $pgp_encrypt_key The key to use to encrypt
     * @param string $gnupg_path Optional The path to your .gnupg directory, must be
     * readible by apache, by default served out of /private/resources e.g. ROOT.'/private/resources/.gnupg
     */
    public function pgp_enccrypt($pgp_encrypt_key, $gnupg_path='') {

        if(empty($gnupg_path)){
            $gnupg_path = ROOT.'/private/resources/.gnupg';
        }

        putenv("GNUPGHOME=".$gnupg_path);
        
        $gpg = new gnupg();
        // throw exception if error occurs
        $gpg->seterrormode(gnupg::ERROR_EXCEPTION);

        $gpg->addencryptkey($pgp_encrypt_key);

        $this->contents = $gpg->encrypt($this->contents);
        $this->mime_type = 'application/pgp';
        $this->name .= '.pgp';
    }


}
?><commit_msg>fixed spelling error in method name<commit_after><?php
/**
 * Describes an email attachment, when found they are attached to sb_Email objects
 *
 * @author: <NAME> and <NAME>
 * @package: email
 * @version 2.2 07/09/2007 06/17/09
 *
 */
class sb_Email_Attachment{

	/**
	 * The extension of the attachment file
	 *
	 * @var string
	 */
	public $extension='';

	/**
	 * The file name of the file attachment e.g. gif, jpg, png, wav, mp3, etc
	 *
	 * @var string
	 */
	public $name='';

	/**
	 * The path to the attachment on the local drive after reading or before writing
	 *
	 * @var string
	 */
	public $filepath='';

	/**
	 * The encoding type of the attchment
	 *
	 * 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
	 *
	 * @var integer
	 */
	public $encoding;

	/**
	 * The subtype of the attachment
	 *
	 * JPEG, WAV, HTML, PLAIN, etc
	 *
	 * @var string
	 */
	public $subtype;

	/**
	 * The type of the attachment
	 *
	 * type 0 = text, 1 = multipart, 2 = message, 3 = application, 4 = audio, 5= image, 6= video, 7 = other
	 *
	 * @var interger
	 */
	public $type;

	/**
	 * The file size in K
	 *
	 * @var float
	 */
	public $sizeK;

	/**
	 * The binary content of the attachment
	 *
	 * @var string
	 */
	public $contents;

	/**
	 * The mime type of the attachment, used when sending
	 *
	 * @var string e.g. image/jpeg
	 */
	public $mime_type;

    /**
     * Zips the attachment before sending and sets the proper mime type
     */
    public function zip(){

        if(empty($this->filepath)){
            throw(new Exception("Must set sb_Email_Attachment::file_path before zipping attachment"));
        }

        if(empty($this->name)){
            $this->name = basename($this->filepath);
        }

        $zip = new ZipArchive();
        $zipfile_path = ROOT."/private/cache/compression/".md5(microtime(true)).'_'.$this->name.".zip";

        @mkdir(dirname($zipfile_path), 0755, true);
        if ($zip->open($zipfile_path, ZIPARCHIVE::CREATE)!==TRUE) {
            throw(new Exception("cannot open <$zipfile_path>\n"));
        }

        $zip->addFromString($this->name, file_get_contents($this->filepath));

        $zip->close();

        $this->name .= '.zip';

         //this is the content, in this case I am ready the blob data from a saved image file but you could easily replace this with blob data from a database.  The mime type will be added based on the extension using sb_Files::extension_to_mime.  For bizarre mime-types that are not in sb_Files::extension_to_mime you can override this by setting the mime-type manually $myAttachment->mime_type ='bizarre/weird';
        $this->contents = file_get_contents($zipfile_path);

        //remove the tmp zip file
        unlink($zipfile_path);

        //add mime type for zip files, sb_Files should handle this after 1.41
        $this->mime_type ='application/x-zip-compressed';

    }

    /**
     * Encrypts the extension with PGP using gpg extension for php http://pecl.php.net/package/gnupg
     * @author <NAME>
     * @param string $pgp_encrypt_key The key to use to encrypt
     * @param string $gnupg_path Optional The path to your .gnupg directory, must be
     * readible by apache, by default served out of /private/resources e.g. ROOT.'/private/resources/.gnupg
     */
    public function pgp_encrypt($pgp_encrypt_key, $gnupg_path='') {

        if(empty($gnupg_path)){
            $gnupg_path = ROOT.'/private/resources/.gnupg';
        }

        putenv("GNUPGHOME=".$gnupg_path);
        
        $gpg = new gnupg();
        // throw exception if error occurs
        $gpg->seterrormode(gnupg::ERROR_EXCEPTION);

        $gpg->addencryptkey($pgp_encrypt_key);

        $this->contents = $gpg->encrypt($this->contents);
        $this->mime_type = 'application/pgp';
        $this->name .= '.pgp';
    }


}
?>
{'fraction_non_alphanumeric': 0.13225088385491685, 'fraction_numerical': 0.011260966348042425, 'mean_word_length': 2.619905213270142, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2839779', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2390, 'n_words': 727}