if (sortFrom != null && sortFrom.length() > DbMailItem.MAX_SENDER_LENGTH)
if (sortFrom == null) sortFrom = ""; else if (sortFrom.length() > DbMailItem.MAX_SENDER_LENGTH)
    public Document getDocument(ParsedMessage pm)    throws MessagingException, ServiceException {                mDocument.add(Field.Text(LuceneFields.L_MIMETYPE, "message/rfc822"));        mDocument.add(Field.Keyword(LuceneFields.L_PARTNAME, LuceneFields.L_PARTNAME_TOP));        mDocument.add(new Field(LuceneFields.L_PARTNAME, LuceneFields.L_PARTNAME_TOP,   true/*store*/, true/*index*/, false/*tokenize*/));                String toValue = setHeaderAsField("to", pm, LuceneFields.L_H_TO, DONT_STORE, INDEX, TOKENIZE);        String ccValue = setHeaderAsField("cc", pm, LuceneFields.L_H_CC, DONT_STORE, INDEX, TOKENIZE);                setHeaderAsField("x-envelope-from", pm, LuceneFields.L_H_X_ENV_FROM, DONT_STORE, INDEX, TOKENIZE);        setHeaderAsField("x-envelope-to", pm, LuceneFields.L_H_X_ENV_TO, DONT_STORE, INDEX, TOKENIZE);        //        String msgId = setHeaderAsField("message-id", pm, LuceneFields.L_H_MESSAGE_ID, DONT_STORE, INDEX, DONT_TOKENIZE);                String msgId = pm.getHeader("message-id");        if (msgId.length() > 0) {                        if (msgId.charAt(0) == '<')                msgId = msgId.substring(1);                        if (msgId.charAt(msgId.length()-1) == '>')                msgId = msgId.substring(0, msgId.length()-1);                        if (msgId.length() > 0) {                //                                                         store, index, tokenize                mDocument.add(new Field(LuceneFields.L_H_MESSAGE_ID, msgId, false, true, false));            }        }                String subject = pm.getNormalizedSubject();        String sortFrom = pm.getParsedSender().getSortString();        if (sortFrom != null && sortFrom.length() > DbMailItem.MAX_SENDER_LENGTH)            sortFrom = sortFrom.substring(0, DbMailItem.MAX_SENDER_LENGTH);        String from = pm.getSender();                //                                                                                                             store, index, tokenize        mDocument.add(new Field(LuceneFields.L_H_FROM, from,                                    false, true, true));        mDocument.add(new Field(LuceneFields.L_H_SUBJECT, subject,                           false, true, true));        mDocument.add(new Field(LuceneFields.L_SORT_SUBJECT, subject.toUpperCase(), false, true, false));        mDocument.add(new Field(LuceneFields.L_SORT_NAME, sortFrom.toUpperCase(),    false, true, false));        // calculate the fragment *before* we add non-content data        mFragment = getFragment();        // add subject and from to main content for better searching        addContent(subject);        // Bug 583: add all of the TOKENIZED versions of the email addresses to our CONTENT field...        addContent(ZimbraAnalyzer.getAllTokensConcatenated(LuceneFields.L_H_FROM, from));        addContent(ZimbraAnalyzer.getAllTokensConcatenated(LuceneFields.L_H_TO, toValue));        addContent(ZimbraAnalyzer.getAllTokensConcatenated(LuceneFields.L_H_CC, ccValue));        String text = mContent.toString();                mDocument.add(Field.UnStored(LuceneFields.L_CONTENT, text));        String sizeStr = Integer.toString(pm.getMimeMessage().getSize());        mDocument.add(Field.Text(LuceneFields.L_SIZE, sizeStr));                try {            MimeHandler.getObjects(text, mDocument);        } catch (ObjectHandlerException e) {            String msgid = pm.getMessageID();            String sbj = pm.getSubject();            mLog.warn("Unable to recognize searchable objects in message (Message-ID: " +                msgid + ", Subject: " + sbj + ")", e);        }                // Get the list of attachment content types from this message and any        // TNEF attachments        Set<String> contentTypes = Mime.getAttachmentList(mMessageParts);                // Assemble a comma-separated list of attachment content types        StringBuilder buf = new StringBuilder();        for (String contentType : contentTypes) {            if (buf.length() > 0)                buf.append(',');            buf.append(contentType);        }                String attachments = buf.toString();        if (attachments.equals(""))            attachments = LuceneFields.L_ATTACHMENT_NONE;        else            attachments = attachments + "," + LuceneFields.L_ATTACHMENT_ANY;        mDocument.add(Field.UnStored(LuceneFields.L_ATTACHMENTS, attachments));                long date = pm.getReceivedDate();                String dateString = DateField.timeToString(date);        if (dateString != null) {            try {                mDocument.add(Field.Text(LuceneFields.L_DATE, dateString));            } catch(Exception e) {                // parse error on date or                 // date before/after lucene's valid date range.  ignore it.            }        } else {            throw new MessagingException("Couldn't get valid date for message");        }                return mDocument;    }