filter mails by property contact alias
This commit is contained in:
@@ -28,14 +28,16 @@ class EmailStorage(
|
||||
val safeName = (messageId ?: UUID.randomUUID().toString()).replace(Regex("[^A-Za-z0-9._-]"), "_")
|
||||
val fileName = "${safeName}_${OffsetDateTime.now().toEpochSecond()}.pdf"
|
||||
val path = dir.resolve(fileName).normalize()
|
||||
val tmp = dir.resolve("${fileName}.tmp").normalize()
|
||||
|
||||
val document = PDDocument()
|
||||
val page = PDPage(PDRectangle.LETTER)
|
||||
document.addPage(page)
|
||||
val header = "Subject: ${subject ?: ""}\n\n"
|
||||
writeText(document, page, header + body)
|
||||
document.save(path.toFile())
|
||||
document.save(tmp.toFile())
|
||||
document.close()
|
||||
atomicMove(tmp, path)
|
||||
return path.toString()
|
||||
}
|
||||
|
||||
@@ -82,4 +84,28 @@ class EmailStorage(
|
||||
content.endText()
|
||||
content.close()
|
||||
}
|
||||
|
||||
fun storeEml(propertyId: UUID?, messageId: String?, rawBytes: ByteArray): String {
|
||||
val dir = if (propertyId != null) {
|
||||
Paths.get(rootPath, propertyId.toString(), "raw")
|
||||
} else {
|
||||
Paths.get(rootPath, "unassigned", "raw")
|
||||
}
|
||||
Files.createDirectories(dir)
|
||||
val safeName = (messageId ?: UUID.randomUUID().toString()).replace(Regex("[^A-Za-z0-9._-]"), "_")
|
||||
val fileName = "${safeName}_${OffsetDateTime.now().toEpochSecond()}.eml"
|
||||
val path = dir.resolve(fileName).normalize()
|
||||
val tmp = dir.resolve("${fileName}.tmp").normalize()
|
||||
Files.write(tmp, rawBytes)
|
||||
atomicMove(tmp, path)
|
||||
return path.toString()
|
||||
}
|
||||
|
||||
private fun atomicMove(tmp: Path, target: Path) {
|
||||
try {
|
||||
Files.move(tmp, target, java.nio.file.StandardCopyOption.ATOMIC_MOVE, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||
} catch (_: Exception) {
|
||||
Files.move(tmp, target, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user