Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
php-emailcatcher
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
php-emailcatcher
Commits
3cfd1b66
Commit
3cfd1b66
authored
8 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
email catcher class: detect parse error when reading email data
parent
27ef9263
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
classes/emailcatcher.class.php
+28
-1
28 additions, 1 deletion
classes/emailcatcher.class.php
with
28 additions
and
1 deletion
classes/emailcatcher.class.php
+
28
−
1
View file @
3cfd1b66
...
@@ -12,22 +12,36 @@
...
@@ -12,22 +12,36 @@
*
*
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
* 2024-10-08 v0.1 initial version
* 2024-10-08 v0.1 initial version
* 2024-10-16 v0.2 detect parse error when reading email data
* =======================================================================
* =======================================================================
*/
*/
class
emailcatcher
class
emailcatcher
{
{
/**
* Filename for email data
* @var string
*/
protected
string
$sMailData
=
'emaildata.txt'
;
protected
string
$sMailData
=
'emaildata.txt'
;
/**
* Id of selected email
* @var string
*/
protected
string
$sId
=
''
;
protected
string
$sId
=
''
;
/**
* Email data of the selected email
* @var array
*/
protected
array
$aSelectedEmail
=
[];
protected
array
$aSelectedEmail
=
[];
// ------------------------------------------------------------------
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
sMailData
=
dirname
(
__DIR__
)
.
'/data/'
.
$this
->
sMailData
;
$this
->
sMailData
=
dirname
(
__DIR__
)
.
'/data/'
.
$this
->
sMailData
;
// $this->_readEmails();
}
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
...
@@ -37,6 +51,7 @@ class emailcatcher
...
@@ -37,6 +51,7 @@ class emailcatcher
/**
/**
* Fetch email of a single email from stdin and store it.
* Fetch email of a single email from stdin and store it.
* It returns the return value of file_put_contents().
* It returns the return value of file_put_contents().
* used in php-sendmail.php
*
*
* @return bool|int
* @return bool|int
*/
*/
...
@@ -70,6 +85,11 @@ class emailcatcher
...
@@ -70,6 +85,11 @@ class emailcatcher
// ------------------------------------------------------------------
// ------------------------------------------------------------------
/**
* Read all stored emails and return them as an array
* @param string $sEmail2Show optional: id of email to show
* @return array
*/
protected
function
_readEmails
(
string
$sEmail2Show
=
''
):
array
protected
function
_readEmails
(
string
$sEmail2Show
=
''
):
array
{
{
if
(
!
file_exists
(
$this
->
sMailData
)){
if
(
!
file_exists
(
$this
->
sMailData
)){
...
@@ -77,7 +97,14 @@ class emailcatcher
...
@@ -77,7 +97,14 @@ class emailcatcher
}
}
foreach
(
file
(
$this
->
sMailData
)
as
$line
)
{
foreach
(
file
(
$this
->
sMailData
)
as
$line
)
{
if
(
empty
(
trim
(
$line
)))
{
continue
;
}
$aLinedata
=
json_decode
(
$line
,
true
);
$aLinedata
=
json_decode
(
$line
,
true
);
if
(
!
is_array
(
$aLinedata
)){
// echo "ERROR: unable to parse line as single json object: <code>$line</code>";
continue
;
}
[
$sHead
,
$sBody
]
=
explode
(
"
\r\n\r\n
"
,
$aLinedata
[
'mail'
]);
[
$sHead
,
$sBody
]
=
explode
(
"
\r\n\r\n
"
,
$aLinedata
[
'mail'
]);
$sHead
=
"
\n
$sHead
"
;
$sHead
=
"
\n
$sHead
"
;
...
...
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