У меня следующий код запускается на сервере через gwt rpc:
public class MailHandlerServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
MimeMessage message = new MimeMessage(session, req.getInputStream());
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Я не знаю функцию, которая разбирает MimeMessage
. Как мне получить содержимое MimeMessage
?
вот простой код, который я пишу, но он не работает:
Object content = message.getContent();
if(content instanceof Multipart){
Multipart mp = (Multipart)content;
int count3 = mp.getCount();
for(int i = 0;i < count3;i++){
BodyPart p = mp.getBodyPart(i);
if(p.isMimeType("text/plain")){
TextBody data = (TextBody) p.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
data.writeTo(baos);
String datafull = new String(baos.toByteArray());
PrintWriter out = resp.getWriter();
out.print(datafull.toString());
}