Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
ad54dda1
Commit
ad54dda1
authored
11 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Parse collaborators from email header.
parent
77df040b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/api.tickets.php
+4
-1
4 additions, 1 deletion
include/api.tickets.php
include/class.mailfetch.php
+29
-17
29 additions, 17 deletions
include/class.mailfetch.php
include/class.mailparse.php
+33
-11
33 additions, 11 deletions
include/class.mailparse.php
with
66 additions
and
29 deletions
include/api.tickets.php
+
4
−
1
View file @
ad54dda1
...
...
@@ -39,7 +39,10 @@ class TicketApiController extends ApiController {
if
(
!
strcasecmp
(
$format
,
'email'
))
{
$supported
=
array_merge
(
$supported
,
array
(
'header'
,
'mid'
,
'emailId'
,
'ticketId'
,
'reply-to'
,
'reply-to-name'
,
'in-reply-to'
,
'references'
));
'in-reply-to'
,
'references'
,
'collaborators'
=>
array
(
"*"
=>
array
(
"name"
,
"email"
))
));
$supported
[
'attachments'
][
'*'
][]
=
'cid'
;
}
...
...
This diff is collapsed.
Click to expand it.
include/class.mailfetch.php
+
29
−
17
View file @
ad54dda1
...
...
@@ -269,9 +269,9 @@ class MailFetcher {
$sender
=
$headerinfo
->
from
[
0
];
//Just what we need...
$header
=
array
(
'name'
=>@
$sender
->
personal
,
$header
=
array
(
'name'
=>
$this
->
mime_decode
(
@
$sender
->
personal
)
,
'email'
=>
trim
(
strtolower
(
$sender
->
mailbox
)
.
'@'
.
$sender
->
host
),
'subject'
=>@
$headerinfo
->
subject
,
'subject'
=>
$this
->
mime_decode
(
@
$headerinfo
->
subject
)
,
'mid'
=>
trim
(
@
$headerinfo
->
message_id
),
'header'
=>
$this
->
getHeader
(
$mid
),
'in-reply-to'
=>
$headerinfo
->
in_reply_to
,
...
...
@@ -283,22 +283,33 @@ class MailFetcher {
$header
[
'reply-to-name'
]
=
$replyto
[
0
]
->
personal
;
}
//Try to determine target email - useful when fetched inbox has
// aliases that are independent emails within osTicket.
$emailId
=
0
;
// Put together a list of recipients
$tolist
=
array
();
if
(
$headerinfo
->
to
)
$tolist
=
array_merge
(
$tolist
,
$headerinfo
->
to
);
if
(
$headerinfo
->
cc
)
$tolist
=
array_merge
(
$tolist
,
$headerinfo
->
cc
);
if
(
$headerinfo
->
bcc
)
$tolist
=
array_merge
(
$tolist
,
$headerinfo
->
bcc
);
foreach
(
$tolist
as
$addr
)
if
((
$emailId
=
Email
::
getIdByEmail
(
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
)))
break
;
$header
[
'collaborators'
]
=
array
();
foreach
(
$tolist
as
$addr
)
{
if
(
!
(
$emailId
=
Email
::
getIdByEmail
(
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
)))
{
$header
[
'collaborators'
][]
=
array
(
'name'
=>
$this
->
mime_decode
(
@
$addr
->
personal
),
'email'
=>
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
);
}
elseif
(
!
$header
[
'emailId'
])
{
$header
[
'emailId'
]
=
$emailId
;
}
}
$header
[
'emailId'
]
=
$emailId
;
//BCCed?
if
(
!
$header
[
'emailId'
])
{
unset
(
$header
[
'collaborators'
]);
//Nuke the recipients - we were bcced
if
(
$headerinfo
->
bcc
)
foreach
(
$headerinfo
->
bcc
as
$addr
)
if
(
!
$header
[
'emailId'
]
&&
(
$emailId
=
Email
::
getIdByEmail
(
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
)))
$header
[
'emailId'
]
=
$emailId
;
}
// Ensure we have a message-id. If unable to read it out of the
// email, use the hash of the entire email headers
...
...
@@ -485,18 +496,18 @@ class MailFetcher {
}
$vars
=
$mailinfo
;
$vars
[
'name'
]
=
$this
->
mime_decode
(
$mailinfo
[
'name'
]
)
;
$vars
[
'subject'
]
=
$mailinfo
[
'subject'
]
?
$this
->
mime_decode
(
$mailinfo
[
'subject'
]
)
:
'[No Subject]'
;
$vars
[
'message'
]
=
Format
::
stripEmptyLines
(
$this
->
getBody
(
$mid
));
$vars
[
'emailId'
]
=
$mailinfo
[
'emailId'
]
?
$mailinfo
[
'emailId'
]
:
$this
->
getEmailId
();
$vars
[
'name'
]
=
$mailinfo
[
'name'
];
$vars
[
'subject'
]
=
$mailinfo
[
'subject'
]
?
$mailinfo
[
'subject'
]
:
'[No Subject]'
;
$vars
[
'message'
]
=
Format
::
stripEmptyLines
(
$this
->
getBody
(
$mid
));
$vars
[
'emailId'
]
=
$mailinfo
[
'emailId'
]
?
$mailinfo
[
'emailId'
]
:
$this
->
getEmailId
();
//Missing FROM name - use email address.
if
(
!
$vars
[
'name'
])
$vars
[
'name'
]
=
$vars
[
'email'
];
list
(
$vars
[
'name'
]
)
=
explode
(
'@'
,
$vars
[
'email'
]
)
;
//An email with just attachments can have empty body.
if
(
!
$vars
[
'message'
])
$vars
[
'message'
]
=
'-'
;
$vars
[
'message'
]
=
'-
-
'
;
if
(
$ost
->
getConfig
()
->
useEmailPriority
())
$vars
[
'priorityId'
]
=
$this
->
getPriority
(
$mid
);
...
...
@@ -565,6 +576,7 @@ class MailFetcher {
return
null
;
}
return
$ticket
;
}
...
...
This diff is collapsed.
Click to expand it.
include/class.mailparse.php
+
33
−
11
View file @
ad54dda1
...
...
@@ -154,6 +154,13 @@ class Mail_Parse {
return
Mail_Parse
::
parseAddressList
(
$header
);
}
function
getBccAddressList
(){
if
(
!
(
$header
=
$this
->
struct
->
headers
[
'bcc'
]))
return
null
;
return
Mail_Parse
::
parseAddressList
(
$header
);
}
function
getMessageId
(){
return
$this
->
struct
->
headers
[
'message-id'
];
}
...
...
@@ -378,19 +385,35 @@ class EmailDataParser {
}
//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
;
$data
[
'emailId'
]
=
0
;
$data
[
'collaborators'
]
=
array
();
$tolist
=
array
();
if
((
$to
=
$parser
->
getToAddressList
()))
$tolist
=
array_merge
(
$tolist
,
$to
);
if
((
$cc
=
$parser
->
getCcAddressList
()))
$tolist
=
array_merge
(
$tolist
,
$cc
);
foreach
(
$tolist
as
$addr
)
{
if
(
!
(
$emailId
=
Email
::
getIdByEmail
(
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
)))
{
$data
[
'collaborators'
][]
=
array
(
'name'
=>
trim
(
@
$addr
->
personal
,
'"'
),
'email'
=>
strtolower
(
$addr
->
mailbox
)
.
'@'
.
$addr
->
host
);
}
elseif
(
!
$data
[
'emailId'
])
{
$data
[
'emailId'
]
=
$emailId
;
}
}
//maybe we got CC'ed??
if
(
!
$emailId
&&
(
$cclist
=
$parser
->
getCcAddressList
()))
{
foreach
(
$cclist
as
$ccaddr
)
{
if
((
$emailId
=
Email
::
getIdByEmail
(
$ccaddr
->
mailbox
.
'@'
.
$ccaddr
->
host
)))
break
;
//maybe we got BCC'ed??
if
(
!
$data
[
'emailId'
])
{
unset
(
$data
[
'collaborators'
]);
$emailId
=
0
;
if
(
$bcc
=
$parser
->
getBccAddressList
())
foreach
(
$bcc
as
$addr
)
{
if
((
$emailId
=
Email
::
getIdByEmail
(
$addr
->
mailbox
.
'@'
.
$addr
->
host
)))
break
;
}
$data
[
'emailId'
]
=
$emailId
;
}
$data
[
'subject'
]
=
$parser
->
getSubject
();
...
...
@@ -398,7 +421,6 @@ class EmailDataParser {
$data
[
'header'
]
=
$parser
->
getHeader
();
$data
[
'mid'
]
=
$parser
->
getMessageId
();
$data
[
'priorityId'
]
=
$parser
->
getPriority
();
$data
[
'emailId'
]
=
$emailId
;
$data
[
'in-reply-to'
]
=
$parser
->
struct
->
headers
[
'in-reply-to'
];
$data
[
'references'
]
=
$parser
->
struct
->
headers
[
'references'
];
...
...
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