Package net.rim.blackberry.api.mail

Examples of net.rim.blackberry.api.mail.Message


     * @see net.rim.blackberry.api.mail.event.MessageListener#changed(MessageEvent)
     */

    public void changed(final MessageEvent e) {
        // Get the selected message to update screen at the message's row
        final Message message = e.getMessage();
        _listField.invalidate(_messages.indexOf(message));
    }
View Full Code Here


    /**
     * @see net.rim.blackberry.api.mail.event.FolderListener#messagesAdded(FolderEvent)
     */
    public void messagesAdded(final FolderEvent e) {
        final Message message = e.getMessage();

        message.addMessageListener(this);

        // Insert the message into the vector of messages, preserving
        // the sorted order.
        int indexToInsert = _messages.find(message);
        if (indexToInsert < 0) {
View Full Code Here

    /**
     * @see net.rim.blackberry.api.mail.event.FolderListener#messagesRemoved(FolderEvent)
     */
    public void messagesRemoved(final FolderEvent e) {
        final Message msg = e.getMessage();

        // Remove the listeners and delete the message from the list
        msg.removeMessageListener(this);
        _messages.removeElement(msg);

        updateScreen();
    }
View Full Code Here

     * @return A new message
     */
    Message getMessage() {
        // Find an outbox folder and use it to construct a new message
        final Folder outbox = _store.findFolder("Outbox")[FIRST];
        final Message message = new Message(outbox);

        // Add all the current headers
        for (int keyNo = 0; keyNo < HEADER_KEYS.length; keyNo++) {
            final Vector fieldsByType =
                    (Vector) _fieldTable.get(HEADER_KEYS[keyNo]);

            if (fieldsByType != null) {
                // Build a vector of all the addresses
                final Vector addressVector = new Vector();
                final int size = fieldsByType.size();
                for (int fieldNo = 0; fieldNo < size; fieldNo++) {
                    final TextField addressField =
                            (TextField) fieldsByType.elementAt(fieldNo);

                    // Try to create a new address object wrapping the email
                    // address and add it to the address vector.
                    try {
                        addressVector.addElement(new Address(addressField
                                .getText(), ""));
                    } catch (final AddressException e) // Invalid address
                    {
                        BlackBerryMailDemo
                                .errorDialog("Address(String, String) threw "
                                        + e.toString());
                    }
                }

                // Dump the vector of addresses into an array to send the
                // message
                final Address[] addresses = new Address[addressVector.size()];
                addressVector.copyInto(addresses);

                // Try to add the addresses to the message's list of recipients
                try {
                    message.addRecipients(HEADER_KEYS[keyNo], addresses);
                } catch (final MessagingException e) {
                    BlackBerryMailDemo
                            .errorDialog("Message#addRecipients(int, Address[]) threw "
                                    + e.toString());
                }
            }
        }

        // Add the subject
        final Vector subjectFields = (Vector) _fieldTable.get(SUBJECT);
        final TextField subjectField =
                (TextField) subjectFields.elementAt(FIRST);

        if (subjectFields != null && subjectFields.size() > 0) {
            message.setSubject(subjectField.getText());
        }

        // Add the body by adding all the body fields into one multipart
        final Vector bodyFields = (Vector) _fieldTable.get(BODY);
        if (bodyFields != null) {
            final int size = bodyFields.size();
            final Multipart content = new Multipart();
            for (int fieldNo = 0; fieldNo < size; fieldNo++) {
                final TextField body =
                        (TextField) bodyFields.elementAt(fieldNo);
                content.addBodyPart(new TextBodyPart(content, body.getText()));
            }
            try {
                message.setContent(content);
            } catch (final MessagingException e) {
                BlackBerryMailDemo
                        .errorDialog("Message#setContent(Object) threw "
                                + e.toString());
            }
        } else {
            BlackBerryMailDemo.errorDialog("Error: no body field available");
            return null;
        }

        // Set the date
        message.setSentDate(Calendar.getInstance().getTime());

        return message;
    }
View Full Code Here

     * @see net.rim.device.api.ui.Screen#onSave()
     */
    protected boolean onSave() {
        // Save the message to the outbox
        try {
            final Message newMessage = getMessage();
            if (newMessage != null) {
                // Retrieve an outbox to save the message in
                final Store store = Session.waitForDefaultSession().getStore();
                final Folder[] allOutboxFolders = store.list(Folder.OUTBOX);

View Full Code Here

     * @see net.rim.device.api.ui.component.ListFieldCallback#drawListRow(ListField,
     *      Graphics, int, int, int)
     */
    public void drawListRow(final ListField list, final Graphics g,
            final int index, final int y, final int w) {
        final Message message = (Message) _messages.elementAt(index);

        int x = 0;

        // If an icon associated with the message's status exists in our
        // _statusMap, then draw it.
        g.drawText(Util.getStatusIcon(message), x, y, 0, w);

        x += _statusColumnWidth;

        // Display the date that the message was received
        final Date recievedDate = message.getReceivedDate();
        g.drawText(Util.getDateAsString(recievedDate, DateFormat.DATE_SHORT),
                x, y, 0, _dateColumnWidth);
        x += _dateColumnWidth;

        // Display the name of the sender if the message is inbound
        String name;
        if (message.isInbound()) {
            name = getSenderName(message);
        } else // Outbound message
        {
            name = getFirstRecipientName(message);
        }
        g.drawText(name, x, y, DrawStyle.ELLIPSIS, _nameColumnWidth);
        x += _nameColumnWidth;

        // Display the subject in the remaining column width
        final int remainingColumnWidth = Display.getWidth() - x;
        String textToDisplay = message.getSubject();
        if (textToDisplay == null) // No subject
        {
            textToDisplay = MessageScreen.NO_SUBJECT;
        }

View Full Code Here

             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
             *      Object)
             */
            public void execute(final ReadOnlyCommandMetadata metadata,
                    final Object context) {
                final Message msg = (Message) getSelectedItem();
                final MessageScreen messageScreen =
                        new MessageScreen(msg, true);
                UiApplication.getUiApplication().pushScreen(messageScreen);
                updateScreen();
            }
View Full Code Here

            menu.add(_changeViewMenuItem);

            // If the selected item is a message then allow the user to open it
            final Object obj = getSelectedItem();
            if (obj instanceof Message) {
                final Message msg = (Message) obj;

                // If the message is a saved message allow the user to edit it
                if (msg.getStatus() == Message.Status.TX_COMPOSING) {
                    menu.add(_editMenuItem);
                } else // Allow the user to view the message
                {
                    menu.add(_openMenuItem);
                }
View Full Code Here

            } else if (obj instanceof Folder) {
                text =
                        Characters.WHITE_RIGHT_POINTING_SMALL_TRIANGLE + "  "
                                + ((Folder) obj).getName();
            } else if (obj instanceof Message) {
                final Message message = (Message) obj;
                text =
                        Util.getStatusIcon(message) + "  "
                                + message.getSubject();
            }

            g.drawText(text, 0, y, 0, w);
        }
View Full Code Here

TOP

Related Classes of net.rim.blackberry.api.mail.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.