-
Notifications
You must be signed in to change notification settings - Fork 182
/
RetrCommand.java
54 lines (45 loc) · 1.67 KB
/
RetrCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) 2014 Wael Chatila / Icegreen Technologies. All Rights Reserved.
* This software is released under the Apache license 2.0
* This file has been used and modified.
* Original file can be found on http://foedus.sourceforge.net
*/
package com.icegreen.greenmail.pop3.commands;
import com.icegreen.greenmail.foedus.util.MsgRangeFilter;
import com.icegreen.greenmail.pop3.Pop3Connection;
import com.icegreen.greenmail.pop3.Pop3State;
import com.icegreen.greenmail.store.MailFolder;
import com.icegreen.greenmail.store.StoredMessage;
import com.icegreen.greenmail.util.GreenMailUtil;
import javax.mail.Flags;
import java.io.StringReader;
import java.util.List;
public class RetrCommand
extends Pop3Command {
@Override
public boolean isValidForState(Pop3State state) {
return state.isAuthenticated();
}
@Override
public void execute(Pop3Connection conn, Pop3State state,
String cmd) {
try {
MailFolder inbox = state.getFolder();
String[] cmdLine = cmd.split(" ");
String msgNumStr = cmdLine[1];
List<StoredMessage> msgList = inbox.getMessages(new MsgRangeFilter(msgNumStr, false));
if (msgList.size() != 1) {
conn.println("-ERR no such message");
return;
}
StoredMessage msg = msgList.get(0);
String email = GreenMailUtil.getWholeMessage(msg.getMimeMessage());
conn.println("+OK");
conn.println(email);
conn.println(".");
msg.setFlag(Flags.Flag.SEEN, true);
} catch (Exception e) {
conn.println("-ERR " + e);
}
}
}