idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
5,700
|
private function establishSocketConnection ( ) { $ host = $ this -> params [ 'host' ] ; if ( ! empty ( $ this -> params [ 'protocol' ] ) ) { $ host = $ this -> params [ 'protocol' ] . '://' . $ host ; } $ timeout = 15 ; if ( ! empty ( $ this -> params [ 'timeout' ] ) ) { $ timeout = $ this -> params [ 'timeout' ] ; } $ options = [ ] ; if ( ! empty ( $ this -> params [ 'sourceIp' ] ) ) { $ options [ 'socket' ] [ 'bindto' ] = $ this -> params [ 'sourceIp' ] . ':0' ; } if ( isset ( $ this -> params [ 'stream_context_options' ] ) ) { $ options = array_merge ( $ options , $ this -> params [ 'stream_context_options' ] ) ; } $ streamContext = stream_context_create ( $ options ) ; $ this -> stream = @ stream_socket_client ( $ host . ':' . $ this -> params [ 'port' ] , $ errno , $ errstr , $ timeout , STREAM_CLIENT_CONNECT , $ streamContext ) ; if ( false === $ this -> stream ) { throw new Swift_TransportException ( 'Connection could not be established with host ' . $ this -> params [ 'host' ] . ' [' . $ errstr . ' #' . $ errno . ']' ) ; } if ( ! empty ( $ this -> params [ 'blocking' ] ) ) { stream_set_blocking ( $ this -> stream , 1 ) ; } else { stream_set_blocking ( $ this -> stream , 0 ) ; } stream_set_timeout ( $ this -> stream , $ timeout ) ; $ this -> in = & $ this -> stream ; $ this -> out = & $ this -> stream ; }
|
Establishes a connection to a remote server .
|
5,701
|
protected function sendMessage1 ( Swift_Transport_SmtpAgent $ agent ) { $ message = $ this -> createMessage1 ( ) ; return $ agent -> executeCommand ( sprintf ( "AUTH %s %s\r\n" , $ this -> getAuthKeyword ( ) , base64_encode ( $ message ) ) , [ 334 ] ) ; }
|
Send our auth message and returns the response .
|
5,702
|
protected function readSubBlock ( $ block ) { $ block = substr ( $ block , 0 , - 8 ) ; $ length = strlen ( $ block ) ; $ offset = 0 ; $ data = [ ] ; while ( $ offset < $ length ) { $ blockLength = hexdec ( substr ( substr ( $ block , $ offset , 8 ) , - 4 ) ) / 256 ; $ offset += 8 ; $ data [ ] = hex2bin ( substr ( $ block , $ offset , $ blockLength * 2 ) ) ; $ offset += $ blockLength * 2 ; } if ( 3 == count ( $ data ) ) { $ data [ ] = $ data [ 2 ] ; $ data [ 2 ] = '' ; } $ data [ ] = $ this -> createByte ( '00' ) ; return $ data ; }
|
Read the blob information in from message2 .
|
5,703
|
protected function sendMessage3 ( $ response , $ username , $ password , $ timestamp , $ client , Swift_Transport_SmtpAgent $ agent , $ v2 = true ) { list ( $ domain , $ username ) = $ this -> getDomainAndUsername ( $ username ) ; list ( $ challenge , , , , , $ workstation , , , $ blob ) = $ this -> parseMessage2 ( $ response ) ; if ( ! $ v2 ) { $ lmResponse = $ this -> createLMPassword ( $ password , $ challenge ) ; $ ntlmResponse = $ this -> createNTLMPassword ( $ password , $ challenge ) ; } else { $ lmResponse = $ this -> createLMv2Password ( $ password , $ username , $ domain , $ challenge , $ client ) ; $ ntlmResponse = $ this -> createNTLMv2Hash ( $ password , $ username , $ domain , $ challenge , $ blob , $ timestamp , $ client ) ; } $ message = $ this -> createMessage3 ( $ domain , $ username , $ workstation , $ lmResponse , $ ntlmResponse ) ; return $ agent -> executeCommand ( sprintf ( "%s\r\n" , base64_encode ( $ message ) ) , [ 235 ] ) ; }
|
Send our final message with all our data .
|
5,704
|
protected function createMessage3 ( $ domain , $ username , $ workstation , $ lmResponse , $ ntlmResponse ) { $ domainSec = $ this -> createSecurityBuffer ( $ domain , 64 ) ; $ domainInfo = $ this -> readSecurityBuffer ( bin2hex ( $ domainSec ) ) ; $ userSec = $ this -> createSecurityBuffer ( $ username , ( $ domainInfo [ 0 ] + $ domainInfo [ 1 ] ) / 2 ) ; $ userInfo = $ this -> readSecurityBuffer ( bin2hex ( $ userSec ) ) ; $ workSec = $ this -> createSecurityBuffer ( $ workstation , ( $ userInfo [ 0 ] + $ userInfo [ 1 ] ) / 2 ) ; $ workInfo = $ this -> readSecurityBuffer ( bin2hex ( $ workSec ) ) ; $ lmSec = $ this -> createSecurityBuffer ( $ lmResponse , ( $ workInfo [ 0 ] + $ workInfo [ 1 ] ) / 2 , true ) ; $ lmInfo = $ this -> readSecurityBuffer ( bin2hex ( $ lmSec ) ) ; $ ntlmSec = $ this -> createSecurityBuffer ( $ ntlmResponse , ( $ lmInfo [ 0 ] + $ lmInfo [ 1 ] ) / 2 , true ) ; return self :: NTLMSIG . $ this -> createByte ( '03' ) . $ lmSec . $ ntlmSec . $ domainSec . $ userSec . $ workSec . $ this -> createByte ( '000000009a' , 8 ) . $ this -> createByte ( '01020000' ) . $ this -> convertTo16bit ( $ domain ) . $ this -> convertTo16bit ( $ username ) . $ this -> convertTo16bit ( $ workstation ) . $ lmResponse . $ ntlmResponse ; }
|
Create our message 3 .
|
5,705
|
protected function getDomainAndUsername ( $ name ) { if ( false !== strpos ( $ name , '\\' ) ) { return explode ( '\\' , $ name ) ; } if ( false !== strpos ( $ name , '@' ) ) { list ( $ user , $ domain ) = explode ( '@' , $ name ) ; return [ $ domain , $ user ] ; } return [ '' , $ name ] ; }
|
Get domain and username from our username .
|
5,706
|
protected function createLMPassword ( $ password , $ challenge ) { $ password = $ this -> createByte ( strtoupper ( $ password ) , 14 , false ) ; list ( $ key1 , $ key2 ) = str_split ( $ password , 7 ) ; $ desKey1 = $ this -> createDesKey ( $ key1 ) ; $ desKey2 = $ this -> createDesKey ( $ key2 ) ; $ constantDecrypt = $ this -> createByte ( $ this -> desEncrypt ( self :: DESCONST , $ desKey1 ) . $ this -> desEncrypt ( self :: DESCONST , $ desKey2 ) , 21 , false ) ; list ( $ key1 , $ key2 , $ key3 ) = str_split ( $ constantDecrypt , 7 ) ; $ desKey1 = $ this -> createDesKey ( $ key1 ) ; $ desKey2 = $ this -> createDesKey ( $ key2 ) ; $ desKey3 = $ this -> createDesKey ( $ key3 ) ; return $ this -> desEncrypt ( $ challenge , $ desKey1 ) . $ this -> desEncrypt ( $ challenge , $ desKey2 ) . $ this -> desEncrypt ( $ challenge , $ desKey3 ) ; }
|
Create LMv1 response .
|
5,707
|
protected function createNTLMPassword ( $ password , $ challenge ) { $ ntlmHash = $ this -> createByte ( $ this -> md4Encrypt ( $ password ) , 21 , false ) ; list ( $ key1 , $ key2 , $ key3 ) = str_split ( $ ntlmHash , 7 ) ; $ desKey1 = $ this -> createDesKey ( $ key1 ) ; $ desKey2 = $ this -> createDesKey ( $ key2 ) ; $ desKey3 = $ this -> createDesKey ( $ key3 ) ; return $ this -> desEncrypt ( $ challenge , $ desKey1 ) . $ this -> desEncrypt ( $ challenge , $ desKey2 ) . $ this -> desEncrypt ( $ challenge , $ desKey3 ) ; }
|
Create NTLMv1 response .
|
5,708
|
protected function getCorrectTimestamp ( $ time ) { $ time = number_format ( $ time , 0 , '.' , '' ) ; $ time = bcadd ( $ time , '11644473600000' , 0 ) ; $ time = bcmul ( $ time , 10000 , 0 ) ; $ binary = $ this -> si2bin ( $ time , 64 ) ; $ timestamp = '' ; for ( $ i = 0 ; $ i < 8 ; ++ $ i ) { $ timestamp .= chr ( bindec ( substr ( $ binary , - ( ( $ i + 1 ) * 8 ) , 8 ) ) ) ; } return $ timestamp ; }
|
Convert a normal timestamp to a tenth of a microtime epoch time .
|
5,709
|
protected function createLMv2Password ( $ password , $ username , $ domain , $ challenge , $ client ) { $ lmPass = '00' ; if ( strlen ( $ password ) <= 15 ) { $ ntlmHash = $ this -> md4Encrypt ( $ password ) ; $ ntml2Hash = $ this -> md5Encrypt ( $ ntlmHash , $ this -> convertTo16bit ( strtoupper ( $ username ) . $ domain ) ) ; $ lmPass = bin2hex ( $ this -> md5Encrypt ( $ ntml2Hash , $ challenge . $ client ) . $ client ) ; } return $ this -> createByte ( $ lmPass , 24 ) ; }
|
Create LMv2 response .
|
5,710
|
protected function createNTLMv2Hash ( $ password , $ username , $ domain , $ challenge , $ targetInfo , $ timestamp , $ client ) { $ ntlmHash = $ this -> md4Encrypt ( $ password ) ; $ ntml2Hash = $ this -> md5Encrypt ( $ ntlmHash , $ this -> convertTo16bit ( strtoupper ( $ username ) . $ domain ) ) ; $ blob = $ this -> createBlob ( $ timestamp , $ client , $ targetInfo ) ; $ ntlmv2Response = $ this -> md5Encrypt ( $ ntml2Hash , $ challenge . $ blob ) ; return $ ntlmv2Response . $ blob ; }
|
Create NTLMv2 response .
|
5,711
|
protected function createSecurityBuffer ( $ value , $ offset , $ is16 = false ) { $ length = strlen ( bin2hex ( $ value ) ) ; $ length = $ is16 ? $ length / 2 : $ length ; $ length = $ this -> createByte ( str_pad ( dechex ( $ length ) , 2 , '0' , STR_PAD_LEFT ) , 2 ) ; return $ length . $ length . $ this -> createByte ( dechex ( $ offset ) , 4 ) ; }
|
Create our security buffer depending on length and offset .
|
5,712
|
protected function readSecurityBuffer ( $ value ) { $ length = floor ( hexdec ( substr ( $ value , 0 , 4 ) ) / 256 ) * 2 ; $ offset = floor ( hexdec ( substr ( $ value , 8 , 4 ) ) / 256 ) * 2 ; return [ $ length , $ offset ] ; }
|
Read our security buffer to fetch length and offset of our value .
|
5,713
|
protected function createByte ( $ input , $ bytes = 4 , $ isHex = true ) { if ( $ isHex ) { $ byte = hex2bin ( str_pad ( $ input , $ bytes * 2 , '00' ) ) ; } else { $ byte = str_pad ( $ input , $ bytes , "\x00" ) ; } return $ byte ; }
|
Right padding with 0 to certain length .
|
5,714
|
protected function md5Encrypt ( $ key , $ msg ) { $ blocksize = 64 ; if ( strlen ( $ key ) > $ blocksize ) { $ key = pack ( 'H*' , md5 ( $ key ) ) ; } $ key = str_pad ( $ key , $ blocksize , "\0" ) ; $ ipadk = $ key ^ str_repeat ( "\x36" , $ blocksize ) ; $ opadk = $ key ^ str_repeat ( "\x5c" , $ blocksize ) ; return pack ( 'H*' , md5 ( $ opadk . pack ( 'H*' , md5 ( $ ipadk . $ msg ) ) ) ) ; }
|
MD5 Encryption .
|
5,715
|
protected function md4Encrypt ( $ input ) { $ input = $ this -> convertTo16bit ( $ input ) ; return function_exists ( 'hash' ) ? hex2bin ( hash ( 'md4' , $ input ) ) : mhash ( MHASH_MD4 , $ input ) ; }
|
MD4 Encryption .
|
5,716
|
public function setQPDotEscape ( $ dotEscape ) { $ dotEscape = ! empty ( $ dotEscape ) ; Swift_DependencyContainer :: getInstance ( ) -> register ( 'mime.qpcontentencoder' ) -> asNewInstanceOf ( 'Swift_Mime_ContentEncoder_QpContentEncoder' ) -> withDependencies ( [ 'mime.charstream' , 'mime.bytecanonicalizer' ] ) -> addConstructorValue ( $ dotEscape ) ; return $ this ; }
|
Set the QuotedPrintable dot escaper preference .
|
5,717
|
public function write ( $ bytes ) { $ this -> out += strlen ( $ bytes ) ; foreach ( $ this -> mirrors as $ stream ) { $ stream -> write ( $ bytes ) ; } }
|
Called when a message is sent so that the outgoing counter can be increased .
|
5,718
|
public function addPart ( $ body , $ contentType = null , $ charset = null ) { return $ this -> attach ( ( new Swift_MimePart ( $ body , $ contentType , $ charset ) ) -> setEncoder ( $ this -> getEncoder ( ) ) ) ; }
|
Add a MimePart to this Message .
|
5,719
|
public function attachSigner ( Swift_Signer $ signer ) { if ( $ signer instanceof Swift_Signers_HeaderSigner ) { $ this -> headerSigners [ ] = $ signer ; } elseif ( $ signer instanceof Swift_Signers_BodySigner ) { $ this -> bodySigners [ ] = $ signer ; } return $ this ; }
|
Attach a new signature handler to the message .
|
5,720
|
public function detachSigner ( Swift_Signer $ signer ) { if ( $ signer instanceof Swift_Signers_HeaderSigner ) { foreach ( $ this -> headerSigners as $ k => $ headerSigner ) { if ( $ headerSigner === $ signer ) { unset ( $ this -> headerSigners [ $ k ] ) ; return $ this ; } } } elseif ( $ signer instanceof Swift_Signers_BodySigner ) { foreach ( $ this -> bodySigners as $ k => $ bodySigner ) { if ( $ bodySigner === $ signer ) { unset ( $ this -> bodySigners [ $ k ] ) ; return $ this ; } } } return $ this ; }
|
Detach a signature handler from a message .
|
5,721
|
protected function doSign ( ) { foreach ( $ this -> bodySigners as $ signer ) { $ altered = $ signer -> getAlteredHeaders ( ) ; $ this -> saveHeaders ( $ altered ) ; $ signer -> signMessage ( $ this ) ; } foreach ( $ this -> headerSigners as $ signer ) { $ altered = $ signer -> getAlteredHeaders ( ) ; $ this -> saveHeaders ( $ altered ) ; $ signer -> reset ( ) ; $ signer -> setHeaders ( $ this -> getHeaders ( ) ) ; $ signer -> startBody ( ) ; $ this -> bodyToByteStream ( $ signer ) ; $ signer -> endBody ( ) ; $ signer -> addSignature ( $ this -> getHeaders ( ) ) ; } }
|
loops through signers and apply the signatures .
|
5,722
|
protected function saveMessage ( ) { $ this -> savedMessage = [ 'headers' => [ ] ] ; $ this -> savedMessage [ 'body' ] = $ this -> getBody ( ) ; $ this -> savedMessage [ 'children' ] = $ this -> getChildren ( ) ; if ( count ( $ this -> savedMessage [ 'children' ] ) > 0 && '' != $ this -> getBody ( ) ) { $ this -> setChildren ( array_merge ( [ $ this -> becomeMimePart ( ) ] , $ this -> savedMessage [ 'children' ] ) ) ; $ this -> setBody ( '' ) ; } }
|
save the message before any signature is applied .
|
5,723
|
protected function saveHeaders ( array $ altered ) { foreach ( $ altered as $ head ) { $ lc = strtolower ( $ head ) ; if ( ! isset ( $ this -> savedMessage [ 'headers' ] [ $ lc ] ) ) { $ this -> savedMessage [ 'headers' ] [ $ lc ] = $ this -> getHeaders ( ) -> getAll ( $ head ) ; } } }
|
save the original headers .
|
5,724
|
protected function restoreHeaders ( ) { foreach ( $ this -> savedMessage [ 'headers' ] as $ name => $ savedValue ) { $ headers = $ this -> getHeaders ( ) -> getAll ( $ name ) ; foreach ( $ headers as $ key => $ value ) { if ( ! isset ( $ savedValue [ $ key ] ) ) { $ this -> getHeaders ( ) -> remove ( $ name , $ key ) ; } } } }
|
Remove or restore altered headers .
|
5,725
|
protected function restoreMessage ( ) { $ this -> setBody ( $ this -> savedMessage [ 'body' ] ) ; $ this -> setChildren ( $ this -> savedMessage [ 'children' ] ) ; $ this -> restoreHeaders ( ) ; $ this -> savedMessage = [ ] ; }
|
Restore message body .
|
5,726
|
public function setCharset ( $ charset ) { $ this -> charset = $ charset ; $ this -> factory -> charsetChanged ( $ charset ) ; $ this -> notifyHeadersOfCharset ( $ charset ) ; }
|
Set the charset used by these headers .
|
5,727
|
public function addIdHeader ( $ name , $ ids = null ) { $ this -> storeHeader ( $ name , $ this -> factory -> createIdHeader ( $ name , $ ids ) ) ; }
|
Add a new ID header for Message - ID or Content - ID .
|
5,728
|
public function set ( Swift_Mime_Header $ header , $ index = 0 ) { $ this -> storeHeader ( $ header -> getFieldName ( ) , $ header , $ index ) ; }
|
Set a header in the HeaderSet .
|
5,729
|
public function listAll ( ) { $ headers = $ this -> headers ; if ( $ this -> canSort ( ) ) { uksort ( $ headers , [ $ this , 'sortHeaders' ] ) ; } return array_keys ( $ headers ) ; }
|
Return the name of all Headers .
|
5,730
|
public function toString ( ) { $ string = '' ; $ headers = $ this -> headers ; if ( $ this -> canSort ( ) ) { uksort ( $ headers , [ $ this , 'sortHeaders' ] ) ; } foreach ( $ headers as $ collection ) { foreach ( $ collection as $ header ) { if ( $ this -> isDisplayed ( $ header ) || '' != $ header -> getFieldBody ( ) ) { $ string .= $ header -> toString ( ) ; } } } return $ string ; }
|
Returns a string with a representation of all headers .
|
5,731
|
private function storeHeader ( $ name , Swift_Mime_Header $ header , $ offset = null ) { if ( ! isset ( $ this -> headers [ strtolower ( $ name ) ] ) ) { $ this -> headers [ strtolower ( $ name ) ] = [ ] ; } if ( ! isset ( $ offset ) ) { $ this -> headers [ strtolower ( $ name ) ] [ ] = $ header ; } else { $ this -> headers [ strtolower ( $ name ) ] [ $ offset ] = $ header ; } }
|
Save a Header to the internal collection
|
5,732
|
private function notifyHeadersOfCharset ( $ charset ) { foreach ( $ this -> headers as $ headerGroup ) { foreach ( $ headerGroup as $ header ) { $ header -> setCharset ( $ charset ) ; } } }
|
Notify all Headers of the new charset
|
5,733
|
public function setSubject ( $ subject ) { if ( ! $ this -> setHeaderFieldModel ( 'Subject' , $ subject ) ) { $ this -> getHeaders ( ) -> addTextHeader ( 'Subject' , $ subject ) ; } return $ this ; }
|
Set the subject of this message .
|
5,734
|
public function setDate ( DateTimeInterface $ dateTime ) { if ( ! $ this -> setHeaderFieldModel ( 'Date' , $ dateTime ) ) { $ this -> getHeaders ( ) -> addDateHeader ( 'Date' , $ dateTime ) ; } return $ this ; }
|
Set the date at which this message was created .
|
5,735
|
public function detach ( Swift_Mime_SimpleMimeEntity $ entity ) { $ newChildren = [ ] ; foreach ( $ this -> getChildren ( ) as $ child ) { if ( $ entity !== $ child ) { $ newChildren [ ] = $ child ; } } $ this -> setChildren ( $ newChildren ) ; return $ this ; }
|
Remove an already attached entity .
|
5,736
|
protected function becomeMimePart ( ) { $ part = new parent ( $ this -> getHeaders ( ) -> newInstance ( ) , $ this -> getEncoder ( ) , $ this -> getCache ( ) , $ this -> getIdGenerator ( ) , $ this -> userCharset ) ; $ part -> setContentType ( $ this -> userContentType ) ; $ part -> setBody ( $ this -> getBody ( ) ) ; $ part -> setFormat ( $ this -> userFormat ) ; $ part -> setDelSp ( $ this -> userDelSp ) ; $ part -> setNestingLevel ( $ this -> getTopNestingLevel ( ) ) ; return $ part ; }
|
Turn the body of this message into a child of itself if needed
|
5,737
|
private function getTopNestingLevel ( ) { $ highestLevel = $ this -> getNestingLevel ( ) ; foreach ( $ this -> getChildren ( ) as $ child ) { $ childLevel = $ child -> getNestingLevel ( ) ; if ( $ highestLevel < $ childLevel ) { $ highestLevel = $ childLevel ; } } return $ highestLevel ; }
|
Get the highest nesting level nested inside this message
|
5,738
|
public function setAddress ( $ address ) { if ( null === $ address ) { $ this -> address = null ; } elseif ( '' == $ address ) { $ this -> address = '' ; } else { $ this -> assertValidAddress ( $ address ) ; $ this -> address = $ address ; } $ this -> setCachedValue ( null ) ; }
|
Set the Address which should appear in this Header .
|
5,739
|
public function setTimeout ( $ timeout ) { $ this -> params [ 'timeout' ] = ( int ) $ timeout ; $ this -> buffer -> setParam ( 'timeout' , ( int ) $ timeout ) ; return $ this ; }
|
Set the connection timeout .
|
5,740
|
public function setExtensionHandlers ( array $ handlers ) { $ assoc = [ ] ; foreach ( $ handlers as $ handler ) { $ assoc [ $ handler -> getHandledKeyword ( ) ] = $ handler ; } uasort ( $ assoc , function ( $ a , $ b ) { return $ a -> getPriorityOver ( $ b -> getHandledKeyword ( ) ) ; } ) ; $ this -> handlers = $ assoc ; $ this -> setHandlerParams ( ) ; return $ this ; }
|
Set ESMTP extension handlers .
|
5,741
|
protected function doHeloCommand ( ) { try { $ response = $ this -> executeCommand ( sprintf ( "EHLO %s\r\n" , $ this -> domain ) , [ 250 ] ) ; } catch ( Swift_TransportException $ e ) { return parent :: doHeloCommand ( ) ; } if ( $ this -> params [ 'tls' ] ) { try { $ this -> executeCommand ( "STARTTLS\r\n" , [ 220 ] ) ; if ( ! $ this -> buffer -> startTLS ( ) ) { throw new Swift_TransportException ( 'Unable to connect with TLS encryption' ) ; } try { $ response = $ this -> executeCommand ( sprintf ( "EHLO %s\r\n" , $ this -> domain ) , [ 250 ] ) ; } catch ( Swift_TransportException $ e ) { return parent :: doHeloCommand ( ) ; } } catch ( Swift_TransportException $ e ) { $ this -> throwException ( $ e ) ; } } $ this -> capabilities = $ this -> getCapabilities ( $ response ) ; if ( ! isset ( $ this -> pipelining ) ) { $ this -> pipelining = isset ( $ this -> capabilities [ 'PIPELINING' ] ) ; } $ this -> setHandlerParams ( ) ; foreach ( $ this -> getActiveHandlers ( ) as $ handler ) { $ handler -> afterEhlo ( $ this ) ; } }
|
Overridden to perform EHLO instead
|
5,742
|
protected function doMailFromCommand ( $ address ) { $ address = $ this -> addressEncoder -> encodeString ( $ address ) ; $ handlers = $ this -> getActiveHandlers ( ) ; $ params = [ ] ; foreach ( $ handlers as $ handler ) { $ params = array_merge ( $ params , ( array ) $ handler -> getMailParams ( ) ) ; } $ paramStr = ! empty ( $ params ) ? ' ' . implode ( ' ' , $ params ) : '' ; $ this -> executeCommand ( sprintf ( "MAIL FROM:<%s>%s\r\n" , $ address , $ paramStr ) , [ 250 ] , $ failures , true ) ; }
|
Overridden to add Extension support
|
5,743
|
private function getCapabilities ( $ ehloResponse ) { $ capabilities = [ ] ; $ ehloResponse = trim ( $ ehloResponse ) ; $ lines = explode ( "\r\n" , $ ehloResponse ) ; array_shift ( $ lines ) ; foreach ( $ lines as $ line ) { if ( preg_match ( '/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di' , $ line , $ matches ) ) { $ keyword = strtoupper ( $ matches [ 1 ] ) ; $ paramStr = strtoupper ( ltrim ( $ matches [ 2 ] , ' =' ) ) ; $ params = ! empty ( $ paramStr ) ? explode ( ' ' , $ paramStr ) : [ ] ; $ capabilities [ $ keyword ] = $ params ; } } return $ capabilities ; }
|
Determine ESMTP capabilities by function group
|
5,744
|
private function setHandlerParams ( ) { foreach ( $ this -> handlers as $ keyword => $ handler ) { if ( array_key_exists ( $ keyword , $ this -> capabilities ) ) { $ handler -> setKeywordParams ( $ this -> capabilities [ $ keyword ] ) ; } } }
|
Set parameters which are used by each extension handler
|
5,745
|
private function getActiveHandlers ( ) { $ handlers = [ ] ; foreach ( $ this -> handlers as $ keyword => $ handler ) { if ( array_key_exists ( $ keyword , $ this -> capabilities ) ) { $ handlers [ ] = $ handler ; } } return $ handlers ; }
|
Get ESMTP handlers which are currently ok to use
|
5,746
|
public function importByteStream ( Swift_OutputByteStream $ os ) { if ( ! isset ( $ this -> charReader ) ) { $ this -> charReader = $ this -> charReaderFactory -> getReaderFor ( $ this -> charset ) ; } $ startLength = $ this -> charReader -> getInitialByteSize ( ) ; while ( false !== $ bytes = $ os -> read ( $ startLength ) ) { $ c = [ ] ; for ( $ i = 0 , $ len = strlen ( $ bytes ) ; $ i < $ len ; ++ $ i ) { $ c [ ] = self :: $ byteMap [ $ bytes [ $ i ] ] ; } $ size = count ( $ c ) ; $ need = $ this -> charReader -> validateByteSequence ( $ c , $ size ) ; if ( $ need > 0 && false !== $ bytes = $ os -> read ( $ need ) ) { for ( $ i = 0 , $ len = strlen ( $ bytes ) ; $ i < $ len ; ++ $ i ) { $ c [ ] = self :: $ byteMap [ $ bytes [ $ i ] ] ; } } $ this -> array [ ] = $ c ; ++ $ this -> array_size ; } }
|
Overwrite this character stream using the byte sequence in the byte stream .
|
5,747
|
public function getId ( ) { $ tmp = ( array ) $ this -> getHeaderFieldModel ( $ this -> getIdField ( ) ) ; return $ this -> headers -> has ( $ this -> getIdField ( ) ) ? current ( $ tmp ) : $ this -> id ; }
|
Get the CID of this entity .
|
5,748
|
public function setId ( $ id ) { if ( ! $ this -> setHeaderFieldModel ( $ this -> getIdField ( ) , $ id ) ) { $ this -> headers -> addIdHeader ( $ this -> getIdField ( ) , $ id ) ; } $ this -> id = $ id ; return $ this ; }
|
Set the CID of this entity .
|
5,749
|
public function setDescription ( $ description ) { if ( ! $ this -> setHeaderFieldModel ( 'Content-Description' , $ description ) ) { $ this -> headers -> addTextHeader ( 'Content-Description' , $ description ) ; } return $ this ; }
|
Set the description of this entity .
|
5,750
|
public function setChildren ( array $ children , $ compoundLevel = null ) { $ compoundLevel = $ compoundLevel ?? $ this -> getCompoundLevel ( $ children ) ; $ immediateChildren = [ ] ; $ grandchildren = [ ] ; $ newContentType = $ this -> userContentType ; foreach ( $ children as $ child ) { $ level = $ this -> getNeededChildLevel ( $ child , $ compoundLevel ) ; if ( empty ( $ immediateChildren ) ) { $ immediateChildren = [ $ child ] ; } else { $ nextLevel = $ this -> getNeededChildLevel ( $ immediateChildren [ 0 ] , $ compoundLevel ) ; if ( $ nextLevel == $ level ) { $ immediateChildren [ ] = $ child ; } elseif ( $ level < $ nextLevel ) { $ grandchildren = array_merge ( $ grandchildren , $ immediateChildren ) ; $ immediateChildren = [ $ child ] ; } else { $ grandchildren [ ] = $ child ; } } } if ( $ immediateChildren ) { $ lowestLevel = $ this -> getNeededChildLevel ( $ immediateChildren [ 0 ] , $ compoundLevel ) ; foreach ( $ this -> compositeRanges as $ mediaType => $ range ) { if ( $ lowestLevel > $ range [ 0 ] && $ lowestLevel <= $ range [ 1 ] ) { $ newContentType = $ mediaType ; break ; } } if ( ! empty ( $ grandchildren ) ) { $ subentity = $ this -> createChild ( ) ; $ subentity -> setNestingLevel ( $ lowestLevel ) ; $ subentity -> setChildren ( $ grandchildren , $ compoundLevel ) ; array_unshift ( $ immediateChildren , $ subentity ) ; } } $ this -> immediateChildren = $ immediateChildren ; $ this -> children = $ children ; $ this -> setContentTypeInHeaders ( $ newContentType ) ; $ this -> fixHeaders ( ) ; $ this -> sortChildren ( ) ; return $ this ; }
|
Set all children of this entity .
|
5,751
|
public function getBody ( ) { return $ this -> body instanceof Swift_OutputByteStream ? $ this -> readStream ( $ this -> body ) : $ this -> body ; }
|
Get the body of this entity as a string .
|
5,752
|
public function setEncoder ( Swift_Mime_ContentEncoder $ encoder ) { if ( $ encoder !== $ this -> encoder ) { $ this -> clearCache ( ) ; } $ this -> encoder = $ encoder ; $ this -> setEncoding ( $ encoder -> getName ( ) ) ; $ this -> notifyEncoderChanged ( $ encoder ) ; return $ this ; }
|
Set the encoder used for the body of this entity .
|
5,753
|
public function getBoundary ( ) { if ( ! isset ( $ this -> boundary ) ) { $ this -> boundary = '_=_swift_' . time ( ) . '_' . bin2hex ( random_bytes ( 16 ) ) . '_=_' ; } return $ this -> boundary ; }
|
Get the boundary used to separate children in this entity .
|
5,754
|
protected function bodyToString ( ) { $ string = '' ; if ( isset ( $ this -> body ) && empty ( $ this -> immediateChildren ) ) { if ( $ this -> cache -> hasKey ( $ this -> cacheKey , 'body' ) ) { $ body = $ this -> cache -> getString ( $ this -> cacheKey , 'body' ) ; } else { $ body = "\r\n" . $ this -> encoder -> encodeString ( $ this -> getBody ( ) , 0 , $ this -> getMaxLineLength ( ) ) ; $ this -> cache -> setString ( $ this -> cacheKey , 'body' , $ body , Swift_KeyCache :: MODE_WRITE ) ; } $ string .= $ body ; } if ( ! empty ( $ this -> immediateChildren ) ) { foreach ( $ this -> immediateChildren as $ child ) { $ string .= "\r\n\r\n--" . $ this -> getBoundary ( ) . "\r\n" ; $ string .= $ child -> toString ( ) ; } $ string .= "\r\n\r\n--" . $ this -> getBoundary ( ) . "--\r\n" ; } return $ string ; }
|
Get this entire entity as a string .
|
5,755
|
protected function fixHeaders ( ) { if ( count ( $ this -> immediateChildren ) ) { $ this -> setHeaderParameter ( 'Content-Type' , 'boundary' , $ this -> getBoundary ( ) ) ; $ this -> headers -> remove ( 'Content-Transfer-Encoding' ) ; } else { $ this -> setHeaderParameter ( 'Content-Type' , 'boundary' , null ) ; $ this -> setEncoding ( $ this -> encoder -> getName ( ) ) ; } }
|
Re - evaluate what content type and encoding should be used on this entity .
|
5,756
|
public function connect ( ) { if ( isset ( $ this -> connection ) ) { $ this -> connection -> connect ( ) ; } else { if ( ! isset ( $ this -> socket ) ) { if ( ! $ socket = fsockopen ( $ this -> getHostString ( ) , $ this -> port , $ errno , $ errstr , $ this -> timeout ) ) { throw new Swift_Plugins_Pop_Pop3Exception ( sprintf ( 'Failed to connect to POP3 host [%s]: %s' , $ this -> host , $ errstr ) ) ; } $ this -> socket = $ socket ; if ( false === $ greeting = fgets ( $ this -> socket ) ) { throw new Swift_Plugins_Pop_Pop3Exception ( sprintf ( 'Failed to connect to POP3 host [%s]' , trim ( $ greeting ) ) ) ; } $ this -> assertOk ( $ greeting ) ; if ( $ this -> username ) { $ this -> command ( sprintf ( "USER %s\r\n" , $ this -> username ) ) ; $ this -> command ( sprintf ( "PASS %s\r\n" , $ this -> password ) ) ; } } } }
|
Connect to the POP3 host and authenticate .
|
5,757
|
public function disconnect ( ) { if ( isset ( $ this -> connection ) ) { $ this -> connection -> disconnect ( ) ; } else { $ this -> command ( "QUIT\r\n" ) ; if ( ! fclose ( $ this -> socket ) ) { throw new Swift_Plugins_Pop_Pop3Exception ( sprintf ( 'POP3 host [%s] connection could not be stopped' , $ this -> host ) ) ; } $ this -> socket = null ; } }
|
Disconnect from the POP3 host .
|
5,758
|
public function setLocalDomain ( $ domain ) { if ( '[' !== substr ( $ domain , 0 , 1 ) ) { if ( filter_var ( $ domain , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { $ domain = '[' . $ domain . ']' ; } elseif ( filter_var ( $ domain , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { $ domain = '[IPv6:' . $ domain . ']' ; } } $ this -> domain = $ domain ; return $ this ; }
|
Set the name of the local domain which Swift will identify itself as .
|
5,759
|
public function start ( ) { if ( ! $ this -> started ) { if ( $ evt = $ this -> eventDispatcher -> createTransportChangeEvent ( $ this ) ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'beforeTransportStarted' ) ; if ( $ evt -> bubbleCancelled ( ) ) { return ; } } try { $ this -> buffer -> initialize ( $ this -> getBufferParams ( ) ) ; } catch ( Swift_TransportException $ e ) { $ this -> throwException ( $ e ) ; } $ this -> readGreeting ( ) ; $ this -> doHeloCommand ( ) ; if ( $ evt ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'transportStarted' ) ; } $ this -> started = true ; } }
|
Start the SMTP connection .
|
5,760
|
public function stop ( ) { if ( $ this -> started ) { if ( $ evt = $ this -> eventDispatcher -> createTransportChangeEvent ( $ this ) ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'beforeTransportStopped' ) ; if ( $ evt -> bubbleCancelled ( ) ) { return ; } } try { $ this -> executeCommand ( "QUIT\r\n" , [ 221 ] ) ; } catch ( Swift_TransportException $ e ) { } try { $ this -> buffer -> terminate ( ) ; if ( $ evt ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'transportStopped' ) ; } } catch ( Swift_TransportException $ e ) { $ this -> throwException ( $ e ) ; } } $ this -> started = false ; }
|
Stop the SMTP connection .
|
5,761
|
protected function doMailFromCommand ( $ address ) { $ address = $ this -> addressEncoder -> encodeString ( $ address ) ; $ this -> executeCommand ( sprintf ( "MAIL FROM:<%s>\r\n" , $ address ) , [ 250 ] , $ failures , true ) ; }
|
Send the MAIL FROM command
|
5,762
|
protected function streamMessage ( Swift_Mime_SimpleMessage $ message ) { $ this -> buffer -> setWriteTranslations ( [ "\r\n." => "\r\n.." ] ) ; try { $ message -> toByteStream ( $ this -> buffer ) ; $ this -> buffer -> flushBuffers ( ) ; } catch ( Swift_TransportException $ e ) { $ this -> throwException ( $ e ) ; } $ this -> buffer -> setWriteTranslations ( [ ] ) ; $ this -> executeCommand ( "\r\n.\r\n" , [ 250 ] ) ; }
|
Stream the contents of the message over the buffer
|
5,763
|
protected function throwException ( Swift_TransportException $ e ) { if ( $ evt = $ this -> eventDispatcher -> createTransportExceptionEvent ( $ this , $ e ) ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'exceptionThrown' ) ; if ( ! $ evt -> bubbleCancelled ( ) ) { throw $ e ; } } else { throw $ e ; } }
|
Throw a TransportException first sending it to any listeners
|
5,764
|
protected function assertResponseCode ( $ response , $ wanted ) { if ( ! $ response ) { $ this -> throwException ( new Swift_TransportException ( 'Expected response code ' . implode ( '/' , $ wanted ) . ' but got an empty response' ) ) ; } list ( $ code ) = sscanf ( $ response , '%3d' ) ; $ valid = ( empty ( $ wanted ) || in_array ( $ code , $ wanted ) ) ; if ( $ evt = $ this -> eventDispatcher -> createResponseEvent ( $ this , $ response , $ valid ) ) { $ this -> eventDispatcher -> dispatchEvent ( $ evt , 'responseReceived' ) ; } if ( ! $ valid ) { $ this -> throwException ( new Swift_TransportException ( 'Expected response code ' . implode ( '/' , $ wanted ) . ' but got code "' . $ code . '", with message "' . $ response . '"' , $ code ) ) ; } }
|
Throws an Exception if a response code is incorrect
|
5,765
|
protected function getFullResponse ( $ seq ) { $ response = '' ; try { do { $ line = $ this -> buffer -> readLine ( $ seq ) ; $ response .= $ line ; } while ( null !== $ line && false !== $ line && ' ' != $ line [ 3 ] ) ; } catch ( Swift_TransportException $ e ) { $ this -> throwException ( $ e ) ; } catch ( Swift_IoException $ e ) { $ this -> throwException ( new Swift_TransportException ( $ e -> getMessage ( ) , 0 , $ e ) ) ; } return $ response ; }
|
Get an entire multi - line response using its sequence number
|
5,766
|
private function doMailTransaction ( $ message , $ reversePath , array $ recipients , array & $ failedRecipients ) { $ sent = 0 ; $ this -> doMailFromCommand ( $ reversePath ) ; foreach ( $ recipients as $ forwardPath ) { try { $ this -> doRcptToCommand ( $ forwardPath ) ; ++ $ sent ; } catch ( Swift_TransportException $ e ) { $ failedRecipients [ ] = $ forwardPath ; } catch ( Swift_AddressEncoderException $ e ) { $ failedRecipients [ ] = $ forwardPath ; } } if ( 0 != $ sent ) { $ sent += count ( $ failedRecipients ) ; $ this -> doDataCommand ( $ failedRecipients ) ; $ sent -= count ( $ failedRecipients ) ; $ this -> streamMessage ( $ message ) ; } else { $ this -> reset ( ) ; } return $ sent ; }
|
Send an email to the given recipients from the given reverse path
|
5,767
|
public function createIdHeader ( $ name , $ ids = null ) { $ header = new Swift_Mime_Headers_IdentificationHeader ( $ name , $ this -> emailValidator ) ; if ( isset ( $ ids ) ) { $ header -> setFieldBodyModel ( $ ids ) ; } $ this -> setHeaderCharset ( $ header ) ; return $ header ; }
|
Create a new ID header for Message - ID or Content - ID .
|
5,768
|
public function charsetChanged ( $ charset ) { $ this -> charset = $ charset ; $ this -> encoder -> charsetChanged ( $ charset ) ; $ this -> paramEncoder -> charsetChanged ( $ charset ) ; }
|
Notify this observer that the entity s charset has changed .
|
5,769
|
private function setHeaderCharset ( Swift_Mime_Header $ header ) { if ( isset ( $ this -> charset ) ) { $ header -> setCharset ( $ this -> charset ) ; } }
|
Apply the charset to the Header
|
5,770
|
public function shouldBuffer ( $ buffer ) { if ( '' === $ buffer ) { return false ; } $ endOfBuffer = substr ( $ buffer , - 1 ) ; foreach ( ( array ) $ this -> search as $ needle ) { if ( false !== strpos ( $ needle , $ endOfBuffer ) ) { return true ; } } return false ; }
|
Returns true if based on the buffer passed more bytes should be buffered .
|
5,771
|
private function filterHeaderSet ( Swift_Mime_SimpleHeaderSet $ headerSet , $ type ) { foreach ( $ headerSet -> getAll ( $ type ) as $ headers ) { $ headers -> setNameAddresses ( $ this -> filterNameAddresses ( $ headers -> getNameAddresses ( ) ) ) ; } }
|
Filter header set against a whitelist of regular expressions .
|
5,772
|
private function filterNameAddresses ( array $ recipients ) { $ filtered = [ ] ; foreach ( $ recipients as $ address => $ name ) { if ( $ this -> isWhitelisted ( $ address ) ) { $ filtered [ $ address ] = $ name ; } } return $ filtered ; }
|
Filtered list of addresses = > name pairs .
|
5,773
|
protected function isWhitelisted ( $ recipient ) { if ( in_array ( $ recipient , ( array ) $ this -> recipient ) ) { return true ; } foreach ( $ this -> whitelist as $ pattern ) { if ( preg_match ( $ pattern , $ recipient ) ) { return true ; } } return false ; }
|
Matches address against whitelist of regular expressions .
|
5,774
|
public function setSignCertificate ( $ certificate , $ privateKey = null , $ signOptions = PKCS7_DETACHED , $ extraCerts = null ) { $ this -> signCertificate = 'file://' . str_replace ( '\\' , '/' , realpath ( $ certificate ) ) ; if ( null !== $ privateKey ) { if ( is_array ( $ privateKey ) ) { $ this -> signPrivateKey = $ privateKey ; $ this -> signPrivateKey [ 0 ] = 'file://' . str_replace ( '\\' , '/' , realpath ( $ privateKey [ 0 ] ) ) ; } else { $ this -> signPrivateKey = 'file://' . str_replace ( '\\' , '/' , realpath ( $ privateKey ) ) ; } } $ this -> signOptions = $ signOptions ; $ this -> extraCerts = $ extraCerts ? realpath ( $ extraCerts ) : null ; return $ this ; }
|
Set the certificate location to use for signing .
|
5,775
|
public function setEncryptCertificate ( $ recipientCerts , $ cipher = null ) { if ( is_array ( $ recipientCerts ) ) { $ this -> encryptCert = [ ] ; foreach ( $ recipientCerts as $ cert ) { $ this -> encryptCert [ ] = 'file://' . str_replace ( '\\' , '/' , realpath ( $ cert ) ) ; } } else { $ this -> encryptCert = 'file://' . str_replace ( '\\' , '/' , realpath ( $ recipientCerts ) ) ; } if ( null !== $ cipher ) { $ this -> encryptCipher = $ cipher ; } return $ this ; }
|
Set the certificate location to use for encryption .
|
5,776
|
public function signMessage ( Swift_Message $ message ) { if ( null === $ this -> signCertificate && null === $ this -> encryptCert ) { return $ this ; } if ( $ this -> signThenEncrypt ) { $ this -> smimeSignMessage ( $ message ) ; $ this -> smimeEncryptMessage ( $ message ) ; } else { $ this -> smimeEncryptMessage ( $ message ) ; $ this -> smimeSignMessage ( $ message ) ; } }
|
Change the Swift_Message to apply the signing .
|
5,777
|
protected function smimeSignMessage ( Swift_Message $ message ) { if ( null === $ this -> signCertificate ) { return ; } $ signMessage = clone $ message ; $ signMessage -> clearSigners ( ) ; if ( $ this -> wrapFullMessage ) { $ signMessage = $ this -> wrapMimeMessage ( $ signMessage ) ; } else { $ this -> clearAllHeaders ( $ signMessage ) ; $ this -> copyHeaders ( $ message , $ signMessage , [ 'Content-Type' , 'Content-Transfer-Encoding' , 'Content-Disposition' , ] ) ; } $ messageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; $ signMessage -> toByteStream ( $ messageStream ) ; $ messageStream -> commit ( ) ; $ signedMessageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; if ( ! openssl_pkcs7_sign ( $ messageStream -> getPath ( ) , $ signedMessageStream -> getPath ( ) , $ this -> signCertificate , $ this -> signPrivateKey , [ ] , $ this -> signOptions , $ this -> extraCerts ) ) { throw new Swift_IoException ( sprintf ( 'Failed to sign S/Mime message. Error: "%s".' , openssl_error_string ( ) ) ) ; } $ this -> parseSSLOutput ( $ signedMessageStream , $ message ) ; }
|
Sign a Swift message .
|
5,778
|
protected function smimeEncryptMessage ( Swift_Message $ message ) { if ( null === $ this -> encryptCert ) { return ; } $ encryptMessage = clone $ message ; $ encryptMessage -> clearSigners ( ) ; if ( $ this -> wrapFullMessage ) { $ encryptMessage = $ this -> wrapMimeMessage ( $ encryptMessage ) ; } else { $ this -> clearAllHeaders ( $ encryptMessage ) ; $ this -> copyHeaders ( $ message , $ encryptMessage , [ 'Content-Type' , 'Content-Transfer-Encoding' , 'Content-Disposition' , ] ) ; } $ messageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; $ encryptMessage -> toByteStream ( $ messageStream ) ; $ messageStream -> commit ( ) ; $ encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; if ( ! openssl_pkcs7_encrypt ( $ messageStream -> getPath ( ) , $ encryptedMessageStream -> getPath ( ) , $ this -> encryptCert , [ ] , 0 , $ this -> encryptCipher ) ) { throw new Swift_IoException ( sprintf ( 'Failed to encrypt S/Mime message. Error: "%s".' , openssl_error_string ( ) ) ) ; } $ this -> parseSSLOutput ( $ encryptedMessageStream , $ message ) ; }
|
Encrypt a Swift message .
|
5,779
|
protected function copyHeaders ( Swift_Message $ fromMessage , Swift_Message $ toMessage , array $ headers = [ ] ) { foreach ( $ headers as $ header ) { $ this -> copyHeader ( $ fromMessage , $ toMessage , $ header ) ; } }
|
Copy named headers from one Swift message to another .
|
5,780
|
protected function copyHeader ( Swift_Message $ fromMessage , Swift_Message $ toMessage , $ headerName ) { $ header = $ fromMessage -> getHeaders ( ) -> get ( $ headerName ) ; if ( ! $ header ) { return ; } $ headers = $ toMessage -> getHeaders ( ) ; switch ( $ header -> getFieldType ( ) ) { case Swift_Mime_Header :: TYPE_TEXT : $ headers -> addTextHeader ( $ header -> getFieldName ( ) , $ header -> getValue ( ) ) ; break ; case Swift_Mime_Header :: TYPE_PARAMETERIZED : $ headers -> addParameterizedHeader ( $ header -> getFieldName ( ) , $ header -> getValue ( ) , $ header -> getParameters ( ) ) ; break ; } }
|
Copy a single header from one Swift message to another .
|
5,781
|
protected function clearAllHeaders ( Swift_Message $ message ) { $ headers = $ message -> getHeaders ( ) ; foreach ( $ headers -> listAll ( ) as $ header ) { $ headers -> removeAll ( $ header ) ; } }
|
Remove all headers from a Swift message .
|
5,782
|
protected function streamToMime ( Swift_OutputByteStream $ fromStream , Swift_Message $ message ) { list ( $ headers , $ messageStream ) = $ this -> parseStream ( $ fromStream ) ; $ messageHeaders = $ message -> getHeaders ( ) ; $ encoding = '' ; $ messageHeaders -> removeAll ( 'Content-Transfer-Encoding' ) ; if ( isset ( $ headers [ 'content-transfer-encoding' ] ) ) { $ encoding = $ headers [ 'content-transfer-encoding' ] ; } $ message -> setEncoder ( new Swift_Mime_ContentEncoder_NullContentEncoder ( $ encoding ) ) ; if ( isset ( $ headers [ 'content-disposition' ] ) ) { $ messageHeaders -> addTextHeader ( 'Content-Disposition' , $ headers [ 'content-disposition' ] ) ; } $ message -> setChildren ( [ ] ) ; $ message -> setBody ( $ messageStream , $ headers [ 'content-type' ] ) ; }
|
Merges an OutputByteStream from OpenSSL to a Swift_Message .
|
5,783
|
protected function parseStream ( Swift_OutputByteStream $ emailStream ) { $ bufferLength = 78 ; $ headerData = '' ; $ headerBodySeparator = "\r\n\r\n" ; $ emailStream -> setReadPointer ( 0 ) ; while ( false !== ( $ buffer = $ emailStream -> read ( $ bufferLength ) ) ) { $ headerData .= $ buffer ; $ headersPosEnd = strpos ( $ headerData , $ headerBodySeparator ) ; if ( false !== $ headersPosEnd ) { break ; } } $ headerData = trim ( substr ( $ headerData , 0 , $ headersPosEnd ) ) ; $ headerLines = explode ( "\r\n" , $ headerData ) ; unset ( $ headerData ) ; $ headers = [ ] ; $ currentHeaderName = '' ; foreach ( $ headerLines as $ headerLine ) { if ( false === strpos ( $ headerLine , ':' ) ) { $ headers [ $ currentHeaderName ] .= ' ' . trim ( $ headerLine ) ; continue ; } $ header = explode ( ':' , $ headerLine , 2 ) ; $ currentHeaderName = strtolower ( $ header [ 0 ] ) ; $ headers [ $ currentHeaderName ] = trim ( $ header [ 1 ] ) ; } $ bodyStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; $ emailStream -> setReadPointer ( $ headersPosEnd + strlen ( $ headerBodySeparator ) ) ; while ( false !== ( $ buffer = $ emailStream -> read ( $ bufferLength ) ) ) { $ bodyStream -> write ( $ buffer ) ; } $ bodyStream -> commit ( ) ; return [ $ headers , $ bodyStream ] ; }
|
This message will parse the headers of a MIME email byte stream and return an array that contains the headers as an associative array and the email body as a string .
|
5,784
|
public function setCharset ( $ charset ) { $ this -> setHeaderParameter ( 'Content-Type' , 'charset' , $ charset ) ; if ( $ charset !== $ this -> userCharset ) { $ this -> clearCache ( ) ; } $ this -> userCharset = $ charset ; parent :: charsetChanged ( $ charset ) ; return $ this ; }
|
Set the character set of this entity .
|
5,785
|
public function setDelSp ( $ delsp = true ) { $ this -> setHeaderParameter ( 'Content-Type' , 'delsp' , $ delsp ? 'yes' : null ) ; $ this -> userDelSp = $ delsp ; return $ this ; }
|
Turn delsp on or off for this entity .
|
5,786
|
protected function fixHeaders ( ) { parent :: fixHeaders ( ) ; if ( count ( $ this -> getChildren ( ) ) ) { $ this -> setHeaderParameter ( 'Content-Type' , 'charset' , null ) ; $ this -> setHeaderParameter ( 'Content-Type' , 'format' , null ) ; $ this -> setHeaderParameter ( 'Content-Type' , 'delsp' , null ) ; } else { $ this -> setCharset ( $ this -> userCharset ) ; $ this -> setFormat ( $ this -> userFormat ) ; $ this -> setDelSp ( $ this -> userDelSp ) ; } }
|
Fix the content - type and encoding of this entity
|
5,787
|
protected function convertString ( $ string ) { $ charset = strtolower ( $ this -> getCharset ( ) ) ; if ( ! in_array ( $ charset , [ 'utf-8' , 'iso-8859-1' , 'iso-8859-15' , '' ] ) ) { return mb_convert_encoding ( $ string , $ charset , 'utf-8' ) ; } return $ string ; }
|
Encode charset when charset is not utf - 8
|
5,788
|
protected function sendCacheControlHeader ( ) { if ( Yii :: app ( ) -> session -> isStarted ) { Yii :: app ( ) -> session -> setCacheLimiter ( 'public' ) ; header ( 'Pragma:' , true ) ; } header ( 'Cache-Control: ' . $ this -> cacheControl , true ) ; }
|
Sends the cache control header to the client
|
5,789
|
protected function getViewFile ( $ file ) { if ( $ this -> useRuntimePath ) { $ crc = sprintf ( '%x' , crc32 ( get_class ( $ this ) . Yii :: getVersion ( ) . dirname ( $ file ) ) ) ; $ viewFile = Yii :: app ( ) -> getRuntimePath ( ) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $ crc . DIRECTORY_SEPARATOR . basename ( $ file ) ; if ( ! is_file ( $ viewFile ) ) @ mkdir ( dirname ( $ viewFile ) , $ this -> filePermission , true ) ; return $ viewFile ; } else return $ file . 'c' ; }
|
Generates the resulting view file path .
|
5,790
|
public function up ( ) { $ transaction = $ this -> getDbConnection ( ) -> beginTransaction ( ) ; try { if ( $ this -> safeUp ( ) === false ) { $ transaction -> rollback ( ) ; return false ; } $ transaction -> commit ( ) ; } catch ( Exception $ e ) { echo "Exception: " . $ e -> getMessage ( ) . ' (' . $ e -> getFile ( ) . ':' . $ e -> getLine ( ) . ")\n" ; echo $ e -> getTraceAsString ( ) . "\n" ; $ transaction -> rollback ( ) ; return false ; } }
|
This method contains the logic to be executed when applying this migration . Child classes may implement this method to provide actual migration logic .
|
5,791
|
public function down ( ) { $ transaction = $ this -> getDbConnection ( ) -> beginTransaction ( ) ; try { if ( $ this -> safeDown ( ) === false ) { $ transaction -> rollback ( ) ; return false ; } $ transaction -> commit ( ) ; } catch ( Exception $ e ) { echo "Exception: " . $ e -> getMessage ( ) . ' (' . $ e -> getFile ( ) . ':' . $ e -> getLine ( ) . ")\n" ; echo $ e -> getTraceAsString ( ) . "\n" ; $ transaction -> rollback ( ) ; return false ; } }
|
This method contains the logic to be executed when removing this migration . Child classes may override this method if the corresponding migrations can be removed .
|
5,792
|
public function insert ( $ table , $ columns ) { echo " > insert into $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> insert ( $ table , $ columns ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Creates and executes an INSERT SQL statement . The method will properly escape the column names and bind the values to be inserted .
|
5,793
|
public function insertMultiple ( $ table , $ data ) { echo " > insert into $table ..." ; $ time = microtime ( true ) ; $ builder = $ this -> getDbConnection ( ) -> getSchema ( ) -> getCommandBuilder ( ) ; $ command = $ builder -> createMultipleInsertCommand ( $ table , $ data ) ; $ command -> execute ( ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Creates and executes an INSERT SQL statement with multiple data . The method will properly escape the column names and bind the values to be inserted .
|
5,794
|
public function update ( $ table , $ columns , $ conditions = '' , $ params = array ( ) ) { echo " > update $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> update ( $ table , $ columns , $ conditions , $ params ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Creates and executes an UPDATE SQL statement . The method will properly escape the column names and bind the values to be updated .
|
5,795
|
public function delete ( $ table , $ conditions = '' , $ params = array ( ) ) { echo " > delete from $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> delete ( $ table , $ conditions , $ params ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Creates and executes a DELETE SQL statement .
|
5,796
|
public function createTable ( $ table , $ columns , $ options = null ) { echo " > create table $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> createTable ( $ table , $ columns , $ options ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Builds and executes a SQL statement for creating a new DB table .
|
5,797
|
public function renameTable ( $ table , $ newName ) { echo " > rename table $table to $newName ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> renameTable ( $ table , $ newName ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Builds and executes a SQL statement for renaming a DB table .
|
5,798
|
public function dropColumn ( $ table , $ column ) { echo " > drop column $column from table $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> dropColumn ( $ table , $ column ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Builds and executes a SQL statement for dropping a DB column .
|
5,799
|
public function renameColumn ( $ table , $ name , $ newName ) { echo " > rename column $name in table $table to $newName ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> renameColumn ( $ table , $ name , $ newName ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
|
Builds and executes a SQL statement for renaming a column .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.