Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fMailbox.php handling 5.6+ Security #218

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions fMailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,6 @@ static private function handlePart($info, $structure)
}
}

// This indicates a content-id which is used for multipart/related
if ($structure['content_id']) {
if (!isset($info['related'])) {
$info['related'] = array();
}
$cid = $structure['content_id'][0] == '<' ? substr($structure['content_id'], 1, -1) : $structure['content_id'];
$info['related']['cid:' . $cid] = array(
'mimetype' => $structure['type'] . '/' . $structure['subtype'],
'data' => $content
);
return $info;
}


$has_disposition = !empty($structure['disposition']);
$is_text = $structure['type'] == 'text' && $structure['subtype'] == 'plain';
$is_html = $structure['type'] == 'text' && $structure['subtype'] == 'html';
Expand Down Expand Up @@ -262,6 +248,20 @@ static private function handlePart($info, $structure)
}
}

// This indicates a content-id which is used for multipart/related
if ($structure['content_id'] && $structure['disposition'] == 'inline') {
if (!isset($info['related'])) {
$info['related'] = array();
}
$cid = $structure['content_id'][0] == '<' ? substr($structure['content_id'], 1, -1) : $structure['content_id'];
$info['related']['cid:' . $cid] = array(
'filename' => $filename,
'mimetype' => $structure['type'] . '/' . $structure['subtype'],
'data' => $content
);
return $info;
}

// This automatically handles primary content that has a content-disposition header on it
if ($structure['disposition'] == 'inline' && $filename === '') {
if ($is_text && !isset($info['text'])) {
Expand Down Expand Up @@ -567,7 +567,7 @@ static private function parseHeaders($headers, $filter=NULL)
}

} elseif ($header == 'references') {
$headers[$header] = array_map(array('fMailbox', 'decodeHeader'), preg_split('#(?<=>)\s+(?=<)#', $value));
$headers[$header] = array_map(array('fMailbox', 'decodeHeader'), preg_split('#(?<=>)[^<]*?(?=<)#', $value));

} elseif ($header == 'received') {
if (!isset($headers[$header])) {
Expand Down Expand Up @@ -965,13 +965,30 @@ private function connect()

fCore::startErrorCapture(E_WARNING);

$this->connection = fsockopen(
$this->secure ? 'tls://' . $this->host : $this->host,
$this->port,
$error_number,
$error_string,
$this->timeout
);
if ($this->secure) {
$this->connection = stream_socket_client(
'tls://' . $this->host . ':' . $this->port,
$error_number,
$error_string,
$this->timeout,
STREAM_CLIENT_CONNECT,
stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'disable_compression' => true,
)
))
);
} else {
$this->connection = fsockopen(
$this->host,
$this->port,
$error_number,
$error_string,
$this->timeout
);
}

foreach (fCore::stopErrorCapture('#ssl#i') as $error) {
throw new fConnectivityException('There was an error connecting to the server. A secure connection was requested, but was not available. Try a non-secure connection instead.');
Expand Down Expand Up @@ -1522,4 +1539,4 @@ private function write($command, $expected=NULL)
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
*/