Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MailboxesParser #268

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

MailboxesParser #268

wants to merge 12 commits into from

Conversation

piernik
Copy link

@piernik piernik commented Nov 20, 2017

I'm adding mailboxesParser. It sorts mailboxes and fetches special folders like "sent", "inbox", "trash". Tests are in tests\MailboxesParser\.
Usage:

$parser = new MailboxesParser($this->mailboxes);
//set language (only pl) for special folders names and mailboxNames
$parser->setLanguage('pl');
//get flat but sorted folders. Folders are ParsedMailbox class
$folders = $parser->getFolders();
//get tree structure of folders
$tree = $parser->getTreeStructure();

Copy link
Collaborator

@Slamdunk Slamdunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the idea is good, we need to shape it for general purpose though.

Please make the tests pass, and run the PHP-CS-Fixer to apply the code style this library follows.

.gitignore Outdated
@@ -2,3 +2,5 @@ vendor/
.php_cs.cache
composer.lock
phpunit.xml
.idea/
phpunit.xml.dist
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need phpunit.xml.dist in the package, please revert .gitignore file

verbose="true"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to keep one indentation for this file, please revert it.

self::TRASH => ['trash', 'bin', 'INBOX.trash', '[Gmail]/trash'],
self::TEMPLATES => ['templates'],
self::ARCHIVES => ['archives',],
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID of special folder vary a lot from different email provider, I don't want to have a static list to keep up to date.

What about letting the user specify it in the constructor, so this library doesn't have to maintain it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those are common ones. All other folders are simply listed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, those are not as common as you may think.
I work with a lot of IMAP servers where these special folders have many other aliases: only for the Trash one I have 15 variants 😞 in English, without counting localizations.

I'm still against to maintain this list: let the user specify them.

Also the tests would be much more easy to implement and verify.

self::TRASH => 'Trash',
self::TEMPLATES => 'Templates',
self::ARCHIVES => 'Archives',
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same goes for folder names: if you need them, let the user specify them as a constructor dependency.

We don't have the resources to maintain translations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can manually name special folders with setSpecialFoldersNames.
and add special folders Id with addSpecialFolderId

*
* @param MailboxInterface[] $mailboxes
*/
public function __construct($mailboxes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type-hints

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in php 7.0 I cannot use public function __construct(MailboxInterface[] $mailboxes)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but you can typehint the array at least.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see __construct($mailboxes).

Can you change this to __construct(array $mailboxes)?

$this->specialFoldersIds[$specialFolder][] = $id;
}

private function getFolderLevel($mailboxName, $delimiter)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type-hints, return-type and doc-block

namespace Ddeboer\Imap\MailboxesParser;


class MailboxesTreeParser
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it final and add an Interface for it

*
* @return array
*/
public function parse($input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type-hints and the return-type


use Ddeboer\Imap\MailboxInterface;

class ParsedMailbox
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it final and add an Interface for it

/**
* @param MailboxInterface $mailbox
*/
public function setMailbox(MailboxInterface $mailbox)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all the setters to be the constructor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is internal helper class I see no point.

Copy link
Collaborator

@Slamdunk Slamdunk Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is that immutable objects are far more easy to maintain.

@piernik
Copy link
Author

piernik commented Dec 1, 2017

I've changed files.

@Slamdunk
Copy link
Collaborator

Slamdunk commented Dec 1, 2017

Thanks for the changes.

Still please make the tests pass, and run the PHP-CS-Fixer to apply the code style this library follows.

@piernik
Copy link
Author

piernik commented Dec 1, 2017

I said I'm not github fluent. I don't know what that is :)
Can't You make it on Your own?

@Slamdunk
Copy link
Collaborator

Slamdunk commented Dec 1, 2017

On the bottom of this Pull Request you can see a red cross near continuous-integration/travis-ci/pr.

If you click on the "Details" link you can see that Travis, a continuous integration server, pulled your PR and performed some checks that this library asked Travis to do.

At the time of writing, those checks are done against three different PHP versions, and if you click in each of them you can see what are the failures that are marking your PR as failing.

The first failure I see is:

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /home/travis/build/ddeboer/imap/tests/MailboxesParser/MailboxesParserTest.php on line 15

And the second failure I see is that you didn't run the following command:

$ vendor/bin/php-cs-fixer fix --verbose

That fix the coding style of the code you wrote.

Please try to fix those failure: if you need more help I'm here.

@piernik
Copy link
Author

piernik commented Dec 1, 2017

About tests - You're using phpunit 6 - I have phpunit 5 globally. It's fixed.

About cs-fixer. This is my output. Don't know what that means.
cs-fixer

@Slamdunk
Copy link
Collaborator

Slamdunk commented Dec 1, 2017

Vendor binaries must be run from the project root folder.
All the necessary dependencies are installed in the project: you should run these once, there is no need for a global PHPUnit installation.

From the imap project repository run these commands:

$ vendor/bin/phpunit
$ vendor/bin/php-cs-fixer fix --verbose

You need both to pass.

@piernik
Copy link
Author

piernik commented Dec 1, 2017

I give up. Fix the code on Your own - sorry.

@Slamdunk
Copy link
Collaborator

Slamdunk commented Dec 1, 2017

I'm sad that you are giving up.

Though, each new functionality must be well tested and checked.
This library is widely used by a lot of users and we must ensure reliability: we can ship code that isn't tested.

I'll leave this PR open: if you ever want to finish it, we'll be thankful.

@piernik
Copy link
Author

piernik commented Dec 1, 2017

I did add tests. I don't know what travis wants. You can fetch code and fix it on Your own.

@Slamdunk
Copy link
Collaborator

Slamdunk commented Dec 4, 2017

I'm sorry but you can't share a code that isn't proved to be working and expect someone else to fix it.

I can help you if you don't understand the tools, but it is up to you to provide the functionality and its tests, and to prove everything works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants