@@ -3,26 +3,23 @@ package org.cmdline.ackr
3
3
import com.sun.mail.util.MailSSLSocketFactory
4
4
import java.util.*
5
5
import javax.mail.Flags
6
- import javax.mail.Folder
6
+ import javax.mail.Message
7
7
import javax.mail.Session
8
+ import javax.mail.Folder
8
9
import javax.mail.Store
9
10
10
11
11
12
class ImapConnection {
12
13
private val socketFactory = MailSSLSocketFactory ().apply {
13
- isTrustAllHosts = true // TODO: Terrible. Remove.
14
+ // isTrustAllHosts = true // TODO: Terrible. Remove.
14
15
}
15
16
16
17
private val properties = Properties ().apply {
17
18
this [" mail.imap.ssl.enable" ] = " true"
18
19
this [" mail.imap.ssl.socketFactory" ] = socketFactory
19
20
}
20
21
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 > {
26
23
val email = mutableListOf<Email >()
27
24
28
25
val session: Session = Session .getInstance(properties, null )
@@ -35,14 +32,7 @@ class ImapConnection {
35
32
it.open(Folder .READ_ONLY )
36
33
}
37
34
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)) }
46
36
47
37
it.close()
48
38
}
@@ -51,4 +41,14 @@ class ImapConnection {
51
41
52
42
return email
53
43
}
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
+ }
54
54
}
0 commit comments