切换导航条
此项目
正在载入...
登录
周海龙
/
mail-serve
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
邓超
6 months ago
提交
ba722dce20c3c3c326a9e3a7b2ed5f37754a1b6d
1 个父辈
c759e778
x
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
90 行增加
和
69 行删除
controller/Home.php
lib/Imap/Parse/Attachment.php
lib/Imap/Parse/Body.php
lib/Imap/Parse/Header.php
service/SyncMail.php
controller/Home.php
查看文件 @
ba722dc
...
...
@@ -13,6 +13,7 @@ use Model\listsSql;
use
Model\sendJobsSql
;
use
PHPMailer\PHPMailer\PHPMailer
;
use
PHPMailer\PHPMailer\SMTP
;
use
Service\SyncMail
;
use
function
Swoole
\Coroutine\Http\request
;
...
...
@@ -858,23 +859,10 @@ class Home extends Base {
// 是否再次 重新获取
$reload
=
app
()
->
request
(
'reload'
,
0
,
'intval'
);
if
(
$reload
){
// 删除原有数据
db
()
->
delete
(
bodySql
::
$table
,[
'lists_id'
=>
$id
]);
//同步基础信息
$mail
=
new
Mail
(
$email
[
'email'
],
base64_decode
(
$email
[
'password'
]),
$email
[
'imap'
]);
if
(
$mail
->
login
()
==
1
){
$folder
=
db
()
->
value
(
folderSql
::
first
([
'id'
=>
$data
[
'folder_id'
]],
'origin_folder'
));
if
(
$folder
){
$mail
->
client
->
selectFolder
(
$folder
);
$mail
->
syncUidEmail
([
$data
[
'uid'
]],
$email
[
'id'
],
$folder
,
$data
[
'folder_id'
],[],[],
db
());
}
}
}
HOME_INFO_BODY
:
$body
=
db
()
->
first
(
bodySql
::
first
(
$id
));
if
(
$body
){
if
(
$body
&&
!
$reload
){
$data
[
'body'
]
=
json_decode
(
$body
[
'text_html'
],
true
);
$charset
=
'utf-8'
;
...
...
@@ -897,8 +885,8 @@ class Home extends Base {
if
(
!
empty
(
$bd
[
'path'
])){
$data
[
'body'
][
$bdk
][
'name'
]
=
@
base64_decode
(
$bd
[
'name'
]);
$data
[
'body'
][
$bdk
][
'filename'
]
=
@
base64_decode
(
$bd
[
'filename'
]);
$data
[
'body'
][
$bdk
][
'name'
]
=
MailFun
::
isBase64
(
$bd
[
'name'
])
?
@
base64_decode
(
$bd
[
'name'
])
:
$bd
[
'name'
];
$data
[
'body'
][
$bdk
][
'filename'
]
=
MailFun
::
isBase64
(
$bd
[
'filename'
])
?
@
base64_decode
(
$bd
[
'filename'
])
:
$bd
[
'filename'
];
// 进行编码转换 会出现未知bug
// if($charset && strtolower($charset) != 'utf-8' && strtolower($charset) != 'utf8'){
// $data['body'][$bdk]['name'] = @iconv($charset,'utf-8',$data['body'][$bdk]['name']);
...
...
@@ -945,31 +933,17 @@ class Home extends Base {
'data' =>
$data
];
}
// 循环几次
if(
$data['uid']
&&
$sync_num
< 1){
$mail
= new Mail(
$email['email'],base64_decode($email['password']),$email['imap']
);
if(
$mail->login
()==1){
$folder
= db()->value(folderSql::first(['id'=>
$data['folder_id']]
,'origin_folder'));
if(
$folder
){
$ret
=
$mail->syncBody
(
$folder
,
$data['uid']
,
$id
);
$sync_num
++;
if(
$ret
){
goto HOME_INFO_BODY;
}
}
}
$folder
= db()->value(folderSql::first(['id'=>
$data['folder_id']]
,'origin_folder'));
(new SyncMail(
$data['email_id']))->mail($folder,[$data['uid']]
,true);
$sync_num
++;
$reload
= 0;
goto HOME_INFO_BODY;
}
logs('超过读取body次数 '.
$data['id']
);
if(isset(
$mail
)){
if(!
$mail->client
->hasMail(
$data['uid']
)){
app()->e('mail_not');
}
}
}else{
logs('读取body 没有查询到数据 '.
$id
.'-'.(
$email['email']
??''));
}
...
...
lib/Imap/Parse/Attachment.php
查看文件 @
ba722dc
...
...
@@ -98,19 +98,25 @@ class Attachment {
/**
* 保存 文件到目录
* @param string $filename 绝对路径的目录 文件名
* @return bool
* @param string $path 绝对路径的目录
* @param string $filename 文件名
* @return bool|string
* @author:dc
* @time 2024/9/21 17:10
*/
public
function
save
(
string
$filename
)
:
bool
{
$path
=
dirname
(
$filename
);
public
function
save
(
string
$path
,
string
$filename
=
''
)
:
bool
|
string
{
$filename
=
$filename
?
:
(
md5
(
$this
->
getContent
())
.
'.'
.
$this
->
getExtension
());
if
(
!
is_dir
(
$path
)){
@
mkdir
(
$path
,
0775
,
true
);
}
$path
=
rtrim
(
$path
,
'/'
)
.
'/'
;
// 保存文件
if
(
@
file_put_contents
(
$filename
,
$this
->
getContent
())){
return
true
;
if
(
@
file_put_contents
(
$path
.
$filename
,
$this
->
getContent
())){
return
$path
.
$filename
;
}
return
false
;
...
...
lib/Imap/Parse/Body.php
查看文件 @
ba722dc
...
...
@@ -244,6 +244,8 @@ class Body {
// 默认编码
if
(
!
$data
->
Charset
)
$data
->
Charset
=
'utf-8'
;
// 处理content id中意外的字符串
$data
->
set
(
'Content-ID'
,
trim
(
str_replace
([
'"'
,
'<'
,
'>'
],
''
,
$data
->
get
(
'Content-ID'
))));
return
$data
;
}
...
...
@@ -319,17 +321,24 @@ class Body {
* 读取附件 目前有2中
* 1是 attachment 附件 就是文件
* 2是 inline 是嵌套在html代码中的,一半情况只有图片才会这样做
* @param bool $inline 是否是读取嵌入html中的图片或者其他,一半情况 图片路径以 cid:xxx
* @param bool
|null
$inline 是否是读取嵌入html中的图片或者其他,一半情况 图片路径以 cid:xxx
* @return Attachment[]
* @author:dc
* @time 2024/9/23 10:23
*/
public
function
getAttachment
(
bool
$inline
=
false
)
:
array
{
public
function
getAttachment
(
bool
|
null
$inline
=
null
)
:
array
{
$attachment
=
[];
foreach
(
$this
->
items
as
$item
){
// 有的邮箱服务器 不带inline,就只有通过content-id来识别了
if
((
!
$inline
&&
$item
->
eq
(
'Content-Disposition'
,
'attachment'
))
||
(
$inline
&&
$item
->
get
(
'Content-ID'
))){
$attachment
[]
=
new
Attachment
(
$item
);
$isAttachment
=
$item
->
eq
(
'Content-Disposition'
,
'attachment'
);
if
(
$inline
===
null
){
if
(
$isAttachment
||
$item
->
get
(
'Content-ID'
)){
$attachment
[]
=
new
Attachment
(
$item
);
}
}
else
{
if
((
!
$inline
&&
$isAttachment
)
||
(
$inline
&&
$item
->
get
(
'Content-ID'
))){
$attachment
[]
=
new
Attachment
(
$item
);
}
}
}
...
...
lib/Imap/Parse/Header.php
查看文件 @
ba722dc
...
...
@@ -134,10 +134,13 @@ class Header{
*/
private
function
parseAddress
(
string
$address
,
$isArray
=
false
){
$arr
=
[];
foreach
(
explode
(
','
,
$address
)
as
$k
=>
$str
){
$arr
[
$k
]
=
Address
::
make
(
$str
);
if
(
$isArray
)
$arr
[
$k
]
=
$arr
[
$k
]
->
toArray
();
if
(
$address
){
foreach
(
explode
(
','
,
$address
)
as
$k
=>
$str
){
$arr
[
$k
]
=
Address
::
make
(
$str
);
if
(
$isArray
)
$arr
[
$k
]
=
$arr
[
$k
]
->
toArray
();
}
}
return
$arr
;
}
...
...
service/SyncMail.php
查看文件 @
ba722dc
...
...
@@ -201,7 +201,7 @@ class SyncMail {
*/
public
function
mail
(
string
|
\Lib\Imap\Request\Folder
$folder
,
array
$uids
=
[],
$isBody
=
false
){
if
(
is_string
(
$folder
)){
$folder
=
$this
->
imap
->
folder
(
$folder
);
$folder
=
$this
->
imap
->
folder
(
$folder
)
->
exec
()
;
}
$folder_id
=
$this
->
db
->
value
(
folderSql
::
first
([
...
...
@@ -298,25 +298,54 @@ class SyncMail {
// 是否同步body内容
if
(
$isBody
){
// $body = [
// 'lists_id' => $id,
// 'text_html' => []
// ];
//
// foreach ($item->getBody()->getItems() as $item){
// $body['text_html'][] = [
// 'body' => $item->body,
// 'content-type' => $item->get('content-type'),
// 'content-id' => $item->get('content-id'),
// 'charset' => $item->get('charset')
// ];
// }
//
// if($this->db->count(bodySql::has($id))){
// $this->db->update(bodySql::$table,$body,'`lists_id` = '.$id,false);
// }else{
// $this->db->insert(bodySql::$table,$body,false);
// }
$body
=
[
'lists_id'
=>
$id
,
'text_html'
=>
[]
];
$body
[
'text_html'
][]
=
[
'body'
=>
base64_encode
(
$item
->
getBody
()
->
getHtml
()
?
:
$item
->
getBody
()
->
getText
()),
'type'
=>
'text/html'
,
'charset'
=>
'utf-8'
,
'encode'
=>
'base64'
,
];
// 处理附件
foreach
(
$item
->
getBody
()
->
getAttachment
()
as
$itemBody
){
$tmp
=
[
'body'
=>
''
,
'type'
=>
$itemBody
->
getFileType
(),
'charset'
=>
'binary'
,
'encode'
=>
$itemBody
->
data
->
get
(
'content-transfer-encoding'
),
'name'
=>
$itemBody
->
getFilename
(),
'filename'
=>
$itemBody
->
getFilename
(),
'path'
=>
$itemBody
->
save
(
MAIL_ATTACHMENT_PATH
)
];
if
(
!
$tmp
){
throw
new
\Exception
(
'请检查附件是否有写入权限'
);
}
if
(
$itemBody
->
getContentId
()){
$tmp
[
'content-id'
]
=
$itemBody
->
getContentId
();
}
if
(
$itemBody
->
data
->
get
(
'Content-Disposition'
)){
$tmp
[
'content-disposition'
]
=
$itemBody
->
data
->
get
(
'Content-Disposition'
);
}
$tmp
[
'signName'
]
=
explode
(
'/'
,
$tmp
[
'path'
]);
$tmp
[
'signName'
]
=
end
(
$tmp
[
'signName'
]);
$body
[
'text_html'
][]
=
$tmp
;
}
if
(
$this
->
db
->
count
(
bodySql
::
has
(
$id
))){
$this
->
db
->
update
(
bodySql
::
$table
,
$body
,
'`lists_id` = '
.
$id
,
false
);
}
else
{
$this
->
db
->
insert
(
bodySql
::
$table
,
$body
,
false
);
}
// 更新描述
$this
->
db
->
update
(
listsSql
::
$table
,[
'description'
=>
mb_substr
(
$item
->
getBody
()
->
getText
(),
0
,
150
)],
dbWhere
([
'id'
=>
$id
]));
}
...
...
请
注册
或
登录
后发表评论