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

Improvements #35

Merged
merged 12 commits into from
Jun 12, 2024
9 changes: 8 additions & 1 deletion .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

runs-on: ubuntu-latest
permissions:
contents: read
contents: write
packages: write

steps:
Expand All @@ -32,3 +32,10 @@ jobs:
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Upload jar to release
run: |
echo "Uploading to ref ${{ github.event.release.tag_name }}..."
gh release upload ${{ github.event.release.tag_name }} ${{ github.workspace }}/target/pstconv-*.jar
env:
GITHUB_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion license-header.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
60 changes: 31 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<picocli.version>4.7.6</picocli.version>
<slf4j.version>1.7.36</slf4j.version>
</properties>

<scm>
Expand Down Expand Up @@ -81,27 +83,27 @@
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.6.3</version>
<version>${picocli.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.2.1</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
Expand All @@ -111,41 +113,40 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
<version>1.7.32</version>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!--<finalName>${project.artfactId}</finalName>-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.6.3</version>
<version>${picocli.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
Expand All @@ -156,12 +157,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.1</version>
<version>3.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<version>3.7.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand All @@ -185,41 +186,42 @@
</execution>
</executions>
</plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.7.0</version>
<configuration>
<show>package</show>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.1</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/MailMessageFormat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/PstConvertResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/PstConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/PstUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pt/cjmach/pstconv/mail/EmlFolder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,10 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Store;
import javax.mail.internet.MimeMessage;
import org.apache.commons.lang3.StringUtils;
import pt.cjmach.pstconv.PstUtil;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/mail/EmlStore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pt/cjmach/pstconv/mail/LocalFolder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/pt/cjmach/pstconv/LauncherTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
73 changes: 70 additions & 3 deletions src/test/java/pt/cjmach/pstconv/PstConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Carlos Machado
* Copyright 2024 Carlos Machado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,19 @@
import com.pff.PSTException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.mail.Address;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Store;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -39,6 +52,58 @@ public void setUp() {
public void tearDown() {
instance = null;
}

@Test
public void testConvertInputFileSuccess() {
File inputFile = new File("src/test/resources/pt/cjmach/pstconv/outlook.pst");
File outputDirectory = new File("mailbox");
MailMessageFormat format = MailMessageFormat.MBOX;
String encoding = StandardCharsets.ISO_8859_1.name();
int expectedMessageCount = 3;
Store store = null;

try {
PstConvertResult result = instance.convert(inputFile, outputDirectory, format, encoding);
assertEquals(expectedMessageCount, result.getMessageCount(), "Unexpected number of converted messages.");

store = instance.createStore(outputDirectory, format, encoding);
store.connect();

// Root Folder / Inbox (in portuguese)
Folder inbox = store.getFolder("Inicio do ficheiro de dados do Outlook").getFolder("Caixa de Entrada");
inbox.open(Folder.READ_ONLY);

Message[] messages = inbox.getMessages();
assertEquals(expectedMessageCount, messages.length, "Unexpected number of messages in inbox.");

MimeMessage lastMessage = (MimeMessage) messages[expectedMessageCount - 1];
Address[] from = lastMessage.getFrom();
assertEquals(1, from.length);
assertEquals("abcd@as.pt", from[0].toString());

String descriptorIdHeader = lastMessage.getHeader(PstConverter.DESCRIPTOR_ID_HEADER, null);
assertEquals("2097252", descriptorIdHeader);

MimeMultipart multiPart = (MimeMultipart) lastMessage.getContent();
MimeBodyPart bodyPart = (MimeBodyPart) multiPart.getBodyPart(0);
MimeMultipart bodyMultiPart = (MimeMultipart) bodyPart.getContent();
try (InputStream stream = bodyMultiPart.getBodyPart(0).getInputStream()) {
String content = IOUtils.toString(stream, StandardCharsets.US_ASCII.name());
assertEquals("Teste 23:34", content);
}
} catch (Exception ex) {
fail(ex);
} finally {
if (store != null) {
try {
store.close();
} catch (MessagingException ignore) {}
}
try {
FileUtils.deleteDirectory(outputDirectory);
} catch (IOException ignore) { }
}
}

/**
* Test of convert method, of class PstConverter.
Expand All @@ -50,7 +115,8 @@ public void testConvertInputFileNotFound() {
File outputDirectory = new File(".");
MailMessageFormat format = MailMessageFormat.EML;
String encoding = "UTF-8";
assertThrows(FileNotFoundException.class, () -> instance.convert(inputFile, outputDirectory, format, encoding));
FileNotFoundException ex = assertThrows(FileNotFoundException.class, () -> instance.convert(inputFile, outputDirectory, format, encoding));
assertEquals(FileNotFoundException.class, ex.getClass());
}

@Test
Expand All @@ -59,7 +125,8 @@ public void testConvertInputFileIllegal() {
File outputDirectory = new File(".");
MailMessageFormat format = MailMessageFormat.EML;
String encoding = "UTF-8";
assertThrows(FileNotFoundException.class, () -> instance.convert(inputFile, outputDirectory, format, encoding));
FileNotFoundException ex = assertThrows(FileNotFoundException.class, () -> instance.convert(inputFile, outputDirectory, format, encoding));
assertEquals(FileNotFoundException.class, ex.getClass());
}

@Test
Expand Down
Loading