repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/StreamBuffer.php
|
Swift_Transport_StreamBuffer.establishSocketConnection
|
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;
}
|
php
|
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;
}
|
[
"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.
|
[
"Establishes",
"a",
"connection",
"to",
"a",
"remote",
"server",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/StreamBuffer.php#L248-L282
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.sendMessage1
|
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]);
}
|
php
|
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]);
}
|
[
"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.
@return string SMTP Response
|
[
"Send",
"our",
"auth",
"message",
"and",
"returns",
"the",
"response",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L99-L104
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.readSubBlock
|
protected function readSubBlock($block)
{
// remove terminatorByte cause it's always the same
$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;
}
|
php
|
protected function readSubBlock($block)
{
// remove terminatorByte cause it's always the same
$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;
}
|
[
"protected",
"function",
"readSubBlock",
"(",
"$",
"block",
")",
"{",
"// remove terminatorByte cause it's always the same",
"$",
"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.
@return array
|
[
"Read",
"the",
"blob",
"information",
"in",
"from",
"message2",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L145-L168
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.sendMessage3
|
protected function sendMessage3($response, $username, $password, $timestamp, $client, Swift_Transport_SmtpAgent $agent, $v2 = true)
{
list($domain, $username) = $this->getDomainAndUsername($username);
//$challenge, $context, $targetInfoH, $targetName, $domainName, $workstation, $DNSDomainName, $DNSServerName, $blob, $ter
list($challenge, , , , , $workstation, , , $blob) = $this->parseMessage2($response);
if (!$v2) {
// LMv1
$lmResponse = $this->createLMPassword($password, $challenge);
// NTLMv1
$ntlmResponse = $this->createNTLMPassword($password, $challenge);
} else {
// LMv2
$lmResponse = $this->createLMv2Password($password, $username, $domain, $challenge, $client);
// NTLMv2
$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]);
}
|
php
|
protected function sendMessage3($response, $username, $password, $timestamp, $client, Swift_Transport_SmtpAgent $agent, $v2 = true)
{
list($domain, $username) = $this->getDomainAndUsername($username);
//$challenge, $context, $targetInfoH, $targetName, $domainName, $workstation, $DNSDomainName, $DNSServerName, $blob, $ter
list($challenge, , , , , $workstation, , , $blob) = $this->parseMessage2($response);
if (!$v2) {
// LMv1
$lmResponse = $this->createLMPassword($password, $challenge);
// NTLMv1
$ntlmResponse = $this->createNTLMPassword($password, $challenge);
} else {
// LMv2
$lmResponse = $this->createLMv2Password($password, $username, $domain, $challenge, $client);
// NTLMv2
$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]);
}
|
[
"protected",
"function",
"sendMessage3",
"(",
"$",
"response",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"timestamp",
",",
"$",
"client",
",",
"Swift_Transport_SmtpAgent",
"$",
"agent",
",",
"$",
"v2",
"=",
"true",
")",
"{",
"list",
"(",
"$",
"domain",
",",
"$",
"username",
")",
"=",
"$",
"this",
"->",
"getDomainAndUsername",
"(",
"$",
"username",
")",
";",
"//$challenge, $context, $targetInfoH, $targetName, $domainName, $workstation, $DNSDomainName, $DNSServerName, $blob, $ter",
"list",
"(",
"$",
"challenge",
",",
",",
",",
",",
",",
"$",
"workstation",
",",
",",
",",
"$",
"blob",
")",
"=",
"$",
"this",
"->",
"parseMessage2",
"(",
"$",
"response",
")",
";",
"if",
"(",
"!",
"$",
"v2",
")",
"{",
"// LMv1",
"$",
"lmResponse",
"=",
"$",
"this",
"->",
"createLMPassword",
"(",
"$",
"password",
",",
"$",
"challenge",
")",
";",
"// NTLMv1",
"$",
"ntlmResponse",
"=",
"$",
"this",
"->",
"createNTLMPassword",
"(",
"$",
"password",
",",
"$",
"challenge",
")",
";",
"}",
"else",
"{",
"// LMv2",
"$",
"lmResponse",
"=",
"$",
"this",
"->",
"createLMv2Password",
"(",
"$",
"password",
",",
"$",
"username",
",",
"$",
"domain",
",",
"$",
"challenge",
",",
"$",
"client",
")",
";",
"// NTLMv2",
"$",
"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.
@param string $response Message 1 response (message 2)
@param string $username
@param string $password
@param string $timestamp
@param string $client
@param bool $v2 Use version2 of the protocol
@return string
|
[
"Send",
"our",
"final",
"message",
"with",
"all",
"our",
"data",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L182-L203
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createMessage3
|
protected function createMessage3($domain, $username, $workstation, $lmResponse, $ntlmResponse)
{
// Create security buffers
$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') // TYPE 3 message
.$lmSec // LM response header
.$ntlmSec // NTLM response header
.$domainSec // Domain header
.$userSec // User header
.$workSec // Workstation header
.$this->createByte('000000009a', 8) // session key header (empty)
.$this->createByte('01020000') // FLAGS
.$this->convertTo16bit($domain) // domain name
.$this->convertTo16bit($username) // username
.$this->convertTo16bit($workstation) // workstation
.$lmResponse
.$ntlmResponse;
}
|
php
|
protected function createMessage3($domain, $username, $workstation, $lmResponse, $ntlmResponse)
{
// Create security buffers
$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') // TYPE 3 message
.$lmSec // LM response header
.$ntlmSec // NTLM response header
.$domainSec // Domain header
.$userSec // User header
.$workSec // Workstation header
.$this->createByte('000000009a', 8) // session key header (empty)
.$this->createByte('01020000') // FLAGS
.$this->convertTo16bit($domain) // domain name
.$this->convertTo16bit($username) // username
.$this->convertTo16bit($workstation) // workstation
.$lmResponse
.$ntlmResponse;
}
|
[
"protected",
"function",
"createMessage3",
"(",
"$",
"domain",
",",
"$",
"username",
",",
"$",
"workstation",
",",
"$",
"lmResponse",
",",
"$",
"ntlmResponse",
")",
"{",
"// Create security buffers",
"$",
"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'",
")",
"// TYPE 3 message",
".",
"$",
"lmSec",
"// LM response header",
".",
"$",
"ntlmSec",
"// NTLM response header",
".",
"$",
"domainSec",
"// Domain header",
".",
"$",
"userSec",
"// User header",
".",
"$",
"workSec",
"// Workstation header",
".",
"$",
"this",
"->",
"createByte",
"(",
"'000000009a'",
",",
"8",
")",
"// session key header (empty)",
".",
"$",
"this",
"->",
"createByte",
"(",
"'01020000'",
")",
"// FLAGS",
".",
"$",
"this",
"->",
"convertTo16bit",
"(",
"$",
"domain",
")",
"// domain name",
".",
"$",
"this",
"->",
"convertTo16bit",
"(",
"$",
"username",
")",
"// username",
".",
"$",
"this",
"->",
"convertTo16bit",
"(",
"$",
"workstation",
")",
"// workstation",
".",
"$",
"lmResponse",
".",
"$",
"ntlmResponse",
";",
"}"
] |
Create our message 3.
@param string $domain
@param string $username
@param string $workstation
@param string $lmResponse
@param string $ntlmResponse
@return string
|
[
"Create",
"our",
"message",
"3",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L228-L255
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.getDomainAndUsername
|
protected function getDomainAndUsername($name)
{
if (false !== strpos($name, '\\')) {
return explode('\\', $name);
}
if (false !== strpos($name, '@')) {
list($user, $domain) = explode('@', $name);
return [$domain, $user];
}
// no domain passed
return ['', $name];
}
|
php
|
protected function getDomainAndUsername($name)
{
if (false !== strpos($name, '\\')) {
return explode('\\', $name);
}
if (false !== strpos($name, '@')) {
list($user, $domain) = explode('@', $name);
return [$domain, $user];
}
// no domain passed
return ['', $name];
}
|
[
"protected",
"function",
"getDomainAndUsername",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"name",
",",
"'\\\\'",
")",
")",
"{",
"return",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"name",
",",
"'@'",
")",
")",
"{",
"list",
"(",
"$",
"user",
",",
"$",
"domain",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"name",
")",
";",
"return",
"[",
"$",
"domain",
",",
"$",
"user",
"]",
";",
"}",
"// no domain passed",
"return",
"[",
"''",
",",
"$",
"name",
"]",
";",
"}"
] |
Get domain and username from our username.
@example DOMAIN\username
@param string $name
@return array
|
[
"Get",
"domain",
"and",
"username",
"from",
"our",
"username",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L284-L298
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createLMPassword
|
protected function createLMPassword($password, $challenge)
{
// FIRST PART
$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);
// SECOND PART
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);
}
|
php
|
protected function createLMPassword($password, $challenge)
{
// FIRST PART
$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);
// SECOND PART
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);
}
|
[
"protected",
"function",
"createLMPassword",
"(",
"$",
"password",
",",
"$",
"challenge",
")",
"{",
"// FIRST PART",
"$",
"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",
")",
";",
"// SECOND PART",
"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.
@param string $password
@param string $challenge
@return string
|
[
"Create",
"LMv1",
"response",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L308-L327
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createNTLMPassword
|
protected function createNTLMPassword($password, $challenge)
{
// FIRST PART
$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);
}
|
php
|
protected function createNTLMPassword($password, $challenge)
{
// FIRST PART
$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);
}
|
[
"protected",
"function",
"createNTLMPassword",
"(",
"$",
"password",
",",
"$",
"challenge",
")",
"{",
"// FIRST PART",
"$",
"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.
@param string $password
@param string $challenge
@return string
|
[
"Create",
"NTLMv1",
"response",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L337-L348
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.getCorrectTimestamp
|
protected function getCorrectTimestamp($time)
{
// Get our timestamp (tricky!)
$time = number_format($time, 0, '.', ''); // save microtime to string
$time = bcadd($time, '11644473600000', 0); // add epoch time
$time = bcmul($time, 10000, 0); // tenths of a microsecond.
$binary = $this->si2bin($time, 64); // create 64 bit binary string
$timestamp = '';
for ($i = 0; $i < 8; ++$i) {
$timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8)));
}
return $timestamp;
}
|
php
|
protected function getCorrectTimestamp($time)
{
// Get our timestamp (tricky!)
$time = number_format($time, 0, '.', ''); // save microtime to string
$time = bcadd($time, '11644473600000', 0); // add epoch time
$time = bcmul($time, 10000, 0); // tenths of a microsecond.
$binary = $this->si2bin($time, 64); // create 64 bit binary string
$timestamp = '';
for ($i = 0; $i < 8; ++$i) {
$timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8)));
}
return $timestamp;
}
|
[
"protected",
"function",
"getCorrectTimestamp",
"(",
"$",
"time",
")",
"{",
"// Get our timestamp (tricky!)",
"$",
"time",
"=",
"number_format",
"(",
"$",
"time",
",",
"0",
",",
"'.'",
",",
"''",
")",
";",
"// save microtime to string",
"$",
"time",
"=",
"bcadd",
"(",
"$",
"time",
",",
"'11644473600000'",
",",
"0",
")",
";",
"// add epoch time",
"$",
"time",
"=",
"bcmul",
"(",
"$",
"time",
",",
"10000",
",",
"0",
")",
";",
"// tenths of a microsecond.",
"$",
"binary",
"=",
"$",
"this",
"->",
"si2bin",
"(",
"$",
"time",
",",
"64",
")",
";",
"// create 64 bit binary string",
"$",
"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.
@param string $time
@return string
|
[
"Convert",
"a",
"normal",
"timestamp",
"to",
"a",
"tenth",
"of",
"a",
"microtime",
"epoch",
"time",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L357-L371
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createLMv2Password
|
protected function createLMv2Password($password, $username, $domain, $challenge, $client)
{
$lmPass = '00'; // by default 00
// if $password > 15 than we can't use this method
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);
}
|
php
|
protected function createLMv2Password($password, $username, $domain, $challenge, $client)
{
$lmPass = '00'; // by default 00
// if $password > 15 than we can't use this method
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);
}
|
[
"protected",
"function",
"createLMv2Password",
"(",
"$",
"password",
",",
"$",
"username",
",",
"$",
"domain",
",",
"$",
"challenge",
",",
"$",
"client",
")",
"{",
"$",
"lmPass",
"=",
"'00'",
";",
"// by default 00",
"// if $password > 15 than we can't use this method",
"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.
@param string $password
@param string $username
@param string $domain
@param string $challenge NTLM Challenge
@param string $client Random string
@return string
|
[
"Create",
"LMv2",
"response",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L384-L396
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createNTLMv2Hash
|
protected function createNTLMv2Hash($password, $username, $domain, $challenge, $targetInfo, $timestamp, $client)
{
$ntlmHash = $this->md4Encrypt($password);
$ntml2Hash = $this->md5Encrypt($ntlmHash, $this->convertTo16bit(strtoupper($username).$domain));
// create blob
$blob = $this->createBlob($timestamp, $client, $targetInfo);
$ntlmv2Response = $this->md5Encrypt($ntml2Hash, $challenge.$blob);
return $ntlmv2Response.$blob;
}
|
php
|
protected function createNTLMv2Hash($password, $username, $domain, $challenge, $targetInfo, $timestamp, $client)
{
$ntlmHash = $this->md4Encrypt($password);
$ntml2Hash = $this->md5Encrypt($ntlmHash, $this->convertTo16bit(strtoupper($username).$domain));
// create blob
$blob = $this->createBlob($timestamp, $client, $targetInfo);
$ntlmv2Response = $this->md5Encrypt($ntml2Hash, $challenge.$blob);
return $ntlmv2Response.$blob;
}
|
[
"protected",
"function",
"createNTLMv2Hash",
"(",
"$",
"password",
",",
"$",
"username",
",",
"$",
"domain",
",",
"$",
"challenge",
",",
"$",
"targetInfo",
",",
"$",
"timestamp",
",",
"$",
"client",
")",
"{",
"$",
"ntlmHash",
"=",
"$",
"this",
"->",
"md4Encrypt",
"(",
"$",
"password",
")",
";",
"$",
"ntml2Hash",
"=",
"$",
"this",
"->",
"md5Encrypt",
"(",
"$",
"ntlmHash",
",",
"$",
"this",
"->",
"convertTo16bit",
"(",
"strtoupper",
"(",
"$",
"username",
")",
".",
"$",
"domain",
")",
")",
";",
"// create blob",
"$",
"blob",
"=",
"$",
"this",
"->",
"createBlob",
"(",
"$",
"timestamp",
",",
"$",
"client",
",",
"$",
"targetInfo",
")",
";",
"$",
"ntlmv2Response",
"=",
"$",
"this",
"->",
"md5Encrypt",
"(",
"$",
"ntml2Hash",
",",
"$",
"challenge",
".",
"$",
"blob",
")",
";",
"return",
"$",
"ntlmv2Response",
".",
"$",
"blob",
";",
"}"
] |
Create NTLMv2 response.
@param string $password
@param string $username
@param string $domain
@param string $challenge Hex values
@param string $targetInfo Hex values
@param string $timestamp
@param string $client Random bytes
@return string
@see http://davenport.sourceforge.net/ntlm.html#theNtlmResponse
|
[
"Create",
"NTLMv2",
"response",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L413-L424
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createSecurityBuffer
|
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);
}
|
php
|
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);
}
|
[
"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.
@param string $value Value we want to put in
@param int $offset start of value
@param bool $is16 Do we 16bit string or not?
@return string
|
[
"Create",
"our",
"security",
"buffer",
"depending",
"on",
"length",
"and",
"offset",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L466-L473
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.readSecurityBuffer
|
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];
}
|
php
|
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];
}
|
[
"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.
@param string $value Securitybuffer in hex
@return array array with length and offset
|
[
"Read",
"our",
"security",
"buffer",
"to",
"fetch",
"length",
"and",
"offset",
"of",
"our",
"value",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L482-L488
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.createByte
|
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;
}
|
php
|
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;
}
|
[
"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.
@param string $input
@param int $bytes Length of bytes
@param bool $isHex Did we provided hex value
@return string
|
[
"Right",
"padding",
"with",
"0",
"to",
"certain",
"length",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L529-L538
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.md5Encrypt
|
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))));
}
|
php
|
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))));
}
|
[
"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.
@param string $key Encryption key
@param string $msg Message to encrypt
@return string
|
[
"MD5",
"Encryption",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L563-L575
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php
|
Swift_Transport_Esmtp_Auth_NTLMAuthenticator.md4Encrypt
|
protected function md4Encrypt($input)
{
$input = $this->convertTo16bit($input);
return function_exists('hash') ? hex2bin(hash('md4', $input)) : mhash(MHASH_MD4, $input);
}
|
php
|
protected function md4Encrypt($input)
{
$input = $this->convertTo16bit($input);
return function_exists('hash') ? hex2bin(hash('md4', $input)) : mhash(MHASH_MD4, $input);
}
|
[
"protected",
"function",
"md4Encrypt",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"convertTo16bit",
"(",
"$",
"input",
")",
";",
"return",
"function_exists",
"(",
"'hash'",
")",
"?",
"hex2bin",
"(",
"hash",
"(",
"'md4'",
",",
"$",
"input",
")",
")",
":",
"mhash",
"(",
"MHASH_MD4",
",",
"$",
"input",
")",
";",
"}"
] |
MD4 Encryption.
@param string $input
@return string
@see https://secure.php.net/manual/en/ref.hash.php
|
[
"MD4",
"Encryption",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php#L586-L591
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Preferences.php
|
Swift_Preferences.setQPDotEscape
|
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;
}
|
php
|
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;
}
|
[
"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.
@param bool $dotEscape
@return $this
|
[
"Set",
"the",
"QuotedPrintable",
"dot",
"escaper",
"preference",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Preferences.php#L89-L99
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php
|
Swift_Plugins_BandwidthMonitorPlugin.write
|
public function write($bytes)
{
$this->out += strlen($bytes);
foreach ($this->mirrors as $stream) {
$stream->write($bytes);
}
}
|
php
|
public function write($bytes)
{
$this->out += strlen($bytes);
foreach ($this->mirrors as $stream) {
$stream->write($bytes);
}
}
|
[
"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.
@param string $bytes
|
[
"Called",
"when",
"a",
"message",
"is",
"sent",
"so",
"that",
"the",
"outgoing",
"counter",
"can",
"be",
"increased",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php#L74-L80
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.addPart
|
public function addPart($body, $contentType = null, $charset = null)
{
return $this->attach((new Swift_MimePart($body, $contentType, $charset))->setEncoder($this->getEncoder()));
}
|
php
|
public function addPart($body, $contentType = null, $charset = null)
{
return $this->attach((new Swift_MimePart($body, $contentType, $charset))->setEncoder($this->getEncoder()));
}
|
[
"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.
@param string|Swift_OutputByteStream $body
@param string $contentType
@param string $charset
@return $this
|
[
"Add",
"a",
"MimePart",
"to",
"this",
"Message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L72-L75
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.attachSigner
|
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;
}
|
php
|
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;
}
|
[
"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.
@return $this
|
[
"Attach",
"a",
"new",
"signature",
"handler",
"to",
"the",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L82-L91
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.detachSigner
|
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;
}
|
php
|
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;
}
|
[
"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.
@return $this
|
[
"Detach",
"a",
"signature",
"handler",
"from",
"a",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L98-L119
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.doSign
|
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());
}
}
|
php
|
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());
}
}
|
[
"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.
|
[
"loops",
"through",
"signers",
"and",
"apply",
"the",
"signatures",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L184-L205
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.saveMessage
|
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('');
}
}
|
php
|
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('');
}
}
|
[
"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.
|
[
"save",
"the",
"message",
"before",
"any",
"signature",
"is",
"applied",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L210-L219
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.saveHeaders
|
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);
}
}
}
|
php
|
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);
}
}
}
|
[
"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.
|
[
"save",
"the",
"original",
"headers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L224-L233
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.restoreHeaders
|
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);
}
}
}
}
|
php
|
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);
}
}
}
}
|
[
"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.
|
[
"Remove",
"or",
"restore",
"altered",
"headers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L238-L249
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Message.php
|
Swift_Message.restoreMessage
|
protected function restoreMessage()
{
$this->setBody($this->savedMessage['body']);
$this->setChildren($this->savedMessage['children']);
$this->restoreHeaders();
$this->savedMessage = [];
}
|
php
|
protected function restoreMessage()
{
$this->setBody($this->savedMessage['body']);
$this->setChildren($this->savedMessage['children']);
$this->restoreHeaders();
$this->savedMessage = [];
}
|
[
"protected",
"function",
"restoreMessage",
"(",
")",
"{",
"$",
"this",
"->",
"setBody",
"(",
"$",
"this",
"->",
"savedMessage",
"[",
"'body'",
"]",
")",
";",
"$",
"this",
"->",
"setChildren",
"(",
"$",
"this",
"->",
"savedMessage",
"[",
"'children'",
"]",
")",
";",
"$",
"this",
"->",
"restoreHeaders",
"(",
")",
";",
"$",
"this",
"->",
"savedMessage",
"=",
"[",
"]",
";",
"}"
] |
Restore message body.
|
[
"Restore",
"message",
"body",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Message.php#L254-L261
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.setCharset
|
public function setCharset($charset)
{
$this->charset = $charset;
$this->factory->charsetChanged($charset);
$this->notifyHeadersOfCharset($charset);
}
|
php
|
public function setCharset($charset)
{
$this->charset = $charset;
$this->factory->charsetChanged($charset);
$this->notifyHeadersOfCharset($charset);
}
|
[
"public",
"function",
"setCharset",
"(",
"$",
"charset",
")",
"{",
"$",
"this",
"->",
"charset",
"=",
"$",
"charset",
";",
"$",
"this",
"->",
"factory",
"->",
"charsetChanged",
"(",
"$",
"charset",
")",
";",
"$",
"this",
"->",
"notifyHeadersOfCharset",
"(",
"$",
"charset",
")",
";",
"}"
] |
Set the charset used by these headers.
@param string $charset
|
[
"Set",
"the",
"charset",
"used",
"by",
"these",
"headers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L56-L61
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.addIdHeader
|
public function addIdHeader($name, $ids = null)
{
$this->storeHeader($name, $this->factory->createIdHeader($name, $ids));
}
|
php
|
public function addIdHeader($name, $ids = null)
{
$this->storeHeader($name, $this->factory->createIdHeader($name, $ids));
}
|
[
"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.
@param string $name
@param string|array $ids
|
[
"Add",
"a",
"new",
"ID",
"header",
"for",
"Message",
"-",
"ID",
"or",
"Content",
"-",
"ID",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L113-L116
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.set
|
public function set(Swift_Mime_Header $header, $index = 0)
{
$this->storeHeader($header->getFieldName(), $header, $index);
}
|
php
|
public function set(Swift_Mime_Header $header, $index = 0)
{
$this->storeHeader($header->getFieldName(), $header, $index);
}
|
[
"public",
"function",
"set",
"(",
"Swift_Mime_Header",
"$",
"header",
",",
"$",
"index",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"storeHeader",
"(",
"$",
"header",
"->",
"getFieldName",
"(",
")",
",",
"$",
"header",
",",
"$",
"index",
")",
";",
"}"
] |
Set a header in the HeaderSet.
The header may be a previously fetched header via {@link get()} or it may
be one that has been created separately.
If $index is specified, the header will be inserted into the set at this
offset.
@param int $index
|
[
"Set",
"a",
"header",
"in",
"the",
"HeaderSet",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L166-L169
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.listAll
|
public function listAll()
{
$headers = $this->headers;
if ($this->canSort()) {
uksort($headers, [$this, 'sortHeaders']);
}
return array_keys($headers);
}
|
php
|
public function listAll()
{
$headers = $this->headers;
if ($this->canSort()) {
uksort($headers, [$this, 'sortHeaders']);
}
return array_keys($headers);
}
|
[
"public",
"function",
"listAll",
"(",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"headers",
";",
"if",
"(",
"$",
"this",
"->",
"canSort",
"(",
")",
")",
"{",
"uksort",
"(",
"$",
"headers",
",",
"[",
"$",
"this",
",",
"'sortHeaders'",
"]",
")",
";",
"}",
"return",
"array_keys",
"(",
"$",
"headers",
")",
";",
"}"
] |
Return the name of all Headers.
@return array
|
[
"Return",
"the",
"name",
"of",
"all",
"Headers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L230-L238
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.toString
|
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;
}
|
php
|
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;
}
|
[
"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.
@return string
|
[
"Returns",
"a",
"string",
"with",
"a",
"representation",
"of",
"all",
"headers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L300-L316
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.storeHeader
|
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;
}
}
|
php
|
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;
}
}
|
[
"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
|
[
"Save",
"a",
"Header",
"to",
"the",
"internal",
"collection"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L331-L341
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderSet.php
|
Swift_Mime_SimpleHeaderSet.notifyHeadersOfCharset
|
private function notifyHeadersOfCharset($charset)
{
foreach ($this->headers as $headerGroup) {
foreach ($headerGroup as $header) {
$header->setCharset($charset);
}
}
}
|
php
|
private function notifyHeadersOfCharset($charset)
{
foreach ($this->headers as $headerGroup) {
foreach ($headerGroup as $header) {
$header->setCharset($charset);
}
}
}
|
[
"private",
"function",
"notifyHeadersOfCharset",
"(",
"$",
"charset",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"headerGroup",
")",
"{",
"foreach",
"(",
"$",
"headerGroup",
"as",
"$",
"header",
")",
"{",
"$",
"header",
"->",
"setCharset",
"(",
"$",
"charset",
")",
";",
"}",
"}",
"}"
] |
Notify all Headers of the new charset
|
[
"Notify",
"all",
"Headers",
"of",
"the",
"new",
"charset"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderSet.php#L378-L385
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMessage.php
|
Swift_Mime_SimpleMessage.setSubject
|
public function setSubject($subject)
{
if (!$this->setHeaderFieldModel('Subject', $subject)) {
$this->getHeaders()->addTextHeader('Subject', $subject);
}
return $this;
}
|
php
|
public function setSubject($subject)
{
if (!$this->setHeaderFieldModel('Subject', $subject)) {
$this->getHeaders()->addTextHeader('Subject', $subject);
}
return $this;
}
|
[
"public",
"function",
"setSubject",
"(",
"$",
"subject",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"setHeaderFieldModel",
"(",
"'Subject'",
",",
"$",
"subject",
")",
")",
"{",
"$",
"this",
"->",
"getHeaders",
"(",
")",
"->",
"addTextHeader",
"(",
"'Subject'",
",",
"$",
"subject",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the subject of this message.
@param string $subject
@return $this
|
[
"Set",
"the",
"subject",
"of",
"this",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMessage.php#L74-L81
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMessage.php
|
Swift_Mime_SimpleMessage.setDate
|
public function setDate(DateTimeInterface $dateTime)
{
if (!$this->setHeaderFieldModel('Date', $dateTime)) {
$this->getHeaders()->addDateHeader('Date', $dateTime);
}
return $this;
}
|
php
|
public function setDate(DateTimeInterface $dateTime)
{
if (!$this->setHeaderFieldModel('Date', $dateTime)) {
$this->getHeaders()->addDateHeader('Date', $dateTime);
}
return $this;
}
|
[
"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.
@return $this
|
[
"Set",
"the",
"date",
"at",
"which",
"this",
"message",
"was",
"created",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMessage.php#L98-L105
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMessage.php
|
Swift_Mime_SimpleMessage.detach
|
public function detach(Swift_Mime_SimpleMimeEntity $entity)
{
$newChildren = [];
foreach ($this->getChildren() as $child) {
if ($entity !== $child) {
$newChildren[] = $child;
}
}
$this->setChildren($newChildren);
return $this;
}
|
php
|
public function detach(Swift_Mime_SimpleMimeEntity $entity)
{
$newChildren = [];
foreach ($this->getChildren() as $child) {
if ($entity !== $child) {
$newChildren[] = $child;
}
}
$this->setChildren($newChildren);
return $this;
}
|
[
"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.
@return $this
|
[
"Remove",
"an",
"already",
"attached",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMessage.php#L537-L548
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMessage.php
|
Swift_Mime_SimpleMessage.becomeMimePart
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Turn",
"the",
"body",
"of",
"this",
"message",
"into",
"a",
"child",
"of",
"itself",
"if",
"needed"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMessage.php#L615-L627
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMessage.php
|
Swift_Mime_SimpleMessage.getTopNestingLevel
|
private function getTopNestingLevel()
{
$highestLevel = $this->getNestingLevel();
foreach ($this->getChildren() as $child) {
$childLevel = $child->getNestingLevel();
if ($highestLevel < $childLevel) {
$highestLevel = $childLevel;
}
}
return $highestLevel;
}
|
php
|
private function getTopNestingLevel()
{
$highestLevel = $this->getNestingLevel();
foreach ($this->getChildren() as $child) {
$childLevel = $child->getNestingLevel();
if ($highestLevel < $childLevel) {
$highestLevel = $childLevel;
}
}
return $highestLevel;
}
|
[
"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
|
[
"Get",
"the",
"highest",
"nesting",
"level",
"nested",
"inside",
"this",
"message"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMessage.php#L630-L641
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/PathHeader.php
|
Swift_Mime_Headers_PathHeader.setAddress
|
public function setAddress($address)
{
if (null === $address) {
$this->address = null;
} elseif ('' == $address) {
$this->address = '';
} else {
$this->assertValidAddress($address);
$this->address = $address;
}
$this->setCachedValue(null);
}
|
php
|
public function setAddress($address)
{
if (null === $address) {
$this->address = null;
} elseif ('' == $address) {
$this->address = '';
} else {
$this->assertValidAddress($address);
$this->address = $address;
}
$this->setCachedValue(null);
}
|
[
"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.
@param string $address
@throws Swift_RfcComplianceException
|
[
"Set",
"the",
"Address",
"which",
"should",
"appear",
"in",
"this",
"Header",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/PathHeader.php#L93-L104
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.setTimeout
|
public function setTimeout($timeout)
{
$this->params['timeout'] = (int) $timeout;
$this->buffer->setParam('timeout', (int) $timeout);
return $this;
}
|
php
|
public function setTimeout($timeout)
{
$this->params['timeout'] = (int) $timeout;
$this->buffer->setParam('timeout', (int) $timeout);
return $this;
}
|
[
"public",
"function",
"setTimeout",
"(",
"$",
"timeout",
")",
"{",
"$",
"this",
"->",
"params",
"[",
"'timeout'",
"]",
"=",
"(",
"int",
")",
"$",
"timeout",
";",
"$",
"this",
"->",
"buffer",
"->",
"setParam",
"(",
"'timeout'",
",",
"(",
"int",
")",
"$",
"timeout",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the connection timeout.
@param int $timeout seconds
@return $this
|
[
"Set",
"the",
"connection",
"timeout",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L117-L123
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.setExtensionHandlers
|
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;
}
|
php
|
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;
}
|
[
"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.
@param Swift_Transport_EsmtpHandler[] $handlers
@return $this
|
[
"Set",
"ESMTP",
"extension",
"handlers",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L252-L265
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.doHeloCommand
|
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);
}
}
|
php
|
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);
}
}
|
[
"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
|
[
"Overridden",
"to",
"perform",
"EHLO",
"instead"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L334-L373
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.doMailFromCommand
|
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
);
}
|
php
|
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
);
}
|
[
"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
|
[
"Overridden",
"to",
"add",
"Extension",
"support"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L376-L388
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.getCapabilities
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Determine",
"ESMTP",
"capabilities",
"by",
"function",
"group"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L406-L422
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.setHandlerParams
|
private function setHandlerParams()
{
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
$handler->setKeywordParams($this->capabilities[$keyword]);
}
}
}
|
php
|
private function setHandlerParams()
{
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
$handler->setKeywordParams($this->capabilities[$keyword]);
}
}
}
|
[
"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
|
[
"Set",
"parameters",
"which",
"are",
"used",
"by",
"each",
"extension",
"handler"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L425-L432
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/EsmtpTransport.php
|
Swift_Transport_EsmtpTransport.getActiveHandlers
|
private function getActiveHandlers()
{
$handlers = [];
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
$handlers[] = $handler;
}
}
return $handlers;
}
|
php
|
private function getActiveHandlers()
{
$handlers = [];
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
$handlers[] = $handler;
}
}
return $handlers;
}
|
[
"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
|
[
"Get",
"ESMTP",
"handlers",
"which",
"are",
"currently",
"ok",
"to",
"use"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/EsmtpTransport.php#L435-L445
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/CharacterStream/ArrayCharacterStream.php
|
Swift_CharacterStream_ArrayCharacterStream.importByteStream
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
@param Swift_OutputByteStream $os output stream to read from
|
[
"Overwrite",
"this",
"character",
"stream",
"using",
"the",
"byte",
"sequence",
"in",
"the",
"byte",
"stream",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php#L79-L104
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.getId
|
public function getId()
{
$tmp = (array) $this->getHeaderFieldModel($this->getIdField());
return $this->headers->has($this->getIdField()) ? current($tmp) : $this->id;
}
|
php
|
public function getId()
{
$tmp = (array) $this->getHeaderFieldModel($this->getIdField());
return $this->headers->has($this->getIdField()) ? current($tmp) : $this->id;
}
|
[
"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.
The CID will only be present in headers if a Content-ID header is present.
@return string
|
[
"Get",
"the",
"CID",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L200-L205
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.setId
|
public function setId($id)
{
if (!$this->setHeaderFieldModel($this->getIdField(), $id)) {
$this->headers->addIdHeader($this->getIdField(), $id);
}
$this->id = $id;
return $this;
}
|
php
|
public function setId($id)
{
if (!$this->setHeaderFieldModel($this->getIdField(), $id)) {
$this->headers->addIdHeader($this->getIdField(), $id);
}
$this->id = $id;
return $this;
}
|
[
"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.
@param string $id
@return $this
|
[
"Set",
"the",
"CID",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L214-L222
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.setDescription
|
public function setDescription($description)
{
if (!$this->setHeaderFieldModel('Content-Description', $description)) {
$this->headers->addTextHeader('Content-Description', $description);
}
return $this;
}
|
php
|
public function setDescription($description)
{
if (!$this->setHeaderFieldModel('Content-Description', $description)) {
$this->headers->addTextHeader('Content-Description', $description);
}
return $this;
}
|
[
"public",
"function",
"setDescription",
"(",
"$",
"description",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"setHeaderFieldModel",
"(",
"'Content-Description'",
",",
"$",
"description",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"->",
"addTextHeader",
"(",
"'Content-Description'",
",",
"$",
"description",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the description of this entity.
This method sets a value in the Content-ID header.
@param string $description
@return $this
|
[
"Set",
"the",
"description",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L245-L252
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.setChildren
|
public function setChildren(array $children, $compoundLevel = null)
{
// TODO: Try to refactor this logic
$compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
$immediateChildren = [];
$grandchildren = [];
$newContentType = $this->userContentType;
foreach ($children as $child) {
$level = $this->getNeededChildLevel($child, $compoundLevel);
if (empty($immediateChildren)) {
//first iteration
$immediateChildren = [$child];
} else {
$nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
if ($nextLevel == $level) {
$immediateChildren[] = $child;
} elseif ($level < $nextLevel) {
// Re-assign immediateChildren to grandchildren
$grandchildren = array_merge($grandchildren, $immediateChildren);
// Set new children
$immediateChildren = [$child];
} else {
$grandchildren[] = $child;
}
}
}
if ($immediateChildren) {
$lowestLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
// Determine which composite media type is needed to accommodate the
// immediate children
foreach ($this->compositeRanges as $mediaType => $range) {
if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
$newContentType = $mediaType;
break;
}
}
// Put any grandchildren in a subpart
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;
}
|
php
|
public function setChildren(array $children, $compoundLevel = null)
{
// TODO: Try to refactor this logic
$compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
$immediateChildren = [];
$grandchildren = [];
$newContentType = $this->userContentType;
foreach ($children as $child) {
$level = $this->getNeededChildLevel($child, $compoundLevel);
if (empty($immediateChildren)) {
//first iteration
$immediateChildren = [$child];
} else {
$nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
if ($nextLevel == $level) {
$immediateChildren[] = $child;
} elseif ($level < $nextLevel) {
// Re-assign immediateChildren to grandchildren
$grandchildren = array_merge($grandchildren, $immediateChildren);
// Set new children
$immediateChildren = [$child];
} else {
$grandchildren[] = $child;
}
}
}
if ($immediateChildren) {
$lowestLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
// Determine which composite media type is needed to accommodate the
// immediate children
foreach ($this->compositeRanges as $mediaType => $range) {
if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
$newContentType = $mediaType;
break;
}
}
// Put any grandchildren in a subpart
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;
}
|
[
"public",
"function",
"setChildren",
"(",
"array",
"$",
"children",
",",
"$",
"compoundLevel",
"=",
"null",
")",
"{",
"// TODO: Try to refactor this logic",
"$",
"compoundLevel",
"=",
"$",
"compoundLevel",
"??",
"$",
"this",
"->",
"getCompoundLevel",
"(",
"$",
"children",
")",
";",
"$",
"immediateChildren",
"=",
"[",
"]",
";",
"$",
"grandchildren",
"=",
"[",
"]",
";",
"$",
"newContentType",
"=",
"$",
"this",
"->",
"userContentType",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"getNeededChildLevel",
"(",
"$",
"child",
",",
"$",
"compoundLevel",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"immediateChildren",
")",
")",
"{",
"//first iteration",
"$",
"immediateChildren",
"=",
"[",
"$",
"child",
"]",
";",
"}",
"else",
"{",
"$",
"nextLevel",
"=",
"$",
"this",
"->",
"getNeededChildLevel",
"(",
"$",
"immediateChildren",
"[",
"0",
"]",
",",
"$",
"compoundLevel",
")",
";",
"if",
"(",
"$",
"nextLevel",
"==",
"$",
"level",
")",
"{",
"$",
"immediateChildren",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"elseif",
"(",
"$",
"level",
"<",
"$",
"nextLevel",
")",
"{",
"// Re-assign immediateChildren to grandchildren",
"$",
"grandchildren",
"=",
"array_merge",
"(",
"$",
"grandchildren",
",",
"$",
"immediateChildren",
")",
";",
"// Set new children",
"$",
"immediateChildren",
"=",
"[",
"$",
"child",
"]",
";",
"}",
"else",
"{",
"$",
"grandchildren",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"immediateChildren",
")",
"{",
"$",
"lowestLevel",
"=",
"$",
"this",
"->",
"getNeededChildLevel",
"(",
"$",
"immediateChildren",
"[",
"0",
"]",
",",
"$",
"compoundLevel",
")",
";",
"// Determine which composite media type is needed to accommodate the",
"// immediate children",
"foreach",
"(",
"$",
"this",
"->",
"compositeRanges",
"as",
"$",
"mediaType",
"=>",
"$",
"range",
")",
"{",
"if",
"(",
"$",
"lowestLevel",
">",
"$",
"range",
"[",
"0",
"]",
"&&",
"$",
"lowestLevel",
"<=",
"$",
"range",
"[",
"1",
"]",
")",
"{",
"$",
"newContentType",
"=",
"$",
"mediaType",
";",
"break",
";",
"}",
"}",
"// Put any grandchildren in a subpart",
"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.
@param Swift_Mime_SimpleMimeEntity[] $children
@param int $compoundLevel For internal use only
@return $this
|
[
"Set",
"all",
"children",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L298-L355
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.getBody
|
public function getBody()
{
return $this->body instanceof Swift_OutputByteStream ? $this->readStream($this->body) : $this->body;
}
|
php
|
public function getBody()
{
return $this->body instanceof Swift_OutputByteStream ? $this->readStream($this->body) : $this->body;
}
|
[
"public",
"function",
"getBody",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"body",
"instanceof",
"Swift_OutputByteStream",
"?",
"$",
"this",
"->",
"readStream",
"(",
"$",
"this",
"->",
"body",
")",
":",
"$",
"this",
"->",
"body",
";",
"}"
] |
Get the body of this entity as a string.
@return string
|
[
"Get",
"the",
"body",
"of",
"this",
"entity",
"as",
"a",
"string",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L362-L365
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.setEncoder
|
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;
}
|
php
|
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;
}
|
[
"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.
@return $this
|
[
"Set",
"the",
"encoder",
"used",
"for",
"the",
"body",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L405-L416
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.getBoundary
|
public function getBoundary()
{
if (!isset($this->boundary)) {
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
}
return $this->boundary;
}
|
php
|
public function getBoundary()
{
if (!isset($this->boundary)) {
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
}
return $this->boundary;
}
|
[
"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.
@return string
|
[
"Get",
"the",
"boundary",
"used",
"to",
"separate",
"children",
"in",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L423-L430
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.bodyToString
|
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;
}
|
php
|
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;
}
|
[
"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.
@return string
|
[
"Get",
"this",
"entire",
"entity",
"as",
"a",
"string",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L487-L510
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleMimeEntity.php
|
Swift_Mime_SimpleMimeEntity.fixHeaders
|
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());
}
}
|
php
|
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());
}
}
|
[
"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.
|
[
"Re",
"-",
"evaluate",
"what",
"content",
"type",
"and",
"encoding",
"should",
"be",
"used",
"on",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleMimeEntity.php#L635-L646
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php
|
Swift_Plugins_PopBeforeSmtpPlugin.connect
|
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));
}
}
}
}
|
php
|
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));
}
}
}
}
|
[
"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.
@throws Swift_Plugins_Pop_Pop3Exception if connection fails
|
[
"Connect",
"to",
"the",
"POP3",
"host",
"and",
"authenticate",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php#L127-L155
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php
|
Swift_Plugins_PopBeforeSmtpPlugin.disconnect
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
|
[
"Disconnect",
"from",
"the",
"POP3",
"host",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php#L160-L173
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.setLocalDomain
|
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;
}
|
php
|
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;
}
|
[
"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.
This should be a fully-qualified domain name and should be truly the domain
you're using.
If your server does not have a domain name, use the IP address. This will
automatically be wrapped in square brackets as described in RFC 5321,
section 4.1.3.
@param string $domain
@return $this
|
[
"Set",
"the",
"name",
"of",
"the",
"local",
"domain",
"which",
"Swift",
"will",
"identify",
"itself",
"as",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L71-L84
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.start
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
|
[
"Start",
"the",
"SMTP",
"connection",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L132-L156
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.stop
|
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;
}
|
php
|
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;
}
|
[
"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.
|
[
"Stop",
"the",
"SMTP",
"connection",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L232-L258
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.doMailFromCommand
|
protected function doMailFromCommand($address)
{
$address = $this->addressEncoder->encodeString($address);
$this->executeCommand(
sprintf("MAIL FROM:<%s>\r\n", $address), [250], $failures, true
);
}
|
php
|
protected function doMailFromCommand($address)
{
$address = $this->addressEncoder->encodeString($address);
$this->executeCommand(
sprintf("MAIL FROM:<%s>\r\n", $address), [250], $failures, true
);
}
|
[
"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
|
[
"Send",
"the",
"MAIL",
"FROM",
"command"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L370-L376
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.streamMessage
|
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]);
}
|
php
|
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]);
}
|
[
"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
|
[
"Stream",
"the",
"contents",
"of",
"the",
"message",
"over",
"the",
"buffer"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L394-L405
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.throwException
|
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;
}
}
|
php
|
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;
}
}
|
[
"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
|
[
"Throw",
"a",
"TransportException",
"first",
"sending",
"it",
"to",
"any",
"listeners"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L429-L439
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.assertResponseCode
|
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));
}
}
|
php
|
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));
}
}
|
[
"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
|
[
"Throws",
"an",
"Exception",
"if",
"a",
"response",
"code",
"is",
"incorrect"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L442-L459
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.getFullResponse
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Get",
"an",
"entire",
"multi",
"-",
"line",
"response",
"using",
"its",
"sequence",
"number"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L462-L477
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/AbstractSmtpTransport.php
|
Swift_Transport_AbstractSmtpTransport.doMailTransaction
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Send",
"an",
"email",
"to",
"the",
"given",
"recipients",
"from",
"the",
"given",
"reverse",
"path"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/AbstractSmtpTransport.php#L480-L506
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderFactory.php
|
Swift_Mime_SimpleHeaderFactory.createIdHeader
|
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;
}
|
php
|
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;
}
|
[
"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.
@param string $name
@param string|array $ids
@return Swift_Mime_Header
|
[
"Create",
"a",
"new",
"ID",
"header",
"for",
"Message",
"-",
"ID",
"or",
"Content",
"-",
"ID",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderFactory.php#L137-L146
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderFactory.php
|
Swift_Mime_SimpleHeaderFactory.charsetChanged
|
public function charsetChanged($charset)
{
$this->charset = $charset;
$this->encoder->charsetChanged($charset);
$this->paramEncoder->charsetChanged($charset);
}
|
php
|
public function charsetChanged($charset)
{
$this->charset = $charset;
$this->encoder->charsetChanged($charset);
$this->paramEncoder->charsetChanged($charset);
}
|
[
"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.
@param string $charset
|
[
"Notify",
"this",
"observer",
"that",
"the",
"entity",
"s",
"charset",
"has",
"changed",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderFactory.php#L172-L177
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/SimpleHeaderFactory.php
|
Swift_Mime_SimpleHeaderFactory.setHeaderCharset
|
private function setHeaderCharset(Swift_Mime_Header $header)
{
if (isset($this->charset)) {
$header->setCharset($this->charset);
}
}
|
php
|
private function setHeaderCharset(Swift_Mime_Header $header)
{
if (isset($this->charset)) {
$header->setCharset($this->charset);
}
}
|
[
"private",
"function",
"setHeaderCharset",
"(",
"Swift_Mime_Header",
"$",
"header",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"charset",
")",
")",
"{",
"$",
"header",
"->",
"setCharset",
"(",
"$",
"this",
"->",
"charset",
")",
";",
"}",
"}"
] |
Apply the charset to the Header
|
[
"Apply",
"the",
"charset",
"to",
"the",
"Header"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/SimpleHeaderFactory.php#L189-L194
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/StreamFilters/StringReplacementFilter.php
|
Swift_StreamFilters_StringReplacementFilter.shouldBuffer
|
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;
}
|
php
|
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;
}
|
[
"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.
@param string $buffer
@return bool
|
[
"Returns",
"true",
"if",
"based",
"on",
"the",
"buffer",
"passed",
"more",
"bytes",
"should",
"be",
"buffered",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/StreamFilters/StringReplacementFilter.php#L43-L57
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/RedirectingPlugin.php
|
Swift_Plugins_RedirectingPlugin.filterHeaderSet
|
private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type)
{
foreach ($headerSet->getAll($type) as $headers) {
$headers->setNameAddresses($this->filterNameAddresses($headers->getNameAddresses()));
}
}
|
php
|
private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type)
{
foreach ($headerSet->getAll($type) as $headers) {
$headers->setNameAddresses($this->filterNameAddresses($headers->getNameAddresses()));
}
}
|
[
"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.
@param string $type
|
[
"Filter",
"header",
"set",
"against",
"a",
"whitelist",
"of",
"regular",
"expressions",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/RedirectingPlugin.php#L126-L131
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/RedirectingPlugin.php
|
Swift_Plugins_RedirectingPlugin.filterNameAddresses
|
private function filterNameAddresses(array $recipients)
{
$filtered = [];
foreach ($recipients as $address => $name) {
if ($this->isWhitelisted($address)) {
$filtered[$address] = $name;
}
}
return $filtered;
}
|
php
|
private function filterNameAddresses(array $recipients)
{
$filtered = [];
foreach ($recipients as $address => $name) {
if ($this->isWhitelisted($address)) {
$filtered[$address] = $name;
}
}
return $filtered;
}
|
[
"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.
@return array
|
[
"Filtered",
"list",
"of",
"addresses",
"=",
">",
"name",
"pairs",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/RedirectingPlugin.php#L138-L149
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/RedirectingPlugin.php
|
Swift_Plugins_RedirectingPlugin.isWhitelisted
|
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;
}
|
php
|
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;
}
|
[
"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.
@return bool
|
[
"Matches",
"address",
"against",
"whitelist",
"of",
"regular",
"expressions",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/RedirectingPlugin.php#L156-L169
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.setSignCertificate
|
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;
}
|
php
|
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;
}
|
[
"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.
@see https://secure.php.net/manual/en/openssl.pkcs7.flags.php
@param string $certificate
@param string|array $privateKey If the key needs an passphrase use array('file-location', 'passphrase') instead
@param int $signOptions Bitwise operator options for openssl_pkcs7_sign()
@param string $extraCerts A file containing intermediate certificates needed by the signing certificate
@return $this
|
[
"Set",
"the",
"certificate",
"location",
"to",
"use",
"for",
"signing",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L78-L95
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.setEncryptCertificate
|
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;
}
|
php
|
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;
}
|
[
"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.
@see https://secure.php.net/manual/en/openssl.pkcs7.flags.php
@see https://secure.php.net/manual/en/openssl.ciphers.php
@param string|array $recipientCerts Either an single X.509 certificate, or an assoc array of X.509 certificates.
@param int $cipher
@return $this
|
[
"Set",
"the",
"certificate",
"location",
"to",
"use",
"for",
"encryption",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L108-L125
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.signMessage
|
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);
}
}
|
php
|
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);
}
}
|
[
"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.
@return $this
|
[
"Change",
"the",
"Swift_Message",
"to",
"apply",
"the",
"signing",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L204-L217
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.smimeSignMessage
|
protected function smimeSignMessage(Swift_Message $message)
{
// If we don't have a certificate we can't sign the message
if (null === $this->signCertificate) {
return;
}
// Work on a clone of the original message
$signMessage = clone $message;
$signMessage->clearSigners();
if ($this->wrapFullMessage) {
// The original message essentially becomes the body of the new
// wrapped message
$signMessage = $this->wrapMimeMessage($signMessage);
} else {
// Only keep header needed to parse the body correctly
$this->clearAllHeaders($signMessage);
$this->copyHeaders(
$message,
$signMessage,
[
'Content-Type',
'Content-Transfer-Encoding',
'Content-Disposition',
]
);
}
// Copy the cloned message into a temporary file stream
$messageStream = new Swift_ByteStream_TemporaryFileByteStream();
$signMessage->toByteStream($messageStream);
$messageStream->commit();
$signedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();
// Sign the message using openssl
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()));
}
// Parse the resulting signed message content back into the Swift message
// preserving the original headers
$this->parseSSLOutput($signedMessageStream, $message);
}
|
php
|
protected function smimeSignMessage(Swift_Message $message)
{
// If we don't have a certificate we can't sign the message
if (null === $this->signCertificate) {
return;
}
// Work on a clone of the original message
$signMessage = clone $message;
$signMessage->clearSigners();
if ($this->wrapFullMessage) {
// The original message essentially becomes the body of the new
// wrapped message
$signMessage = $this->wrapMimeMessage($signMessage);
} else {
// Only keep header needed to parse the body correctly
$this->clearAllHeaders($signMessage);
$this->copyHeaders(
$message,
$signMessage,
[
'Content-Type',
'Content-Transfer-Encoding',
'Content-Disposition',
]
);
}
// Copy the cloned message into a temporary file stream
$messageStream = new Swift_ByteStream_TemporaryFileByteStream();
$signMessage->toByteStream($messageStream);
$messageStream->commit();
$signedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();
// Sign the message using openssl
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()));
}
// Parse the resulting signed message content back into the Swift message
// preserving the original headers
$this->parseSSLOutput($signedMessageStream, $message);
}
|
[
"protected",
"function",
"smimeSignMessage",
"(",
"Swift_Message",
"$",
"message",
")",
"{",
"// If we don't have a certificate we can't sign the message",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"signCertificate",
")",
"{",
"return",
";",
"}",
"// Work on a clone of the original message",
"$",
"signMessage",
"=",
"clone",
"$",
"message",
";",
"$",
"signMessage",
"->",
"clearSigners",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"wrapFullMessage",
")",
"{",
"// The original message essentially becomes the body of the new",
"// wrapped message",
"$",
"signMessage",
"=",
"$",
"this",
"->",
"wrapMimeMessage",
"(",
"$",
"signMessage",
")",
";",
"}",
"else",
"{",
"// Only keep header needed to parse the body correctly",
"$",
"this",
"->",
"clearAllHeaders",
"(",
"$",
"signMessage",
")",
";",
"$",
"this",
"->",
"copyHeaders",
"(",
"$",
"message",
",",
"$",
"signMessage",
",",
"[",
"'Content-Type'",
",",
"'Content-Transfer-Encoding'",
",",
"'Content-Disposition'",
",",
"]",
")",
";",
"}",
"// Copy the cloned message into a temporary file stream",
"$",
"messageStream",
"=",
"new",
"Swift_ByteStream_TemporaryFileByteStream",
"(",
")",
";",
"$",
"signMessage",
"->",
"toByteStream",
"(",
"$",
"messageStream",
")",
";",
"$",
"messageStream",
"->",
"commit",
"(",
")",
";",
"$",
"signedMessageStream",
"=",
"new",
"Swift_ByteStream_TemporaryFileByteStream",
"(",
")",
";",
"// Sign the message using openssl",
"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",
"(",
")",
")",
")",
";",
"}",
"// Parse the resulting signed message content back into the Swift message",
"// preserving the original headers",
"$",
"this",
"->",
"parseSSLOutput",
"(",
"$",
"signedMessageStream",
",",
"$",
"message",
")",
";",
"}"
] |
Sign a Swift message.
|
[
"Sign",
"a",
"Swift",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L232-L284
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.smimeEncryptMessage
|
protected function smimeEncryptMessage(Swift_Message $message)
{
// If we don't have a certificate we can't encrypt the message
if (null === $this->encryptCert) {
return;
}
// Work on a clone of the original message
$encryptMessage = clone $message;
$encryptMessage->clearSigners();
if ($this->wrapFullMessage) {
// The original message essentially becomes the body of the new
// wrapped message
$encryptMessage = $this->wrapMimeMessage($encryptMessage);
} else {
// Only keep header needed to parse the body correctly
$this->clearAllHeaders($encryptMessage);
$this->copyHeaders(
$message,
$encryptMessage,
[
'Content-Type',
'Content-Transfer-Encoding',
'Content-Disposition',
]
);
}
// Convert the message content (including headers) to a string
// and place it in a temporary file
$messageStream = new Swift_ByteStream_TemporaryFileByteStream();
$encryptMessage->toByteStream($messageStream);
$messageStream->commit();
$encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();
// Encrypt the message
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()));
}
// Parse the resulting signed message content back into the Swift message
// preserving the original headers
$this->parseSSLOutput($encryptedMessageStream, $message);
}
|
php
|
protected function smimeEncryptMessage(Swift_Message $message)
{
// If we don't have a certificate we can't encrypt the message
if (null === $this->encryptCert) {
return;
}
// Work on a clone of the original message
$encryptMessage = clone $message;
$encryptMessage->clearSigners();
if ($this->wrapFullMessage) {
// The original message essentially becomes the body of the new
// wrapped message
$encryptMessage = $this->wrapMimeMessage($encryptMessage);
} else {
// Only keep header needed to parse the body correctly
$this->clearAllHeaders($encryptMessage);
$this->copyHeaders(
$message,
$encryptMessage,
[
'Content-Type',
'Content-Transfer-Encoding',
'Content-Disposition',
]
);
}
// Convert the message content (including headers) to a string
// and place it in a temporary file
$messageStream = new Swift_ByteStream_TemporaryFileByteStream();
$encryptMessage->toByteStream($messageStream);
$messageStream->commit();
$encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();
// Encrypt the message
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()));
}
// Parse the resulting signed message content back into the Swift message
// preserving the original headers
$this->parseSSLOutput($encryptedMessageStream, $message);
}
|
[
"protected",
"function",
"smimeEncryptMessage",
"(",
"Swift_Message",
"$",
"message",
")",
"{",
"// If we don't have a certificate we can't encrypt the message",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"encryptCert",
")",
"{",
"return",
";",
"}",
"// Work on a clone of the original message",
"$",
"encryptMessage",
"=",
"clone",
"$",
"message",
";",
"$",
"encryptMessage",
"->",
"clearSigners",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"wrapFullMessage",
")",
"{",
"// The original message essentially becomes the body of the new",
"// wrapped message",
"$",
"encryptMessage",
"=",
"$",
"this",
"->",
"wrapMimeMessage",
"(",
"$",
"encryptMessage",
")",
";",
"}",
"else",
"{",
"// Only keep header needed to parse the body correctly",
"$",
"this",
"->",
"clearAllHeaders",
"(",
"$",
"encryptMessage",
")",
";",
"$",
"this",
"->",
"copyHeaders",
"(",
"$",
"message",
",",
"$",
"encryptMessage",
",",
"[",
"'Content-Type'",
",",
"'Content-Transfer-Encoding'",
",",
"'Content-Disposition'",
",",
"]",
")",
";",
"}",
"// Convert the message content (including headers) to a string",
"// and place it in a temporary file",
"$",
"messageStream",
"=",
"new",
"Swift_ByteStream_TemporaryFileByteStream",
"(",
")",
";",
"$",
"encryptMessage",
"->",
"toByteStream",
"(",
"$",
"messageStream",
")",
";",
"$",
"messageStream",
"->",
"commit",
"(",
")",
";",
"$",
"encryptedMessageStream",
"=",
"new",
"Swift_ByteStream_TemporaryFileByteStream",
"(",
")",
";",
"// Encrypt the message",
"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",
"(",
")",
")",
")",
";",
"}",
"// Parse the resulting signed message content back into the Swift message",
"// preserving the original headers",
"$",
"this",
"->",
"parseSSLOutput",
"(",
"$",
"encryptedMessageStream",
",",
"$",
"message",
")",
";",
"}"
] |
Encrypt a Swift message.
|
[
"Encrypt",
"a",
"Swift",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L289-L341
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.copyHeaders
|
protected function copyHeaders(
Swift_Message $fromMessage,
Swift_Message $toMessage,
array $headers = []
) {
foreach ($headers as $header) {
$this->copyHeader($fromMessage, $toMessage, $header);
}
}
|
php
|
protected function copyHeaders(
Swift_Message $fromMessage,
Swift_Message $toMessage,
array $headers = []
) {
foreach ($headers as $header) {
$this->copyHeader($fromMessage, $toMessage, $header);
}
}
|
[
"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.
|
[
"Copy",
"named",
"headers",
"from",
"one",
"Swift",
"message",
"to",
"another",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L346-L354
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.copyHeader
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
@param string $headerName
|
[
"Copy",
"a",
"single",
"header",
"from",
"one",
"Swift",
"message",
"to",
"another",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L361-L380
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.clearAllHeaders
|
protected function clearAllHeaders(Swift_Message $message)
{
$headers = $message->getHeaders();
foreach ($headers->listAll() as $header) {
$headers->removeAll($header);
}
}
|
php
|
protected function clearAllHeaders(Swift_Message $message)
{
$headers = $message->getHeaders();
foreach ($headers->listAll() as $header) {
$headers->removeAll($header);
}
}
|
[
"protected",
"function",
"clearAllHeaders",
"(",
"Swift_Message",
"$",
"message",
")",
"{",
"$",
"headers",
"=",
"$",
"message",
"->",
"getHeaders",
"(",
")",
";",
"foreach",
"(",
"$",
"headers",
"->",
"listAll",
"(",
")",
"as",
"$",
"header",
")",
"{",
"$",
"headers",
"->",
"removeAll",
"(",
"$",
"header",
")",
";",
"}",
"}"
] |
Remove all headers from a Swift message.
|
[
"Remove",
"all",
"headers",
"from",
"a",
"Swift",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L385-L391
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.streamToMime
|
protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message)
{
// Parse the stream into headers and body
list($headers, $messageStream) = $this->parseStream($fromStream);
// Get the original message headers
$messageHeaders = $message->getHeaders();
// Let the stream determine the headers describing the body content,
// since the body of the original message is overwritten by the body
// coming from the stream.
// These are all content-* headers.
// Default transfer encoding is 7bit if not set
$encoding = '';
// Remove all existing transfer encoding headers
$messageHeaders->removeAll('Content-Transfer-Encoding');
// See whether the stream sets the transfer encoding
if (isset($headers['content-transfer-encoding'])) {
$encoding = $headers['content-transfer-encoding'];
}
// We use the null content encoder, since the body is already encoded
// according to the transfer encoding specified in the stream
$message->setEncoder(new Swift_Mime_ContentEncoder_NullContentEncoder($encoding));
// Set the disposition, if present
if (isset($headers['content-disposition'])) {
$messageHeaders->addTextHeader('Content-Disposition', $headers['content-disposition']);
}
// Copy over the body from the stream using the content type dictated
// by the stream content
$message->setChildren([]);
$message->setBody($messageStream, $headers['content-type']);
}
|
php
|
protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message)
{
// Parse the stream into headers and body
list($headers, $messageStream) = $this->parseStream($fromStream);
// Get the original message headers
$messageHeaders = $message->getHeaders();
// Let the stream determine the headers describing the body content,
// since the body of the original message is overwritten by the body
// coming from the stream.
// These are all content-* headers.
// Default transfer encoding is 7bit if not set
$encoding = '';
// Remove all existing transfer encoding headers
$messageHeaders->removeAll('Content-Transfer-Encoding');
// See whether the stream sets the transfer encoding
if (isset($headers['content-transfer-encoding'])) {
$encoding = $headers['content-transfer-encoding'];
}
// We use the null content encoder, since the body is already encoded
// according to the transfer encoding specified in the stream
$message->setEncoder(new Swift_Mime_ContentEncoder_NullContentEncoder($encoding));
// Set the disposition, if present
if (isset($headers['content-disposition'])) {
$messageHeaders->addTextHeader('Content-Disposition', $headers['content-disposition']);
}
// Copy over the body from the stream using the content type dictated
// by the stream content
$message->setChildren([]);
$message->setBody($messageStream, $headers['content-type']);
}
|
[
"protected",
"function",
"streamToMime",
"(",
"Swift_OutputByteStream",
"$",
"fromStream",
",",
"Swift_Message",
"$",
"message",
")",
"{",
"// Parse the stream into headers and body",
"list",
"(",
"$",
"headers",
",",
"$",
"messageStream",
")",
"=",
"$",
"this",
"->",
"parseStream",
"(",
"$",
"fromStream",
")",
";",
"// Get the original message headers",
"$",
"messageHeaders",
"=",
"$",
"message",
"->",
"getHeaders",
"(",
")",
";",
"// Let the stream determine the headers describing the body content,",
"// since the body of the original message is overwritten by the body",
"// coming from the stream.",
"// These are all content-* headers.",
"// Default transfer encoding is 7bit if not set",
"$",
"encoding",
"=",
"''",
";",
"// Remove all existing transfer encoding headers",
"$",
"messageHeaders",
"->",
"removeAll",
"(",
"'Content-Transfer-Encoding'",
")",
";",
"// See whether the stream sets the transfer encoding",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'content-transfer-encoding'",
"]",
")",
")",
"{",
"$",
"encoding",
"=",
"$",
"headers",
"[",
"'content-transfer-encoding'",
"]",
";",
"}",
"// We use the null content encoder, since the body is already encoded",
"// according to the transfer encoding specified in the stream",
"$",
"message",
"->",
"setEncoder",
"(",
"new",
"Swift_Mime_ContentEncoder_NullContentEncoder",
"(",
"$",
"encoding",
")",
")",
";",
"// Set the disposition, if present",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'content-disposition'",
"]",
")",
")",
"{",
"$",
"messageHeaders",
"->",
"addTextHeader",
"(",
"'Content-Disposition'",
",",
"$",
"headers",
"[",
"'content-disposition'",
"]",
")",
";",
"}",
"// Copy over the body from the stream using the content type dictated",
"// by the stream content",
"$",
"message",
"->",
"setChildren",
"(",
"[",
"]",
")",
";",
"$",
"message",
"->",
"setBody",
"(",
"$",
"messageStream",
",",
"$",
"headers",
"[",
"'content-type'",
"]",
")",
";",
"}"
] |
Merges an OutputByteStream from OpenSSL to a Swift_Message.
|
[
"Merges",
"an",
"OutputByteStream",
"from",
"OpenSSL",
"to",
"a",
"Swift_Message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L423-L458
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/SMimeSigner.php
|
Swift_Signers_SMimeSigner.parseStream
|
protected function parseStream(Swift_OutputByteStream $emailStream)
{
$bufferLength = 78;
$headerData = '';
$headerBodySeparator = "\r\n\r\n";
$emailStream->setReadPointer(0);
// Read out the headers section from the stream to a string
while (false !== ($buffer = $emailStream->read($bufferLength))) {
$headerData .= $buffer;
$headersPosEnd = strpos($headerData, $headerBodySeparator);
// Stop reading if we found the end of the headers
if (false !== $headersPosEnd) {
break;
}
}
// Split the header data into lines
$headerData = trim(substr($headerData, 0, $headersPosEnd));
$headerLines = explode("\r\n", $headerData);
unset($headerData);
$headers = [];
$currentHeaderName = '';
// Transform header lines into an associative array
foreach ($headerLines as $headerLine) {
// Handle headers that span multiple lines
if (false === strpos($headerLine, ':')) {
$headers[$currentHeaderName] .= ' '.trim($headerLine);
continue;
}
$header = explode(':', $headerLine, 2);
$currentHeaderName = strtolower($header[0]);
$headers[$currentHeaderName] = trim($header[1]);
}
// Read the entire email body into a byte stream
$bodyStream = new Swift_ByteStream_TemporaryFileByteStream();
// Skip the header and separator and point to the body
$emailStream->setReadPointer($headersPosEnd + strlen($headerBodySeparator));
while (false !== ($buffer = $emailStream->read($bufferLength))) {
$bodyStream->write($buffer);
}
$bodyStream->commit();
return [$headers, $bodyStream];
}
|
php
|
protected function parseStream(Swift_OutputByteStream $emailStream)
{
$bufferLength = 78;
$headerData = '';
$headerBodySeparator = "\r\n\r\n";
$emailStream->setReadPointer(0);
// Read out the headers section from the stream to a string
while (false !== ($buffer = $emailStream->read($bufferLength))) {
$headerData .= $buffer;
$headersPosEnd = strpos($headerData, $headerBodySeparator);
// Stop reading if we found the end of the headers
if (false !== $headersPosEnd) {
break;
}
}
// Split the header data into lines
$headerData = trim(substr($headerData, 0, $headersPosEnd));
$headerLines = explode("\r\n", $headerData);
unset($headerData);
$headers = [];
$currentHeaderName = '';
// Transform header lines into an associative array
foreach ($headerLines as $headerLine) {
// Handle headers that span multiple lines
if (false === strpos($headerLine, ':')) {
$headers[$currentHeaderName] .= ' '.trim($headerLine);
continue;
}
$header = explode(':', $headerLine, 2);
$currentHeaderName = strtolower($header[0]);
$headers[$currentHeaderName] = trim($header[1]);
}
// Read the entire email body into a byte stream
$bodyStream = new Swift_ByteStream_TemporaryFileByteStream();
// Skip the header and separator and point to the body
$emailStream->setReadPointer($headersPosEnd + strlen($headerBodySeparator));
while (false !== ($buffer = $emailStream->read($bufferLength))) {
$bodyStream->write($buffer);
}
$bodyStream->commit();
return [$headers, $bodyStream];
}
|
[
"protected",
"function",
"parseStream",
"(",
"Swift_OutputByteStream",
"$",
"emailStream",
")",
"{",
"$",
"bufferLength",
"=",
"78",
";",
"$",
"headerData",
"=",
"''",
";",
"$",
"headerBodySeparator",
"=",
"\"\\r\\n\\r\\n\"",
";",
"$",
"emailStream",
"->",
"setReadPointer",
"(",
"0",
")",
";",
"// Read out the headers section from the stream to a string",
"while",
"(",
"false",
"!==",
"(",
"$",
"buffer",
"=",
"$",
"emailStream",
"->",
"read",
"(",
"$",
"bufferLength",
")",
")",
")",
"{",
"$",
"headerData",
".=",
"$",
"buffer",
";",
"$",
"headersPosEnd",
"=",
"strpos",
"(",
"$",
"headerData",
",",
"$",
"headerBodySeparator",
")",
";",
"// Stop reading if we found the end of the headers",
"if",
"(",
"false",
"!==",
"$",
"headersPosEnd",
")",
"{",
"break",
";",
"}",
"}",
"// Split the header data into lines",
"$",
"headerData",
"=",
"trim",
"(",
"substr",
"(",
"$",
"headerData",
",",
"0",
",",
"$",
"headersPosEnd",
")",
")",
";",
"$",
"headerLines",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headerData",
")",
";",
"unset",
"(",
"$",
"headerData",
")",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"currentHeaderName",
"=",
"''",
";",
"// Transform header lines into an associative array",
"foreach",
"(",
"$",
"headerLines",
"as",
"$",
"headerLine",
")",
"{",
"// Handle headers that span multiple lines",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"headerLine",
",",
"':'",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"currentHeaderName",
"]",
".=",
"' '",
".",
"trim",
"(",
"$",
"headerLine",
")",
";",
"continue",
";",
"}",
"$",
"header",
"=",
"explode",
"(",
"':'",
",",
"$",
"headerLine",
",",
"2",
")",
";",
"$",
"currentHeaderName",
"=",
"strtolower",
"(",
"$",
"header",
"[",
"0",
"]",
")",
";",
"$",
"headers",
"[",
"$",
"currentHeaderName",
"]",
"=",
"trim",
"(",
"$",
"header",
"[",
"1",
"]",
")",
";",
"}",
"// Read the entire email body into a byte stream",
"$",
"bodyStream",
"=",
"new",
"Swift_ByteStream_TemporaryFileByteStream",
"(",
")",
";",
"// Skip the header and separator and point to the body",
"$",
"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.
@return array
|
[
"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",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/SMimeSigner.php#L467-L521
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/MimePart.php
|
Swift_Mime_MimePart.setCharset
|
public function setCharset($charset)
{
$this->setHeaderParameter('Content-Type', 'charset', $charset);
if ($charset !== $this->userCharset) {
$this->clearCache();
}
$this->userCharset = $charset;
parent::charsetChanged($charset);
return $this;
}
|
php
|
public function setCharset($charset)
{
$this->setHeaderParameter('Content-Type', 'charset', $charset);
if ($charset !== $this->userCharset) {
$this->clearCache();
}
$this->userCharset = $charset;
parent::charsetChanged($charset);
return $this;
}
|
[
"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.
@param string $charset
@return $this
|
[
"Set",
"the",
"character",
"set",
"of",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/MimePart.php#L83-L93
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/MimePart.php
|
Swift_Mime_MimePart.setDelSp
|
public function setDelSp($delsp = true)
{
$this->setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
$this->userDelSp = $delsp;
return $this;
}
|
php
|
public function setDelSp($delsp = true)
{
$this->setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
$this->userDelSp = $delsp;
return $this;
}
|
[
"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.
@param bool $delsp
@return $this
|
[
"Turn",
"delsp",
"on",
"or",
"off",
"for",
"this",
"entity",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/MimePart.php#L137-L143
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/MimePart.php
|
Swift_Mime_MimePart.fixHeaders
|
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);
}
}
|
php
|
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);
}
}
|
[
"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
|
[
"Fix",
"the",
"content",
"-",
"type",
"and",
"encoding",
"of",
"this",
"entity"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/MimePart.php#L169-L181
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/MimePart.php
|
Swift_Mime_MimePart.convertString
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Encode",
"charset",
"when",
"charset",
"is",
"not",
"utf",
"-",
"8"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/MimePart.php#L190-L198
|
train
|
yiisoft/yii
|
framework/web/filters/CHttpCacheFilter.php
|
CHttpCacheFilter.sendCacheControlHeader
|
protected function sendCacheControlHeader()
{
if(Yii::app()->session->isStarted)
{
Yii::app()->session->setCacheLimiter('public');
header('Pragma:',true);
}
header('Cache-Control: '.$this->cacheControl,true);
}
|
php
|
protected function sendCacheControlHeader()
{
if(Yii::app()->session->isStarted)
{
Yii::app()->session->setCacheLimiter('public');
header('Pragma:',true);
}
header('Cache-Control: '.$this->cacheControl,true);
}
|
[
"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
@see cacheControl
@since 1.1.12
|
[
"Sends",
"the",
"cache",
"control",
"header",
"to",
"the",
"client"
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/filters/CHttpCacheFilter.php#L192-L200
|
train
|
yiisoft/yii
|
framework/web/renderers/CViewRenderer.php
|
CViewRenderer.getViewFile
|
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';
}
|
php
|
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';
}
|
[
"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.
@param string $file source view file path
@return string resulting view file path
|
[
"Generates",
"the",
"resulting",
"view",
"file",
"path",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/renderers/CViewRenderer.php#L84-L96
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.up
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
@return boolean Returning false means, the migration will not be applied.
|
[
"This",
"method",
"contains",
"the",
"logic",
"to",
"be",
"executed",
"when",
"applying",
"this",
"migration",
".",
"Child",
"classes",
"may",
"implement",
"this",
"method",
"to",
"provide",
"actual",
"migration",
"logic",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L48-L67
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.down
|
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;
}
}
|
php
|
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;
}
}
|
[
"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.
@return boolean Returning false means, the migration will not be applied.
|
[
"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",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L74-L93
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.insert
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table that new rows will be inserted into.
@param array $columns the column data (name=>value) to be inserted into the table.
|
[
"Creates",
"and",
"executes",
"an",
"INSERT",
"SQL",
"statement",
".",
"The",
"method",
"will",
"properly",
"escape",
"the",
"column",
"names",
"and",
"bind",
"the",
"values",
"to",
"be",
"inserted",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L174-L180
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.insertMultiple
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table that new rows will be inserted into.
@param array $data an array of various column data (name=>value) to be inserted into the table.
@since 1.1.16
|
[
"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",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L189-L197
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.update
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table to be updated.
@param array $columns the column data (name=>value) to be updated.
@param mixed $conditions the conditions that will be put in the WHERE part. Please
refer to {@link CDbCommand::where} on how to specify conditions.
@param array $params the parameters to be bound to the query.
|
[
"Creates",
"and",
"executes",
"an",
"UPDATE",
"SQL",
"statement",
".",
"The",
"method",
"will",
"properly",
"escape",
"the",
"column",
"names",
"and",
"bind",
"the",
"values",
"to",
"be",
"updated",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L208-L214
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.delete
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table where the data will be deleted from.
@param mixed $conditions the conditions that will be put in the WHERE part. Please
refer to {@link CDbCommand::where} on how to specify conditions.
@param array $params the parameters to be bound to the query.
|
[
"Creates",
"and",
"executes",
"a",
"DELETE",
"SQL",
"statement",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L223-L229
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.createTable
|
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";
}
|
php
|
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";
}
|
[
"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.
The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'),
where name stands for a column name which will be properly quoted by the method, and definition
stands for the column type which can contain an abstract DB type.
The {@link getColumnType} method will be invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
inserted into the generated SQL.
@param string $table the name of the table to be created. The name will be properly quoted by the method.
@param array $columns the columns (name=>definition) in the new table.
@param string $options additional SQL fragment that will be appended to the generated SQL.
|
[
"Builds",
"and",
"executes",
"a",
"SQL",
"statement",
"for",
"creating",
"a",
"new",
"DB",
"table",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L246-L252
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.renameTable
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table to be renamed. The name will be properly quoted by the method.
@param string $newName the new table name. The name will be properly quoted by the method.
|
[
"Builds",
"and",
"executes",
"a",
"SQL",
"statement",
"for",
"renaming",
"a",
"DB",
"table",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L259-L265
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.dropColumn
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
@param string $column the name of the column to be dropped. The name will be properly quoted by the method.
|
[
"Builds",
"and",
"executes",
"a",
"SQL",
"statement",
"for",
"dropping",
"a",
"DB",
"column",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L312-L318
|
train
|
yiisoft/yii
|
framework/db/CDbMigration.php
|
CDbMigration.renameColumn
|
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";
}
|
php
|
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";
}
|
[
"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.
@param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
@param string $name the old name of the column. The name will be properly quoted by the method.
@param string $newName the new name of the column. The name will be properly quoted by the method.
|
[
"Builds",
"and",
"executes",
"a",
"SQL",
"statement",
"for",
"renaming",
"a",
"column",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L326-L332
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.