Skip to content

Commit 6654aec

Browse files
author
Matthias Huttar
committed
setup structure
0 parents  commit 6654aec

File tree

8 files changed

+195
-0
lines changed

8 files changed

+195
-0
lines changed

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
jmeter.log
2+
germany/*/target
3+
core/*/target
4+
germany/target
5+
core/target
6+
target
7+
extra
8+
.idea/
9+
*.iml
10+
*.ipr
11+
*.iws
12+
nb*.xml
13+
.project
14+
.classpath
15+
.settings
16+
db*.log
17+
db.data
18+
db.redo
19+
.#webclasspath
20+
.tomcatplugin
21+
.metadata
22+
velocity.log*
23+
.cache
24+
work
25+
*global-groovy.log
26+
glassfish-web.xml
27+
context.xml
28+
.pmd
29+
jrebel.xml
30+
.DS_Store
31+
activemq-data
32+
/germany/belen-selenium-tests/nbactions.xml
33+
.checkstyle
34+
test-output/

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Message Extraction Sample
2+
this example is based on a task that we worked on half a year ago for our online message box.
3+
At eBay Kleinanzeigen buyers and sellers used to communicate via E-Mail through our platform.
4+
5+
We introduced a new feature called *message box* to allow people a quicker and less formal way of communication.
6+
Message box can be used transparently over different channels (a user of messagebox might be communicating with a user that
7+
still uses e-mails).
8+
9+
One of the biggest challenge we had, was to cope with the e-mail format in order to extract the actual contents of a mail
10+
from our template text in the first mail and all the quotation mess that mail clients produce.
11+
12+
## Tasks and considerations
13+
This is a complicated task and we know that you're not going to finish it in time. Also, we have not found a perfect solution.
14+
We want to see your approach and considerations as well as your style of work. (and maybe learn from your ideas ;) )
15+
16+
For this task you can assume that:
17+
18+
* we only cope with plaintext mails (no html content e-mails)
19+
* you will have to handle all weird sorts of quotation styles that mail clients may or may not use.
20+
* users may mix their replies with the quoted parts (meaning they reply individually to each paragraph)

pom.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.ebay.classifieds.germany</groupId>
5+
<artifactId>message-extraction</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<url>http://kleinanzeigen.ebay.de/anzeigen</url>
9+
<dependencies>
10+
<dependency>
11+
<groupId>junit</groupId>
12+
<artifactId>junit</artifactId>
13+
<version>4.11</version>
14+
<scope>test</scope>
15+
</dependency>
16+
</dependencies>
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<version>3.1</version>
23+
<configuration>
24+
<source>1.7</source>
25+
<target>1.7</target>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.ebay.classifieds.germany;
2+
3+
import static com.ebay.classifieds.germany.Mail.Role.BUYER;
4+
import static com.ebay.classifieds.germany.Mail.Role.SELLER;
5+
6+
public class Mail {
7+
8+
public static enum Role {BUYER, SELLER}
9+
10+
private final String mailContents;
11+
private final Role from;
12+
13+
14+
public Mail(String mailContents, Role from) {
15+
if (from == null || mailContents == null) {
16+
throw new IllegalArgumentException("all parameters are mandatory");
17+
}
18+
this.mailContents = mailContents;
19+
this.from = from;
20+
}
21+
22+
public String getMailContents() {
23+
return mailContents;
24+
}
25+
26+
public Role getFrom() {
27+
return from;
28+
}
29+
30+
public Role getTo() {
31+
return from == BUYER ? SELLER : BUYER;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.ebay.classifieds.germany;
2+
3+
import java.util.Stack;
4+
5+
public class MessageExtractor {
6+
/**
7+
* extract the actual text of the mail from parameter <code>actualMail</code>. the second parameter, <code>history</code>
8+
* will contain the previous messages in this conversation (from both people involved).
9+
* <p>
10+
* The stack will be filled with messages in the order they arrived. Meaning the first message of the conversation
11+
* is added to the stack first. The <code>actualMail</code> will not be in the stack.
12+
*/
13+
public String extractText(Mail actualMail, Stack<Mail> history) {
14+
return actualMail.getMailContents();
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.ebay.classifieds.germany;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
import java.util.Stack;
7+
8+
import static com.ebay.classifieds.germany.Mail.Role.BUYER;
9+
import static com.ebay.classifieds.germany.SampleReader.readFileContents;
10+
import static org.hamcrest.CoreMatchers.is;
11+
import static org.junit.Assert.assertThat;
12+
13+
public class ExampleTest {
14+
15+
private MessageExtractor messageExtractor = new MessageExtractor();
16+
17+
@Test
18+
public void stripsStandardTemplate() throws IOException {
19+
20+
Mail input = new Mail(
21+
readFileContents("/sample-first-mail.txt"),
22+
BUYER);
23+
24+
assertThat(messageExtractor.extractText(input, new Stack<Mail>()),
25+
is("Hello! I just saw this ticket and wanted to ask if it is still available?"));
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ebay.classifieds.germany;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.nio.charset.Charset;
7+
8+
public class SampleReader {
9+
public static String readFileContents(String filename) {
10+
try(InputStream i = SampleReader.class.getResourceAsStream(filename)) {
11+
ByteArrayOutputStream output = new ByteArrayOutputStream();
12+
byte[] buffer = new byte[100];
13+
int bytesRead = 0;
14+
while((bytesRead = i.read(buffer)) != -1) {
15+
output.write(buffer, 0, bytesRead);
16+
}
17+
return new String(output.toByteArray(), Charset.forName("UTF-8"));
18+
} catch (IOException e) {
19+
throw new RuntimeException(e);
20+
}
21+
}
22+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Dear User!
2+
3+
Somebody wants to buy this item from you:
4+
'Ticket for the next game.'
5+
Ad Id: 46703318
6+
7+
Message from: Max
8+
9+
Hello! I just saw this ticket and wanted to ask if it is still available?
10+
11+
Copyright © 2005-2014 eBay International AG. All rights reserved
12+
Help | Privacy | Terms of use | Imprint | Press | Contact us

0 commit comments

Comments
 (0)