public static byte[] messageBytes(Message m) { byte[] b = new byte[m.getSize()]; m.getBytes(b, 0); return b; }
private void fetchEnvelope( List<Pop3Message> messages, MessageRetrievalListener<Pop3Message> listener) throws IOException, MessagingException { int unsizedMessages = 0; for (Message message : messages) { if (message.getSize() == -1) { unsizedMessages++; } } if (unsizedMessages == 0) { return; } if (unsizedMessages < 50 && mMessageCount > 5000) { /* * In extreme cases we'll do a command per message instead of a bulk request * to hopefully save some time and bandwidth. */ for (int i = 0, count = messages.size(); i < count; i++) { Pop3Message message = messages.get(i); if (listener != null) { listener.messageStarted(message.getUid(), i, count); } String response = executeSimpleCommand( String.format( Locale.US, LIST_COMMAND + " %d", mUidToMsgNumMap.get(message.getUid()))); String[] listParts = response.split(" "); // int msgNum = Integer.parseInt(listParts[1]); int msgSize = Integer.parseInt(listParts[2]); message.setSize(msgSize); if (listener != null) { listener.messageFinished(message, i, count); } } } else { Set<String> msgUidIndex = new HashSet<String>(); for (Message message : messages) { msgUidIndex.add(message.getUid()); } int i = 0, count = messages.size(); String response = executeSimpleCommand(LIST_COMMAND); while ((response = readLine()) != null) { if (response.equals(".")) { break; } String[] listParts = response.split(" "); int msgNum = Integer.parseInt(listParts[0]); int msgSize = Integer.parseInt(listParts[1]); Pop3Message pop3Message = mMsgNumToMsgMap.get(msgNum); if (pop3Message != null && msgUidIndex.contains(pop3Message.getUid())) { if (listener != null) { listener.messageStarted(pop3Message.getUid(), i, count); } pop3Message.setSize(msgSize); if (listener != null) { listener.messageFinished(pop3Message, i, count); } i++; } } } }