我正在尝试使用 Soap Api 获取所有域帐户的收件箱邮件以获取Zimbra邮件。
我有以下代码来获取特定帐户收件箱邮件,但现在我需要使用管理员帐户获取所有域帐户收件箱邮件。
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Properties;
import javax.xml.soap.SOAPMessage;
import com.astidian.zimbra.ws.Marshaller;
import com.astidian.zimbra.ws.SOAPFaultException;
import com.astidian.zimbra.ws.SoapInterface;
import com.astidian.zimbra.ws.messages.AuthRequest;
import com.astidian.zimbra.ws.messages.AuthResponse;
import com.astidian.zimbra.ws.messages.ContextHeader;
import com.astidian.zimbra.ws.messages.SearchRequest;
import com.astidian.zimbra.ws.messages.SearchResponse;
public class Test {
public static void main(String[] args) throws Exception {
Properties p = new Properties();
p.load(Test.class.getResourceAsStream("test.properties"));
URL u = new URL(p.getProperty("url"));
SOAPMessage m = SoapInterface.newMessage();
AuthRequest authreq = new AuthRequest();
authreq.account = new AuthRequest.Account();
authreq.account.by = "name";
authreq.account.name = p.getProperty("user");
authreq.password = "bogus-fake";
// authreq.password = "7dw9T9Gb";
Marshaller.marshal(m.getSOAPBody(), authreq);
SoapInterface.setDebug(true);
m = SoapInterface.call(m, u);
try {
Marshaller.unmarshal(AuthResponse.class, m);
throw new IllegalStateException("soap fault expected");
}
catch (SOAPFaultException e) {
System.out.println("\nFault Code: " + e.code.value);
System.out.println("Fault reason: " + e.reason.text);
}
m = SoapInterface.newMessage();
authreq.password = p.getProperty("pass");
Marshaller.marshal(m.getSOAPBody(), authreq);
m = SoapInterface.call(m, u);
AuthResponse authresp = Marshaller.unmarshal(AuthResponse.class, m);
System.out.println("\n Authtoken: " + authresp.authToken);
///////////////////////////////////////////////////////////////////////
ContextHeader header = new ContextHeader();
header.authToken = authresp.authToken;
/** Getting Week start Date **/
Calendar c = GregorianCalendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
// Set the calendar to monday of the current week
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// Print dates of the current week starting on Monday
DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
String week_startDate = "";
week_startDate = df.format(c.getTime());
m = SoapInterface.newMessage();
SearchRequest searchreq = new SearchRequest();
searchreq.query = "in:inbox AND is:unread";//AND date:>="+week_startDate;
searchreq.type = "message";
searchreq.fetch = "all";
Marshaller.marshal(m.getSOAPHeader(), header);
Marshaller.marshal(m.getSOAPBody(), searchreq);
m = SoapInterface.call(m, u);
SearchResponse searchresp = Marshaller.unmarshal(
SearchResponse.class, m);
for (SearchResponse.Message msg : searchresp.messages) {
System.out.printf("From: %s <%s>\n",
msg.sender.fullName, msg.sender.emailAddress);
System.out.println("Subject: " + msg.subject);
System.out.println("Fragment:\n" + msg.fragment);
System.out.println();
}
}
}
请任何人都可以使用管理员帐户连接帮助我获取所有域帐号收件箱邮件!!!