Skip to content

import a folder full of EML files to James#69

Closed
ilkerceng wants to merge 27 commits intoapache:masterfrom
ilkerceng:master
Closed

import a folder full of EML files to James#69
ilkerceng wants to merge 27 commits intoapache:masterfrom
ilkerceng:master

Conversation

@ilkerceng
Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/JAMES-2081
implemented necessary codes, corrected indentations, added tests.

@chibenwa
Copy link
Copy Markdown
Contributor

chibenwa commented Jul 5, 2017

We tend to prefix our commit names by tickets:

JAMES-2081  	IMPORTEMLFILETOMAILBOX command

Moreover, you need to review this history. Does your changesets makes sens alone? I would encourage you to keep maximum 2/3 commits for this.

eg: commit 1 : Add capability to MailboxManagement
commit 2 : Add feature to the CLI

One commit is also OK

You can do that with

git rebase

CREATEMAILBOX("CreateMailbox", "namespace", "user", "name"),
LISTUSERMAILBOXES("ListUserMailboxes", "user"),
DELETEMAILBOX("DeleteMailbox", "namespace", "user", "name"),
IMPORTEMLFILETOMAILBOX("importemlfiletomailbox", "namespace", "user", "name", "path"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMPORTEMLFILETOMAILBOX("importEmlFileToMailbox", "namespace", "user", "name", "path")

Snake case makes it easier to read for end user

String user = "user@domain";
String namespace = "#private";
String name = "INBOX.test";
String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't need a real path here. "my/path/to/file.eml" will also work.

}

@Test
public void lookupImportEmlFileToMailboxShouldReturnEnumValue() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add one breakline before isEqualTo

assertThat(inMemoryMapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0);
Iterator<MailboxMessage> iterator = inMemoryMapperFactory.getMessageMapper(session).findInMailbox(mailbox,
MessageRange.all(), null, 1);
assertFalse(iterator.hasNext());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

asserThat(iterator.hasNext()).isFalse();

Copy link
Copy Markdown
Contributor

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

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

Very good proposition! Congratulation!

mailboxProbe.deleteMailbox(arguments[1], arguments[2], arguments[3]);
break;
case IMPORTEMLFILETOMAILBOX:
mailboxProbe.importEmlFileToMailBox(arguments[1], arguments[2], arguments[3], arguments[4]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry it's mailbox and not mailBox. Could you please fix this case issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have fixed it as Maibox.

}

@Override
public void importEmlFileToMailBox(String namespace, String user, String name, String emlpath) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please fix this case issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have fixed it as Maibox.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be:

mailboxManagerManagement.importEmlFileToMailbox(namespace, user, name, emlpath);

}

@Test
public void lookupImportEmlFileToMailboxShouldReturnEnumValue() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can get the name of the command shorter... Maybe importEml is enough...

I 'm thinking to poor admins...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, what is your last decision for that :) should i change the name "importEmlFileToMailbox" as importEml for all occurences

session = mailboxManager.createSystemSession(user, log);
mailboxManager.startProcessingRequest(session);
MessageManager messageManager = mailboxManager.getMailbox(new MailboxPath(namespace, user, name), session);
InputStream emlFileResourceAsStream = new FileInputStream(emlpath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

emlFileAsStream

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have changed it as emlFileAsStream

MessageManager messageManager = mailboxManager.getMailbox(new MailboxPath(namespace, user, name), session);
InputStream emlFileResourceAsStream = new FileInputStream(emlpath);
ComposedMessageId composedMessageId = messageManager.appendMessage(emlFileResourceAsStream, new Date(),
session, false, new Flags());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does false means? We tend to extract values to constant to give them a name.

I believe, if it is isRecent then it should be true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep it is isRecent, i have changed isRecent as true.

mailboxManagerManagement.importEmlFileToMailBox(MailboxConstants.USER_NAMESPACE, USER, "name", emlpath);

assertThat(inMemoryMapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(1);
Iterator<MailboxMessage> iterator = inMemoryMapperFactory.getMessageMapper(session).findInMailbox(mailbox,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here what is null? Your fetch type? Use FetchType.Full instead.

Extract 1 in a constant named limit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, named LIMIT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have changed it as MessageMapper.FetchType.Full, added LIMIT as a constant for 1

mailboxManagerManagement.importEmlFileToMailBox(MailboxConstants.USER_NAMESPACE, USER, "name", "wrong_path" + emlpath);

assertThat(inMemoryMapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0);
Iterator<MailboxMessage> iterator = inMemoryMapperFactory.getMessageMapper(session).findInMailbox(mailbox,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Idem here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sorry but what you mean with "Idem here"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean I have the same comment than above:



Here what is null? Your fetch type? Use FetchType.Full instead.

Extract 1 in a constant named limit

}

@Override
public void importEmlFileToMailBox(String namespace, String user, String name, String emlpath) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be:

mailboxManagerManagement.importEmlFileToMailbox(namespace, user, name, emlpath);

CREATEMAILBOX("CreateMailbox", "namespace", "user", "name"),
LISTUSERMAILBOXES("ListUserMailboxes", "user"),
DELETEMAILBOX("DeleteMailbox", "namespace", "user", "name"),
IMPORTEMLFILETOMAILBOX("ImportEmlFileToMailbox", "namespace", "user", "name", "path"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be :

IMPORTEML("ImportEml", "namespace", "user", "name", "path"),

For end user readability

mailboxManagerManagement.importEmlFileToMailBox(MailboxConstants.USER_NAMESPACE, USER, "name", "wrong_path" + emlpath);

assertThat(inMemoryMapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0);
Iterator<MailboxMessage> iterator = inMemoryMapperFactory.getMessageMapper(session).findInMailbox(mailbox,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean I have the same comment than above:



Here what is null? Your fetch type? Use FetchType.Full instead.

Extract 1 in a constant named limit

@ilkerceng
Copy link
Copy Markdown
Contributor Author

mr. @chibenwa
you had said before to fix absolute path to relative path in ServerCmdTest.java
i am using ClassLoader.getSystemResource("eml/frnog.eml").getFile() still; in MailboxManagementTest.java

  1. i think i should fix all occurences of ClassLoader.getSystemResource("eml/frnog.eml").getFile() to relative path?
  2. i have realised that i have forgotten pushing "eml/frnog.eml" resource :(

return subscriptionManager.subscriptions(mailboxSession);
}

//TODO: ilker: impelement this
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please do it then ?

checkString(namespace, "mailbox path namespace");
checkString(user, "mailbox path user");
checkString(name, "mailbox name");
checkString(emlpath, "email file path name");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would remove the checkString private method and do:

		Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "namespace can't be null or empty");

using Strings from Guava: https://google.github.io/guava/releases/18.0/api/docs/com/google/common/base/Strings.html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's done in linagora#889

ilkerceng added 18 commits July 10, 2017 13:17
IMPORTEMLFILETOMAILBOX is added to executeCommand function
IMPORTEMLFILETOMAILBOX("importemlfiletomailbox", "namespace", "user", "name", "path"),
lookupImportEmlFileToMailboxShouldReturnEnumValue test function is added
importEmlFileToMailBox function declaration added to MailboxProbe interface
importEmlFileToMailBox is implemented checking if arguments correctly given
indentation has corrected.
indentations has corrected
UnitTest is added to control if file is not found
indentations has corrected
…led, LIMIT is added as a constant for the maximal limit of returned
@chibenwa
Copy link
Copy Markdown
Contributor

This has just been merged. Could you please close the pull request? This will avoid asking this to the Apache INFRA team...

Thanks again for your contribution.

@ilkerceng
Copy link
Copy Markdown
Contributor Author

I also thank you so much.

@ilkerceng ilkerceng closed this Jul 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants