Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
5ae4fe6b
Commit
5ae4fe6b
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
mail-parse: Reduce memory overhead of parsing large mails
parent
21949b25
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.mailparse.php
+7
-7
7 additions, 7 deletions
include/class.mailparse.php
include/pear/Mail/mimeDecode.php
+14
-18
14 additions, 18 deletions
include/pear/Mail/mimeDecode.php
with
21 additions
and
25 deletions
include/class.mailparse.php
+
7
−
7
View file @
5ae4fe6b
...
...
@@ -32,9 +32,9 @@ class Mail_Parse {
var
$tnef
=
false
;
// TNEF encoded mail
function
Mail_parse
(
$mimeMessage
,
$charset
=
null
){
function
Mail_parse
(
&
$mimeMessage
,
$charset
=
null
){
$this
->
mime_message
=
$mimeMessage
;
$this
->
mime_message
=
&
$mimeMessage
;
if
(
$charset
)
$this
->
charset
=
$charset
;
...
...
@@ -54,18 +54,18 @@ class Mail_Parse {
$params
=
array
(
'crlf'
=>
"
\r\n
"
,
'charset'
=>
$this
->
charset
,
'input'
=>
$this
->
mime_message
,
'include_bodies'
=>
$this
->
include_bodies
,
'decode_headers'
=>
$this
->
decode_headers
,
'decode_bodies'
=>
$this
->
decode_bodies
);
$this
->
struct
=
Mail_mimeDecode
::
decode
(
$params
);
$this
->
splitBodyHeader
();
$decoder
=
new
Mail_mimeDecode
(
$this
->
mime_message
);
$this
->
struct
=
$decoder
->
decode
(
$params
);
if
(
PEAR
::
isError
(
$this
->
struct
))
return
false
;
$this
->
splitBodyHeader
();
// Handle wrapped emails when forwarded
if
(
$this
->
struct
&&
$this
->
struct
->
parts
)
{
$outer
=
$this
->
struct
;
...
...
@@ -119,7 +119,7 @@ class Mail_Parse {
function
splitBodyHeader
()
{
$match
=
array
();
if
(
preg_match
(
"/^(.*?)
\r
?
\n\r
?
\n
(.*)
/s"
,
if
(
preg_match
(
"/^(.*?)
\r
?
\n\r
?
\n
.
/s"
,
$this
->
mime_message
,
$match
))
{
$this
->
header
=
$match
[
1
];
...
...
This diff is collapsed.
Click to expand it.
include/pear/Mail/mimeDecode.php
+
14
−
18
View file @
5ae4fe6b
...
...
@@ -91,14 +91,6 @@ require_once 'PEAR.php';
*/
class
Mail_mimeDecode
extends
PEAR
{
/**
* The raw email to decode
*
* @var string
* @access private
*/
var
$_input
;
/**
* The header part of the input
*
...
...
@@ -157,13 +149,13 @@ class Mail_mimeDecode extends PEAR
* @param string The input to decode
* @access public
*/
function
Mail_mimeDecode
(
$input
)
function
Mail_mimeDecode
(
&
$input
)
{
list
(
$header
,
$body
)
=
$this
->
_splitBodyHeader
(
$input
);
$this
->
_input
=
$input
;
$this
->
_header
=
$header
;
$this
->
_body
=
$body
;
$this
->
_input
=
&
$input
;
$this
->
_header
=
&
$header
;
$this
->
_body
=
&
$body
;
$this
->
_decode_bodies
=
false
;
$this
->
_include_bodies
=
true
;
}
...
...
@@ -241,7 +233,7 @@ class Mail_mimeDecode extends PEAR
* @return object Results of decoding process
* @access private
*/
function
_decode
(
$headers
,
$body
,
$default_ctype
=
'text/plain'
)
function
_decode
(
&
$headers
,
&
$body
,
$default_ctype
=
'text/plain'
)
{
$return
=
new
stdClass
;
$return
->
headers
=
array
();
...
...
@@ -324,8 +316,9 @@ class Mail_mimeDecode extends PEAR
$default_ctype
=
(
strtolower
(
$content_type
[
'value'
])
===
'multipart/digest'
)
?
'message/rfc822'
:
'text/plain'
;
$parts
=
$this
->
_boundarySplit
(
$body
,
$content_type
[
'other'
][
'boundary'
]);
for
(
$i
=
0
;
$i
<
count
(
$parts
);
$i
++
)
{
list
(
$part_header
,
$part_body
)
=
$this
->
_splitBodyHeader
(
$parts
[
$i
]);
while
(
count
(
$parts
))
{
$part
=
array_shift
(
$parts
);
list
(
$part_header
,
$part_body
)
=
$this
->
_splitBodyHeader
(
$part
);
$part
=
$this
->
_decode
(
$part_header
,
$part_body
,
$default_ctype
);
if
(
$part
===
false
)
$part
=
$this
->
raiseError
(
$this
->
_error
);
...
...
@@ -409,10 +402,13 @@ class Mail_mimeDecode extends PEAR
* @return array Contains header and body section
* @access private
*/
function
_splitBodyHeader
(
$input
)
function
_splitBodyHeader
(
&
$input
)
{
if
(
preg_match
(
"/^(.*?)
\r
?
\n\r
?
\n
(.*)/s"
,
$input
,
$match
))
{
return
array
(
$match
[
1
],
$match
[
2
]);
// The headers should end within the first 500k of the email...
$to_check
=
substr
(
$input
,
0
,
500
<<
10
);
if
(
preg_match
(
"/^.*?(
\r
?
\n\r
?
\n
)(.)/s"
,
$to_check
,
$match
,
PREG_OFFSET_CAPTURE
))
{
return
array
(
substr
(
$input
,
0
,
$match
[
1
][
1
]),
substr
(
$input
,
$match
[
2
][
1
]));
}
$this
->
_error
=
'Could not split header and body'
;
return
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment