1 21 22 27 28 package javax.mail; 29 30 44 public class MessageContext { 45 private Part part; 46 47 50 public MessageContext(Part part) { 51 this.part = part; 52 } 53 54 59 public Part getPart() { 60 return part; 61 } 62 63 70 public Message getMessage() { 71 try { 72 return getMessage(part); 73 } catch (MessagingException ex) { 74 return null; 75 } 76 } 77 78 87 private static Message getMessage(Part p) throws MessagingException { 88 while (p != null) { 89 if (p instanceof Message ) 90 return (Message )p; 91 BodyPart bp = (BodyPart )p; 92 Multipart mp = bp.getParent(); 93 if (mp == null) return null; 95 p = mp.getParent(); 96 } 97 return null; 98 } 99 100 105 public Session getSession() { 106 Message msg = getMessage(); 107 return msg != null ? msg.session : null; 108 } 109 } 110 | Popular Tags |