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
542071af
Commit
542071af
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Move encoding to Format class - to be used system wide.
parent
1e359e55
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.format.php
+25
-0
25 additions, 0 deletions
include/class.format.php
include/class.mailfetch.php
+4
-17
4 additions, 17 deletions
include/class.mailfetch.php
with
29 additions
and
17 deletions
include/class.format.php
+
25
−
0
View file @
542071af
...
@@ -46,6 +46,31 @@ class Format {
...
@@ -46,6 +46,31 @@ class Format {
return
$result
?
array_filter
(
$result
)
:
$files
;
return
$result
?
array_filter
(
$result
)
:
$files
;
}
}
/* encode text into desired encoding - taking into accout charset when available. */
function
encode
(
$text
,
$charset
=
null
,
$encoding
=
'utf-8'
)
{
//Try auto-detecting charset/encoding
if
(
!
$charset
&&
function_exists
(
'mb_detect_encoding'
))
$charset
=
mb_detect_encoding
(
$text
);
//Cleanup - junk
if
(
$charset
&&
in_array
(
trim
(
$charset
),
array
(
'default'
,
'x-user-defined'
)))
$charset
=
'ASCII'
;
if
(
function_exists
(
'iconv'
)
&&
$charset
)
return
iconv
(
$charset
,
$encoding
.
'//IGNORE'
,
$text
);
elseif
(
function_exists
(
'iconv_mime_decode'
))
return
iconv_mime_decode
(
$text
,
0
,
$encoding
);
else
//default to utf8 encoding.
return
utf8_encode
(
$text
);
}
//Wrapper for utf-8 encoding.
function
utf8encode
(
$text
,
$charset
=
null
)
{
return
Format
::
enecode
(
$text
,
$charset
,
'utf-8'
);
}
function
phone
(
$phone
)
{
function
phone
(
$phone
)
{
$stripped
=
preg_replace
(
"/[^0-9]/"
,
""
,
$phone
);
$stripped
=
preg_replace
(
"/[^0-9]/"
,
""
,
$phone
);
...
...
This diff is collapsed.
Click to expand it.
include/class.mailfetch.php
+
4
−
17
View file @
542071af
...
@@ -194,30 +194,17 @@ class MailFetcher {
...
@@ -194,30 +194,17 @@ class MailFetcher {
}
}
//Convert text to desired encoding..defaults to utf8
//Convert text to desired encoding..defaults to utf8
function
mime_encode
(
$text
,
$charset
=
null
,
$enc
=
'utf-8'
)
{
//Thank in part to afterburner
function
mime_encode
(
$text
,
$charset
=
null
,
$encoding
=
'utf-8'
)
{
//Thank in part to afterburner
return
Format
::
encode
(
$text
,
$charset
,
$encoding
);
if
(
$charset
&&
in_array
(
trim
(
$charset
),
array
(
'default'
,
'x-user-defined'
)))
$charset
=
'ASCII'
;
if
(
function_exists
(
'iconv'
)
and
(
$charset
or
function_exists
(
'mb_detect_encoding'
)))
{
if
(
$charset
)
return
iconv
(
$charset
,
$enc
.
'//IGNORE'
,
$text
);
elseif
(
function_exists
(
'mb_detect_encoding'
))
return
iconv
(
mb_detect_encoding
(
$text
,
$this
->
encodings
),
$enc
,
$text
);
}
elseif
(
function_exists
(
'iconv_mime_decode'
))
{
return
iconv_mime_decode
(
$text
,
0
,
$enc
);
}
return
utf8_encode
(
$text
);
}
}
//Generic decoder - resulting text is utf8 encoded -> mirrors imap_utf8
//Generic decoder - resulting text is utf8 encoded -> mirrors imap_utf8
function
mime_decode
(
$text
,
$enc
=
'utf-8'
)
{
function
mime_decode
(
$text
,
$enc
oding
=
'utf-8'
)
{
$str
=
''
;
$str
=
''
;
$parts
=
imap_mime_header_decode
(
$text
);
$parts
=
imap_mime_header_decode
(
$text
);
foreach
(
$parts
as
$part
)
foreach
(
$parts
as
$part
)
$str
.
=
$this
->
mime_encode
(
$part
->
text
,
$part
->
charset
,
$enc
);
$str
.
=
$this
->
mime_encode
(
$part
->
text
,
$part
->
charset
,
$enc
oding
);
return
$str
?
$str
:
imap_utf8
(
$text
);
return
$str
?
$str
:
imap_utf8
(
$text
);
}
}
...
...
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