Skip to content

Commit 12dea18

Browse files
committed
This looks better right?
1 parent c67f0f8 commit 12dea18

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

app/src/main/kotlin/ImapConnection.kt

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ package org.cmdline.ackr
33
import com.sun.mail.util.MailSSLSocketFactory
44
import java.util.*
55
import javax.mail.Flags
6-
import javax.mail.Folder
6+
import javax.mail.Message
77
import javax.mail.Session
8+
import javax.mail.Folder
89
import javax.mail.Store
910

1011

1112
class ImapConnection {
1213
private val socketFactory = MailSSLSocketFactory().apply {
13-
isTrustAllHosts = true // TODO: Terrible. Remove.
14+
// isTrustAllHosts = true // TODO: Terrible. Remove.
1415
}
1516

1617
private val properties = Properties().apply {
1718
this["mail.imap.ssl.enable"] = "true"
1819
this["mail.imap.ssl.socketFactory"] = socketFactory
1920
}
2021

21-
fun fetchMail(
22-
host: String,
23-
user: String,
24-
password: String
25-
): List<Email> {
22+
fun fetchMail(host: String, user: String, password: String): List<Email> {
2623
val email = mutableListOf<Email>()
2724

2825
val session: Session = Session.getInstance(properties, null)
@@ -35,14 +32,7 @@ class ImapConnection {
3532
it.open(Folder.READ_ONLY)
3633
}
3734

38-
it.messages.forEach { msg ->
39-
email.add(Email(
40-
msg.from.firstOrNull()?.toString() ?: "",
41-
"is broken FIXME ",
42-
msg.subject,
43-
msg.content.toString() ?: "No Content!",
44-
msg.flags.contains(Flags.Flag.SEEN)))
45-
}
35+
it.messages.forEach { m -> email.add(read_users_email(m)) }
4636

4737
it.close()
4838
}
@@ -51,4 +41,14 @@ class ImapConnection {
5141

5242
return email
5343
}
44+
45+
private fun read_users_email(m: Message): Email {
46+
return Email(
47+
m.from.firstOrNull()?.toString() ?: "",
48+
"is broken FIXME ",
49+
m.subject,
50+
m.content.toString() ?: "No Content!",
51+
m.flags.contains(Flags.Flag.SEEN)
52+
)
53+
}
5454
}

0 commit comments

Comments
 (0)