How do I decode a base64 encoded URL from a test email using Katalon

I have repleased ver 0.1.1

I changed the PathComparableByContentEmailDate class to make it more robust against .eml files that contains irregular white space characters so that unable to parse as ver 0.1.0 expected.

You can see the diff of the tag 0.1.0 and 0.1.1 at

Hi kazurayam,

I downloaded and installed 'SortingFilesByDateTimeInContent-0.1.1.jar" in the Drivers folder.

When I run the test with the following test case code I get the following error:

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import com.kms.katalon.core.configuration.RunConfiguration
import com.kazurayam.study20221030.PathComparableByDateTime
import com.kazurayam.study20221030.PathComparableByContentEmailDate

dataDir = Paths.get('//Test1//MailerPickupDirectory')
List<PathComparableByFileLastModified> emlFiles =
	Files.list(dataDir)
		.filter({ p -> p.toString().endsWith(".eml") })
		// wrap the Path object by a adapter class
		// to sort the Path objects by the Email Date in the file content
		.map({ p -> new PathComparableByContentEmailDate(p) })
		// in the descending order of the Date value
		.sorted(Comparator.reverseOrder())
		.collect(Collectors.toList())

// print path of all eml files
//emlFiles.eachWithIndex  { p, index ->
//	println((index + 1) + "\t" + p.getTimestampFormatted() + "\t" + dataDir.relativize(p.get()))
//}
=============== ROOT CAUSE =====================
For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html
================================================
10-31-2022 06:05:36 PM Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41 fileOpenKazurayam_network

Elapsed time: 0.404s
Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41 fileOpenKazurayam_network FAILED.
Reason: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/devers/Katalon_QAS_Projects/25-mfda-oap/Scripts/A1_PreFeatureCases/01%20How_to_cases/25%20Katalon_tips/41%20fileOpenKazurayam_network/Script1667253349870.groovy: 10: unable to resolve class PathComparableByFileLastModified 
 @ line 10, column 6.
   List<PathComparableByFileLastModified> emlFiles =
        ^
1 error
	at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667264733319.run(TempTestCase1667264733319.groovy:25)

You need to insert a line:

import com.kazurayam.study20221030.PathComparableByDateTime

And you need to change a line from:

		.map({ p -> new PathComparableByContentEmailDate(p) })

to

		.map({ p -> new PathComparableByFileLastModified(p) })

Thanks @kazurayam!
Will update as per your instructions tomorrow.

HI @kazurayam, I am now getting 2 errors using this test case code:

Also had one more Question:
Would it be possible to add a search ‘To:’ email search criteria?
For example search for the last modified file where the To: field contains “johnDoe”
johnDoe would be a Variable/GlobalVariable so it could be changed/updated?

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import com.kms.katalon.core.configuration.RunConfiguration
import com.kazurayam.study20221030.PathComparableByContentEmailDate
import com.kazurayam.study20221030.PathComparableByDateTime

Path dataDir = Paths.get(RunConfiguration.getProjectDir()).resolve("Include/data")
List<PathComparableByFileLastModified> emlFiles =
	Files.list(dataDir)
		.filter({ p -> p.toString().endsWith(".eml") })
		// wrap the Path object by a adapter class
		// to sort the Path objects by the Email Date in the file content
		.map({ p -> new PathComparableByFileLastModified(p) })
		// in the descending order of the Date value
		.sorted(Comparator.reverseOrder())
		.collect(Collectors.toList())

//print path of all eml files
//emlFiles.eachWithIndex  { p, index ->
//	println((index + 1) + "\t" + p.getTimestampFormatted() + "\t" + dataDir.relativize(p.get()))
//}

Error:

=============== ROOT CAUSE =====================
For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html
================================================
11-01-2022 08:00:17 AM Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41 fileOpenKazurayam_local

Elapsed time: 0.392s

Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41 fileOpenKazurayam_local FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/devers/Katalon_QAS_Projects/25-mfda-oap/Scripts/A1_PreFeatureCases/01%20How_to_cases/25%20Katalon_tips/41%20fileOpenKazurayam_local/Script1667253365735.groovy: 10: unable to resolve class PathComparableByFileLastModified 
 @ line 10, column 6.
   List<PathComparableByFileLastModified> emlFiles =
        ^

file:/C:/Users/devers/Katalon_QAS_Projects/25-mfda-oap/Scripts/A1_PreFeatureCases/01%20How_to_cases/25%20Katalon_tips/41%20fileOpenKazurayam_local/Script1667253365735.groovy: 15: unable to resolve class PathComparableByFileLastModified 
 @ line 15, column 15.
   		.map({ p -> new PathComparableByFileLastModified(p) })
                 ^
2 errors
	at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667314814646.run(TempTestCase1667314814646.groovy:25)

You need to add an import statement:

import com.kazurayam.study20221030.PathComparableByFileLastModified

Done, possible.

See

Thanks & Sorry as I should have used CTRL + Shift + O to bring in the imports.
The search by Last Modified date works like a charm now > thanks! :smile:

Hi kazurayam,
Thanks so much for adding the ability to search based on the ‘To’ field.
I used Ctrl+Shift+O to load import the supporting files but I am still seeing an ‘expecting ‘)’, found ‘->’ @ line 10, column 11.’ error for 'filter(p → p.getFileName().toString().endsWith(“.eml”))".
I added the ‘SortingFilesByDateTimeInContent-0.3.0.jar’ to my Drivers folder.
No doubt I messed up again…

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import com.kazurayam.study20221030.IPathComparable

dataDir = Paths.get('//q-van-bsl1//MailerPickupDirectory')
List<IPathComparable> files =
Files.list(dataDir)
	filter(p -> p.getFileName().toString().endsWith(".eml"))
	// filter files with "To: xyz.com" header
	.map(p -> new PathComparableByContentEmailHeaderValue(p, "To"))
	.filter(p -> p.getValue().matches("xyz.com"))
	// to sort by the lastModified timestamp
	.map(p -> new PathComparableByFileLastModified(p.get()))
	.sorted(reverseOrder())
	.collect(Collectors.toList());
	

sortbyName01
sortbyName02

You need to be aware of syntactical difference between Java and Groovy language.

My sample code is written in Java using “Lambda expression”. So I wrote

filter(p -> p.getFileName().toString().endsWith(".eml"))

or

filter(p -> { return p.getFileName().toString().endsWith(".eml");})

On the other hand, you are writing code in Groovy. So you should write using “Closure” syntax:

filter({p -> p.getFileName().toString().endsWith(".eml")})

F.Y.I

for Java Lambda → https://www.baeldung.com/java-stream-filter-lambda

for Groovy Closure → https://www.baeldung.com/groovy-closures

Hi @kazurayam,
I updated the script as follows but am now seeing some other errors…
Am I missing an import file?
Thanks,
Dave
SendToNotWorking

Error after running

2022-11-02 08:29:07.873 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2022-11-02 08:29:07.877 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41e fileOpenKazurayamLastModified_SentToLocal
2022-11-02 08:29:08.385 DEBUG ileOpenKazurayamLastModified_SentToLocal - 1: dataDir = get(getProjectDir()).resolve("Include/data")
2022-11-02 08:29:08.407 DEBUG ileOpenKazurayamLastModified_SentToLocal - 2: println("dataDir: " + dataDir)
dataDir: C:\Users\devers\Katalon_QAS_Projects\25-mfda-oap\Include\data
2022-11-02 08:29:08.411 DEBUG ileOpenKazurayamLastModified_SentToLocal - 3: emlfiles = sorted(reverseOrder()).collect(Collectors.toList())
2022-11-02 08:29:08.477 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41e fileOpenKazurayamLastModified_SentToLocal FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1667344401788.reverseOrder() is applicable for argument types: () values: []
	at 41e fileOpenKazurayamLastModified_SentToLocal.run(41e fileOpenKazurayamLastModified_SentToLocal:16)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667402945107.run(TempTestCase1667402945107.groovy:25)

2022-11-02 08:29:08.495 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41e fileOpenKazurayamLastModified_SentToLocal FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1667344401788.reverseOrder() is applicable for argument types: () values: []
	at 41e fileOpenKazurayamLastModified_SentToLocal.run(41e fileOpenKazurayamLastModified_SentToLocal:16)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667402945107.run(TempTestCase1667402945107.groovy:25)

2022-11-02 08:29:08.512 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/A1_PreFeatureCases/01 How_to_cases/25 Katalon_tips/41e fileOpenKazurayamLastModified_SentToLocal

The following code as a Test Case in Katalon Studio works using the jar ver0.3.2.

/**
 * @author kazurayam
 */

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import java.util.Comparator

import com.kms.katalon.core.configuration.RunConfiguration

import com.kazurayam.study20221030.IPathComparable
import com.kazurayam.study20221030.PathComparableByFileLastModified
import com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue

Path dataDir = Paths.get(RunConfiguration.getProjectDir()).resolve("Include/data")

List<IPathComparable> files =
	Files.list(dataDir)
		.filter({ p -> p.getFileName().toString().endsWith(".eml") })
		// filter files with "To: xyz.com" header
		.map({ p -> new PathComparableByContentEmailHeaderValue(p, "To") })
		.filter({ p -> p.getValue().matches("xyz.com") })
		// to sort by the lastModified timestamp
		.map({ p -> new PathComparableByFileLastModified(p.get()) })
		// sort in descending order
		.sorted(Comparator.reverseOrder())
		// turn the Stream into a List
		.collect(Collectors.toList())
		
// print path of all eml files
files.eachWithIndex  { p, index ->
	println((index + 1) + "\t" + p.getValue() + "\t" + dataDir.relativize(p.get()))
}


スクリーンショット 2022-11-03 8.10.36

Underlines in the Test Case editor of Katalon Studio is not very reliable. It draws unnecessary underlines quite often. Don’t trust it too much.


My working sample code is underlined by Katalon Studio as well:

Why getValue() here is uderlined? — It is obvious to me. The Test Case editor does not understand the “Java8 Stream API”.

Possibly Katalon Team regards th “Java Stream API” is a feature too much advanced for Katalon users; none of them would ever use it, so no need to support it. Or, the “Manual mode” of Test Case editor may prevent Katalon Team from supporting the Stream API. ---- the conceptual model of “Manual mode” will never be adaptable to the Stream API.

I don’t mind these wrong underlines in Test Case editor in Katalon Studio. I will just ignore them.

Hi @kazurayam, Sorry but I am seeing a new error.
I’ve added ‘SortingFilesByDateTimeInContent-0.3.2.jar’ to my Drivers folder

Test Case Code:

/**
 * @author kazurayam
 */

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import java.util.Comparator
import com.kms.katalon.core.configuration.RunConfiguration
import com.kazurayam.study20221030.IPathComparable
import com.kazurayam.study20221030.PathComparableByFileLastModified
import com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue

Path dataDir = Paths.get(RunConfiguration.getProjectDir()).resolve("Include/data")
List<IPathComparable> files =
	Files.list(dataDir)
		.filter({ p -> p.getFileName().toString().endsWith(".eml") })
		// filter files with "To: xyz.com" header
		.map({ p -> new PathComparableByContentEmailHeaderValue(p, "To") })
		.filter({ p -> p.getValue().matches("xyz.com") })
		// to sort by the lastModified timestamp
		.map({ p -> new PathComparableByFileLastModified(p.get()) })
		// sort in descending order
		.sorted(Comparator.reverseOrder())
		// turn the Stream into a List
		.collect(Collectors.toList())
		
// print path of all eml files
files.eachWithIndex  { p, index ->
	println((index + 1) + "\t" + p.getValue() + "\t" + dataDir.relativize(p.get()))
}

Email header being read

X-Sender: "Do Not Reply" <donotreply@hotmail.com>
X-Receiver: AtmLast1667@hotmail.com
MIME-Version: 1.0
From: "Do Not Reply" <donotreply@hotmail.com>
To: AtmLast1667@hotmail.com
Date: 2 Nov 2022 15:32:04 -0700
Subject: Set up online access for your account
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64

New error message:

2022-11-02 17:18:47.577 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2022-11-02 17:18:47.582 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 dje_OpenSignUpEmailUsingTo,called
2022-11-02 17:18:48.146 DEBUG t.07 dje_OpenSignUpEmailUsingTo,called   - 1: dataDir = get(getProjectDir()).resolve("Include/data")
2022-11-02 17:18:48.168 DEBUG t.07 dje_OpenSignUpEmailUsingTo,called   - 2: println("dataDirPath: " + dataDir)
dataDirPath: C:\Users\devers\Katalon_QAS_Projects\25-mfda-oap\Include\data
2022-11-02 17:18:48.172 DEBUG t.07 dje_OpenSignUpEmailUsingTo,called   - 3: files = reverseOrder()).collect(Collectors.toList())
2022-11-02 17:18:48.348 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 dje_OpenSignUpEmailUsingTo,called FAILED.
Reason:
java.time.format.DateTimeParseException: Text '2 Nov 2022 15:32:04 -0700' could not be parsed at index 0
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.getDateInEmailHeader(PathComparableByContentEmailHeaderValue.java:61)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.resolveTimestamp(PathComparableByContentEmailHeaderValue.java:51)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.<init>(PathComparableByContentEmailHeaderValue.java:23)
	at Script1667433324642$_run_closure2.doCall(Script1667433324642.groovy:21)
	at com.sun.proxy.$Proxy10.apply(Unknown Source)
	at java_util_stream_Stream$collect$0.call(Unknown Source)
	at 07 dje_OpenSignUpEmailUsingTo,called.run(07 dje_OpenSignUpEmailUsingTo,called:28)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667434724595.run(TempTestCase1667434724595.groovy:25)

2022-11-02 17:18:48.358 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 dje_OpenSignUpEmailUsingTo,called FAILED.
Reason:
java.time.format.DateTimeParseException: Text '2 Nov 2022 15:32:04 -0700' could not be parsed at index 0
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.getDateInEmailHeader(PathComparableByContentEmailHeaderValue.java:61)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.resolveTimestamp(PathComparableByContentEmailHeaderValue.java:51)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.<init>(PathComparableByContentEmailHeaderValue.java:23)
	at Script1667433324642$_run_closure2.doCall(Script1667433324642.groovy:21)
	at com.sun.proxy.$Proxy10.apply(Unknown Source)
	at java_util_stream_Stream$collect$0.call(Unknown Source)
	at 07 dje_OpenSignUpEmailUsingTo,called.run(07 dje_OpenSignUpEmailUsingTo,called:28)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667434724595.run(TempTestCase1667434724595.groovy:25)
2022-11-02 17:18:48.372 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 dje_OpenSignUpEmailUsingTo,called

Released v0.3.3 to fix this.

You can see the diff between 0.3.2 and 0.3.3

Hi @kazurayam
Still seeing one ‘parsed at index 0’ error message

Test Code:

/**
 * @author kazurayam
 */

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import java.util.Comparator
import com.kms.katalon.core.configuration.RunConfiguration
import com.kazurayam.study20221030.IPathComparable
import com.kazurayam.study20221030.PathComparableByFileLastModified
import com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue

Path dataDir = Paths.get(RunConfiguration.getProjectDir()).resolve("Include/data")

List<IPathComparable> files =
	Files.list(dataDir)
		.filter({ p -> p.getFileName().toString().endsWith(".eml") })
		// filter files with "To: xyz.com" header
		.map({ p -> new PathComparableByContentEmailHeaderValue(p, "To") })
		.filter({ p -> p.getValue().matches("xyz.com") })
		// to sort by the lastModified timestamp
		.map({ p -> new PathComparableByFileLastModified(p.get()) })
		// sort in descending order
		.sorted(Comparator.reverseOrder())
		// turn the Stream into a List
		.collect(Collectors.toList())
		
// print path of all eml files
files.eachWithIndex  { p, index ->
	println((index + 1) + "\t" + p.getValue() + "\t" + dataDir.relativize(p.get()))
}

Drivers
SortingFilesByDateTimeInContent-0.1.1.jar >> works for ‘PathComparableByFileLastModified’
SortingFilesByDateTimeInContent-0.3.3.jar >> One ‘parsed at index 0’ error

Error after running:

=============== ROOT CAUSE =====================
For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html
================================================
11-03-2022 07:50:41 AM Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 djeOpenSignUpEmail_LocalUsingTo,called
Elapsed time: 0.663s
Test Cases/A3_eAdvisorOnboarding/00_CommonCases/07 djeOpenSignUpEmail_LocalUsingTo,called FAILED.
Reason:
java.time.format.DateTimeParseException: Text '2 Nov 2022 15:32:04 -0700' could not be parsed at index 0
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.getDateInEmailHeader(PathComparableByContentEmailHeaderValue.java:61)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.resolveTimestamp(PathComparableByContentEmailHeaderValue.java:51)
	at com.kazurayam.study20221030.PathComparableByContentEmailHeaderValue.<init>(PathComparableByContentEmailHeaderValue.java:23)
	at Script1667485961584$_run_closure2.doCall(Script1667485961584.groovy:21)
	at com.sun.proxy.$Proxy10.apply(Unknown Source)
	at java_util_stream_Stream$collect$0.call(Unknown Source)
	at 07 djeOpenSignUpEmail_LocalUsingTo,called.run(07 djeOpenSignUpEmail_LocalUsingTo,called:28)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1667487039143.run(TempTestCase1667487039143.groovy:25)

I believe, you are still using the version 0.3.2, not 0.3.3.

Please check the Drivers folder. I presume in the Dirvers folder you have 2 jars; 0.3.2 and 0.3.3. Please remove the 0.3.2, close the project and reopen it.

Hi @kazurayam,
You were correct - I must have been working way too late into the night… All works now!
Thanks so much for all of your help, guidance and patience.

Best regards,
Dave