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
3f04bca1
Commit
3f04bca1
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Add EmailDataParser class - to be used by API.
parent
c27bf65f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.mailparse.php
+92
-2
92 additions, 2 deletions
include/class.mailparse.php
with
92 additions
and
2 deletions
include/class.mailparse.php
+
92
−
2
View file @
3f04bca1
...
...
@@ -15,8 +15,8 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once
(
'Mail/mimeDecode.php'
);
require_once
(
'Mail/RFC822.php'
);
require_once
(
PEAR_DIR
.
'Mail/mimeDecode.php'
);
require_once
(
PEAR_DIR
.
'Mail/RFC822.php'
);
class
Mail_Parse
{
...
...
@@ -231,4 +231,94 @@ class Mail_Parse {
function
parseAddressList
(
$address
){
return
Mail_RFC822
::
parseAddressList
(
$address
,
null
,
null
,
false
);
}
function
parse
(
$rawemail
)
{
$parser
=
new
Mail_Parse
(
$rawemail
);
return
(
$parser
&&
$parser
->
decode
())
?
$parser
:
null
;
}
}
class
EmailDataParser
{
var
$stream
;
var
$error
;
function
EmailDataParser
(
$stream
=
null
)
{
$this
->
stream
=
$stream
;
}
function
parse
(
$stream
)
{
$contents
=
''
;
if
(
is_resource
(
$stream
))
{
while
(
!
feof
(
$stream
))
$contents
.
=
fread
(
$stream
,
8192
);
}
else
{
$contents
=
$stream
;
}
$parser
=
new
Mail_Parse
(
$contents
);
if
(
!
$parser
->
decode
())
//Decode...returns false on decoding errors
return
$this
->
err
(
'Email parse failed ['
.
$parser
->
getError
()
.
']'
);
$data
=
array
();
//FROM address: who sent the email.
if
((
$fromlist
=
$parser
->
getFromAddressList
())
&&
!
PEAR
::
isError
(
$fromlist
))
{
$from
=
$fromlist
[
0
];
//Default.
foreach
(
$fromlist
as
$fromobj
)
{
if
(
!
Validator
::
is_email
(
$fromobj
->
mailbox
.
'@'
.
$fromobj
->
host
))
continue
;
$from
=
$fromobj
;
break
;
}
$data
[
'name'
]
=
trim
(
$from
->
personal
,
'"'
);
if
(
$from
->
comment
&&
$from
->
comment
[
0
])
$data
[
'name'
]
.
=
' ('
.
$from
->
comment
[
0
]
.
')'
;
$data
[
'email'
]
=
$from
->
mailbox
.
'@'
.
$from
->
host
;
}
//TO Address:Try to figure out the email address... associated with the incoming email.
$emailId
=
0
;
if
((
$tolist
=
$parser
->
getToAddressList
()))
{
foreach
(
$tolist
as
$toaddr
)
{
if
((
$emailId
=
Email
::
getIdByEmail
(
$toaddr
->
mailbox
.
'@'
.
$toaddr
->
host
)))
break
;
}
}
//maybe we got CC'ed??
if
(
!
$emailId
&&
(
$cclist
=
$parser
->
getCcAddressList
()))
{
foreach
(
$cclist
as
$ccaddr
)
{
if
((
$emailId
=
Email
::
getIdByEmail
(
$ccaddr
->
mailbox
.
'@'
.
$ccaddr
->
host
)))
break
;
}
}
$data
[
'subject'
]
=
Format
::
utf8encode
(
$parser
->
getSubject
());
$data
[
'message'
]
=
Format
::
utf8encode
(
Format
::
stripEmptyLines
(
$parser
->
getBody
()));
$data
[
'header'
]
=
$parser
->
getHeader
();
$data
[
'mid'
]
=
$parser
->
getMessageId
();
$data
[
'priorityId'
]
=
$parser
->
getPriority
();
$data
[
'emailId'
]
=
$emailId
;
//attachments XXX: worry about encoding??
$data
[
'attachments'
]
=
$parser
->
getAttachments
();
return
$data
;
}
function
err
(
$error
)
{
$this
->
error
=
$error
;
return
false
;
}
function
getError
()
{
return
$this
->
lastError
();
}
function
lastError
()
{
return
$this
->
error
;
}
}
?>
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