/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Grendel mail/news client. * * The Initial Developer of the Original Code is Netscape Communications * Corporation. Portions created by Netscape are * Copyright (C) 1997 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): * * Created: Terry Weissman , 24 Nov 1997. */ package grendel.storage; import calypso.util.ByteBuf; import calypso.util.Assert; import grendel.storage.addressparser.RFC822Mailbox; import grendel.storage.addressparser.RFC822MailboxList; import grendel.util.Constants; import java.io.InputStream; import java.io.IOException; import java.io.SequenceInputStream; import java.io.StringBufferInputStream; import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Enumeration; import javax.mail.Flags; import javax.mail.Header; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.InternetHeaders; import javax.mail.internet.MimeUtility; class MessageExtraWrapper implements MessageExtra { Message m; protected MessageExtraWrapper(Message mess) { m = mess; } protected String getSingleAddressName(String headername) { String[] list = null; try { list = m.getHeader("From"); } catch (MessagingException e) { } if (list == null || list.length < 1) return null; RFC822Mailbox boxes[] = new RFC822MailboxList(list[0]).getMailboxArray(); if (boxes == null || boxes.length < 1) return null; String result = boxes[0].getName(); if (result == null || result.length() == 0) result = boxes[0].getAddress(); return result; } public String getAuthor() { return getSingleAddressName("From"); } public String getRecipient() { return getSingleAddressName("To"); } // Removes leading "Re:" or similar from the given StringBuffer. Returns // true if it found such a string to remove; false otherwise. protected boolean stripRe(StringBuffer buf) { // Much of this code is duplicated in MessageBase. Sigh. ### if (buf == null) return false; int numToTrim = 0; int length = buf.length(); if (length > 2 && (buf.charAt(0) == 'r' || buf.charAt(0) == 'R') && (buf.charAt(1) == 'e' || buf.charAt(1) == 'E')) { char c = buf.charAt(2); if (c == ':') { numToTrim = 3; // Skip over "Re:" } else if (c == '[' || c == '(') { int i = 3; // skip over "Re[" or "Re(" // Skip forward over digits after the "[" or "(". while (i < length && buf.charAt(i) >= '0' && buf.charAt(i) <= '9') { i++; } // Now ensure that the following thing is "]:" or "):" // Only if it is do we treat this all as a "Re"-ish thing. if (i < (length-1) && (buf.charAt(i) == ']' || buf.charAt(i) == ')') && buf.charAt(i+1) == ':') { numToTrim = i+2; // Skip the whole thing. } } } if (numToTrim > 0) { int i = numToTrim; while (i < length - 1 && Character.isWhitespace(buf.charAt(i))) { i++; } for (int j=i ; j