Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nextcloud mail - PostGuard
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
Model registry
Operate
Terraform modules
Analyze
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
Laura Kolijn
Nextcloud mail - PostGuard
Commits
0ce28beb
Unverified
Commit
0ce28beb
authored
4 years ago
by
Christoph Wurst
Browse files
Options
Downloads
Patches
Plain Diff
Remove dead methods from the Mailbox class
Signed-off-by:
Christoph Wurst
<
christoph@winzerhof-wurst.at
>
parent
f93c487a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/Account.php
+1
-2
1 addition, 2 deletions
lib/Account.php
lib/Mailbox.php
+1
-227
1 addition, 227 deletions
lib/Mailbox.php
tests/Integration/IMAP/AbstractTest.php
+1
-2
1 addition, 2 deletions
tests/Integration/IMAP/AbstractTest.php
with
3 additions
and
231 deletions
lib/Account.php
+
1
−
2
View file @
0ce28beb
...
@@ -185,8 +185,7 @@ class Account implements JsonSerializable {
...
@@ -185,8 +185,7 @@ class Account implements JsonSerializable {
public
function
getMailbox
(
$folderId
)
{
public
function
getMailbox
(
$folderId
)
{
return
new
Mailbox
(
return
new
Mailbox
(
$this
->
getImapConnection
(),
$this
->
getImapConnection
(),
new
Horde_Imap_Client_Mailbox
(
$folderId
),
new
Horde_Imap_Client_Mailbox
(
$folderId
)
[]
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/Mailbox.php
+
1
−
227
View file @
0ce28beb
...
@@ -32,7 +32,6 @@
...
@@ -32,7 +32,6 @@
namespace
OCA\Mail
;
namespace
OCA\Mail
;
use
Horde_Imap_Client
;
use
Horde_Imap_Client
;
use
Horde_Imap_Client_Exception
;
use
Horde_Imap_Client_Mailbox
;
use
Horde_Imap_Client_Mailbox
;
use
Horde_Imap_Client_Socket
;
use
Horde_Imap_Client_Socket
;
use
OCA\Mail\Model\IMAPMessage
;
use
OCA\Mail\Model\IMAPMessage
;
...
@@ -44,26 +43,6 @@ class Mailbox {
...
@@ -44,26 +43,6 @@ class Mailbox {
*/
*/
protected
$conn
;
protected
$conn
;
/**
* @var array
*/
private
$attributes
;
/**
* @var string
*/
private
$specialRole
;
/**
* @var string
*/
private
$displayName
;
/**
* @var string
*/
private
$delimiter
;
/**
/**
* @var Horde_Imap_Client_Mailbox
* @var Horde_Imap_Client_Mailbox
*/
*/
...
@@ -72,26 +51,10 @@ class Mailbox {
...
@@ -72,26 +51,10 @@ class Mailbox {
/**
/**
* @param Horde_Imap_Client_Socket $conn
* @param Horde_Imap_Client_Socket $conn
* @param Horde_Imap_Client_Mailbox $mailBox
* @param Horde_Imap_Client_Mailbox $mailBox
* @param array $attributes
* @param string $delimiter
*/
*/
public
function
__construct
(
$conn
,
$mailBox
,
$attributes
,
$delimiter
=
'/'
)
{
public
function
__construct
(
$conn
,
$mailBox
)
{
$this
->
conn
=
$conn
;
$this
->
conn
=
$conn
;
$this
->
mailBox
=
$mailBox
;
$this
->
mailBox
=
$mailBox
;
$this
->
attributes
=
$attributes
;
$this
->
delimiter
=
$delimiter
;
$this
->
getSpecialRoleFromAttributes
();
if
(
$this
->
specialRole
===
null
)
{
$this
->
guessSpecialRole
();
}
$this
->
makeDisplayName
();
}
/**
* @return array
*/
public
function
attributes
()
{
return
$this
->
attributes
;
}
}
/**
/**
...
@@ -104,195 +67,6 @@ class Mailbox {
...
@@ -104,195 +67,6 @@ class Mailbox {
return
new
IMAPMessage
(
$this
->
conn
,
$this
->
mailBox
,
$uid
,
null
,
$loadHtmlMessageBody
);
return
new
IMAPMessage
(
$this
->
conn
,
$this
->
mailBox
,
$uid
,
null
,
$loadHtmlMessageBody
);
}
}
/**
* @return array
*/
public
function
getStatus
(
int
$flags
=
Horde_Imap_Client
::
STATUS_ALL
):
array
{
return
$this
->
conn
->
status
(
$this
->
mailBox
,
$flags
);
}
/**
* @return int
*/
public
function
getTotalMessages
()
{
$status
=
$this
->
getStatus
(
\Horde_Imap_Client
::
STATUS_MESSAGES
);
return
(
int
)
$status
[
'messages'
];
}
protected
function
makeDisplayName
():
void
{
$parts
=
explode
(
$this
->
delimiter
,
$this
->
mailBox
->
utf8
,
2
);
if
(
count
(
$parts
)
>
1
)
{
$displayName
=
$parts
[
1
];
}
elseif
(
strtolower
(
$this
->
mailBox
->
utf8
)
===
'inbox'
)
{
$displayName
=
'Inbox'
;
}
else
{
$displayName
=
$this
->
mailBox
->
utf8
;
}
$this
->
displayName
=
$displayName
;
}
public
function
getFolderId
():
string
{
return
$this
->
mailBox
->
utf8
;
}
/**
* @return null|string
*/
public
function
getParent
():
?string
{
$folderId
=
$this
->
getFolderId
();
$parts
=
explode
(
$this
->
delimiter
,
$folderId
,
2
);
if
(
count
(
$parts
)
>
1
)
{
return
$parts
[
0
];
}
return
null
;
}
/**
* @return string
*/
public
function
getSpecialRole
()
{
return
$this
->
specialRole
;
}
/**
* @return string
*/
public
function
getDisplayName
()
{
return
$this
->
displayName
;
}
/**
* @param string $displayName
*
* @return void
*/
public
function
setDisplayName
(
$displayName
):
void
{
$this
->
displayName
=
$displayName
;
}
/**
* @param integer $accountId
* @return array
*/
public
function
serialize
(
$accountId
,
$status
=
null
)
{
$displayName
=
$this
->
getDisplayName
();
try
{
if
(
is_null
(
$status
))
{
$status
=
$this
->
getStatus
();
}
$total
=
$status
[
'messages'
];
$specialRole
=
$this
->
getSpecialRole
();
$unseen
=
(
$specialRole
===
'trash'
)
?
0
:
$status
[
'unseen'
];
$isEmpty
=
(
$total
===
0
);
$noSelect
=
in_array
(
'\\noselect'
,
$this
->
attributes
);
$parentId
=
$this
->
getParent
();
$parentId
=
(
$parentId
!==
null
)
?
base64_encode
(
$parentId
)
:
null
;
return
[
'id'
=>
base64_encode
(
$this
->
getFolderId
()),
'parent'
=>
$parentId
,
'name'
=>
$displayName
,
'specialRole'
=>
$specialRole
,
'unseen'
=>
$unseen
,
'total'
=>
$total
,
'isEmpty'
=>
$isEmpty
,
'accountId'
=>
$accountId
,
'noSelect'
=>
$noSelect
,
'uidvalidity'
=>
$status
[
'uidvalidity'
],
'uidnext'
=>
$status
[
'uidnext'
],
'delimiter'
=>
$this
->
delimiter
];
}
catch
(
Horde_Imap_Client_Exception
$e
)
{
return
[
'id'
=>
base64_encode
(
$this
->
getFolderId
()),
'parent'
=>
null
,
'name'
=>
$displayName
,
'specialRole'
=>
null
,
'unseen'
=>
0
,
'total'
=>
0
,
'error'
=>
$e
->
getMessage
(),
'isEmpty'
=>
true
,
'accountId'
=>
$accountId
,
'noSelect'
=>
true
];
}
}
/**
* Get the special use role of the mailbox
*
* This method reads the attributes sent by the server
*
* @return void
*/
protected
function
getSpecialRoleFromAttributes
():
void
{
/*
* @todo: support multiple attributes on same folder
* "any given server or message store may support
* any combination of the attributes"
* https://tools.ietf.org/html/rfc6154
*/
$result
=
null
;
if
(
is_array
(
$this
->
attributes
))
{
/* Convert attributes to lowercase, because gmail
* returns them as lowercase (eg. \trash and not \Trash)
*/
$specialUseAttributes
=
[
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_ALL
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_ARCHIVE
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_DRAFTS
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_FLAGGED
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_JUNK
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_SENT
),
strtolower
(
Horde_Imap_Client
::
SPECIALUSE_TRASH
)
];
$attributes
=
array_map
(
function
(
$n
)
{
return
strtolower
(
$n
);
},
$this
->
attributes
);
foreach
(
$specialUseAttributes
as
$attr
)
{
if
(
in_array
(
$attr
,
$attributes
))
{
$result
=
ltrim
(
$attr
,
'\\'
);
break
;
}
}
}
$this
->
specialRole
=
$result
;
}
/**
* Assign a special role to this mailbox based on its name
*
* @return void
*/
protected
function
guessSpecialRole
():
void
{
$specialFoldersDict
=
[
'inbox'
=>
[
'inbox'
],
'sent'
=>
[
'sent'
,
'sent items'
,
'sent messages'
,
'sent-mail'
,
'sentmail'
],
'drafts'
=>
[
'draft'
,
'drafts'
],
'archive'
=>
[
'archive'
,
'archives'
],
'trash'
=>
[
'deleted messages'
,
'trash'
],
'junk'
=>
[
'junk'
,
'spam'
,
'bulk mail'
],
];
$lowercaseExplode
=
explode
(
$this
->
delimiter
,
$this
->
getFolderId
(),
2
);
$lowercaseId
=
strtolower
(
array_pop
(
$lowercaseExplode
));
$result
=
null
;
foreach
(
$specialFoldersDict
as
$specialRole
=>
$specialNames
)
{
if
(
in_array
(
$lowercaseId
,
$specialNames
))
{
$result
=
$specialRole
;
break
;
}
}
$this
->
specialRole
=
$result
;
}
/**
/**
* @param int $messageUid
* @param int $messageUid
* @param string $attachmentId
* @param string $attachmentId
...
...
This diff is collapsed.
Click to expand it.
tests/Integration/IMAP/AbstractTest.php
+
1
−
2
View file @
0ce28beb
...
@@ -105,9 +105,8 @@ abstract class AbstractTest extends TestCase {
...
@@ -105,9 +105,8 @@ abstract class AbstractTest extends TestCase {
* @param string $name
* @param string $name
*/
*/
public
function
existsMailBox
(
$name
)
{
public
function
existsMailBox
(
$name
)
{
$mb
=
$this
->
getTestAccount
()
->
getMailbox
(
$name
);
try
{
try
{
$mb
->
getS
tatus
();
self
::
$account
->
getImapConnection
()
->
s
tatus
(
$name
);
return
true
;
return
true
;
}
catch
(
Exception
$ex
)
{
}
catch
(
Exception
$ex
)
{
return
false
;
return
false
;
...
...
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