今天有个项目要用到java mail 进行快速收信,但不删除邮件,所以需要用UIDL获取邮件唯一ID,上网找了一下java mail的实现,有一种改源代码提升效率的方法,不过改源代码比较难维护,所以我想java不至于连这个都没有实现吧,深入看了一下,发现java mail自带的方法就可以完成这个操作,在这里记录一下。
set debug以后我们来看看输出:
DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
DEBUG POP3: connecting to host “pop.126.com”, port 110, isSSL false
S: +OK Welcome to coremail Mail Pop3 Server (126coms[f7aa0ed0270c139a0807240dd700906bs])
C: CAPA
S: +OK Capability list follows
TOP
USER
PIPELINING
UIDL
.
DEBUG POP3: server doesn’t support TOP, disabling it
C: USER *******
S: +OK core mail
C: PASS *******
S: +OK 11 message(s) [766874 byte(s)]
C: STAT
S: +OK 11 766874
C: NOOP
S: +OK core mail
C: UIDL
S: +OK 11 766874
1 1tbirAJ99EX9fhakLwAAs8
2 1tbirAJ99EX9fhakLwABs9
3 1tbi5w1-9EzBsjIZ6AAAsd
4 1tbirAd-9EX9fibK1AAAse
5 1tbi3RR-9EsL9JOV8AAAsA
6 1tbiGAyA9El1nWUOqgAAsA
7 1tbirB+B9EX9fjVf8gAAsY
8 1tbi0hWC9EgYwFaoYwAAs8
9 1tbiBR2D9EkAFOKknwAAsr
10 1tbi0gGD9EgYwGOBNgAAsg
11 1tbi0gGD9EgYwGOBNgACsi
.
1 <————-System.out.println(msgs[0].getMessageNumber());
1tbirAJ99EX9fhakLwAAs8 <————-System.out.println(folder.getUID(msgs[0]));
C: QUIT
S: +OK core mail