Get the named header.
(String name)
| 933 | * Get the named header. |
| 934 | */ |
| 935 | @Override |
| 936 | public String[] getHeader(String name) throws MessagingException { |
| 937 | checkExpunged(); |
| 938 | |
| 939 | if (isHeaderLoaded(name)) // already loaded ? |
| 940 | return headers.getHeader(name); |
| 941 | |
| 942 | // Load this particular header |
| 943 | InputStream is = null; |
| 944 | |
| 945 | // Acquire MessageCacheLock, to freeze seqnum. |
| 946 | synchronized(getMessageCacheLock()) { |
| 947 | try { |
| 948 | IMAPProtocol p = getProtocol(); |
| 949 | |
| 950 | // This message could be expunged when we were waiting |
| 951 | // to acquire the lock ... |
| 952 | checkExpunged(); |
| 953 | |
| 954 | if (p.isREV1()) { |
| 955 | BODY b = p.peekBody(getSequenceNumber(), |
| 956 | toSection("HEADER.FIELDS (" + name + ")") |
| 957 | ); |
| 958 | if (b != null) |
| 959 | is = b.getByteArrayInputStream(); |
| 960 | } else { |
| 961 | RFC822DATA rd = p.fetchRFC822(getSequenceNumber(), |
| 962 | "HEADER.LINES (" + name + ")"); |
| 963 | if (rd != null) |
| 964 | is = rd.getByteArrayInputStream(); |
| 965 | } |
| 966 | } catch (ConnectionException cex) { |
| 967 | throw new FolderClosedException(folder, cex.getMessage()); |
| 968 | } catch (ProtocolException pex) { |
| 969 | forceCheckExpunged(); |
| 970 | throw new MessagingException(pex.getMessage(), pex); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | // if we get this far without "is" being set, something has gone |
| 975 | // wrong; prevent a later NullPointerException and return null here |
| 976 | if (is == null) |
| 977 | return null; |
| 978 | |
| 979 | if (headers == null) |
| 980 | headers = new InternetHeaders(); |
| 981 | headers.load(is, allowutf8); // load this header into the Headers object. |
| 982 | setHeaderLoaded(name); // Mark this header as loaded |
| 983 | |
| 984 | return headers.getHeader(name); |
| 985 | } |
| 986 | |
| 987 | /** |
| 988 | * Get the named header. |
no test coverage detected