src/Rails/ActionMailer/Deliverer.php
protected function addAttachments()
    {
        if (class_exists('Finfo', false)) {
            $finfo = new \Finfo(FILEINFO_MIME_TYPE);
        } else {
            $finfo = null;
        }
        
        foreach ($this->mail->attachments as $filename => $attachment) {
            if (!is_array($attachment)) {
                throw new Exception\RuntimeException(
                    sprintf("Attachments must be array, %s passed", gettype($attachment))
                );
            } elseif (
                !is_string($attachment['content']) &&
                (
                 !is_resource($attachment['content']) ||
                 !get_resource_type($attachment['content']) == 'stream'
                )
            ) {
                throw new Exception\RuntimeException(
                    sprintf(
                        "Attachment content must be string or stream, %s passed",
                        gettype($attachment['content'])
                    )
                );
            }
            
            $type = null;
            
            if (empty($attachment['mime_type']) && $finfo) {
                if (is_resource($attachment['content'])) {
                    $type = $finfo->buffer(stream_get_contents($attachment['content']));
                    rewind($attachment['content']);
                } else {
                    $type = $finfo->buffer($attachment['content']);
                }
            }
            
            $part = new Mime\Part($attachment['content']);
            
            if (empty($attachment['encoding'])) {
                $attachment['encoding'] = Mime\Mime::ENCODING_BASE64;
            }
            
            $part->encoding = $attachment['encoding'];
            
            if ($type) {
                $part->type = $type;
            }
            
            if (!empty($attachment['inline'])) {
                $part->disposition = Mime\Mime::DISPOSITION_INLINE;
            } else {
                $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
            }
            
            $this->body->addPart($part);
        }
    }
protected function addAttachments()
    {
        if (class_exists('Finfo', false)) {
            $finfo = new \Finfo(FILEINFO_MIME_TYPE);
        } else {
            $finfo = null;
        }
        
        foreach ($this->mail->attachments as $filename => $attachment) {
            if (!is_array($attachment)) {
                throw new Exception\RuntimeException(
                    sprintf("Attachments must be array, %s passed", gettype($attachment))
                );
            } elseif (
                !is_string($attachment['content']) &&
                (
                 !is_resource($attachment['content']) ||
                 !get_resource_type($attachment['content']) == 'stream'
                )
            ) {
                throw new Exception\RuntimeException(
                    sprintf(
                        "Attachment content must be string or stream, %s passed",
                        gettype($attachment['content'])
                    )
                );
            }
            
            $type = null;
            
            if (empty($attachment['mime_type']) && $finfo) {
                if (is_resource($attachment['content'])) {
                    $type = $finfo->buffer(stream_get_contents($attachment['content']));
                    rewind($attachment['content']);
                } else {
                    $type = $finfo->buffer($attachment['content']);
                }
            }
            
            $part = new Mime\Part($attachment['content']);
            
            if (empty($attachment['encoding'])) {
                $attachment['encoding'] = Mime\Mime::ENCODING_BASE64;
            }
            
            $part->encoding = $attachment['encoding'];
            
            if ($type) {
                $part->type = $type;
            }
            
            if (!empty($attachment['inline'])) {
                $part->disposition = Mime\Mime::DISPOSITION_INLINE;
            } else {
                $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
            }
            
            $this->body->addPart($part);
        }
    }
protected function addAttachments ( ) { if ( class_exists ( 'Finfo' , false ) ) { $ finfo = new \ Finfo ( FILEINFO_MIME_TYPE ) ; } else { $ finfo = null ; } foreach ( $ this -> mail -> attachments as $ filename => $ attachment ) { if ( ! is_array ( $ attachment ) ) { throw new Exception \ RuntimeException ( sprintf ( "Attachments must be array, %s passed" , gettype ( $ attachment ) ) ) ; } elseif ( ! is_string ( $ attachment [ 'content' ] ) && ( ! is_resource ( $ attachment [ 'content' ] ) || ! get_resource_type ( $ attachment [ 'content' ] ) == 'stream' ) ) { throw new Exception \ RuntimeException ( sprintf ( "Attachment content must be string or stream, %s passed" , gettype ( $ attachment [ 'content' ] ) ) ) ; } $ type = null ; if ( empty ( $ attachment [ 'mime_type' ] ) && $ finfo ) { if ( is_resource ( $ attachment [ 'content' ] ) ) { $ type = $ finfo -> buffer ( stream_get_contents ( $ attachment [ 'content' ] ) ) ; rewind ( $ attachment [ 'content' ] ) ; } else { $ type = $ finfo -> buffer ( $ attachment [ 'content' ] ) ; } } $ part = new Mime \ Part ( $ attachment [ 'content' ] ) ; if ( empty ( $ attachment [ 'encoding' ] ) ) { $ attachment [ 'encoding' ] = Mime \ Mime :: ENCODING_BASE64 ; } $ part -> encoding = $ attachment [ 'encoding' ] ; if ( $ type ) { $ part -> type = $ type ; } if ( ! empty ( $ attachment [ 'inline' ] ) ) { $ part -> disposition = Mime \ Mime :: DISPOSITION_INLINE ; } else { $ part -> disposition = Mime \ Mime :: DISPOSITION_ATTACHMENT ; } $ this -> body -> addPart ( $ part ) ; } }
Requires Fileinfo.
Requires Fileinfo .