login about faq

Hi,

I am trying to retrieve attached messages, and then from the attached message, I am trying to grab the attachments. I can get the number of attachments, but not the file name or the type of attachments, so this is a problem. I am including the code that is not functioning below.

How do I fix this?

Thanks,

Stewart

    String refName;
    refName = "";
    // refName is usually set to an empty string.
    // A non-empty reference name argument is the name of a mailbox or a level of
    // mailbox hierarchy, and indicates the context in which the mailbox
    // name is interpreted.

    // Select all mailboxes matching this pattern:
    String wildcardedMailbox;
    wildcardedMailbox = "*";

    CkMailboxes mboxes;
    mboxes = imap.ListMailboxes(refName,wildcardedMailbox);
    if (mboxes == null ) {
        System.out.println(imap.lastErrorText());
        return;
    }

    int i;
    for (i = 0; i <= mboxes.get_Count() - 1; i++) {
        String name = mboxes.getName(i);

        if (imap.SelectMailbox(name)) {
            int numMessages = imap.get_NumMessages();
            for (int j = 1; j <= numMessages; j++) {
                CkEmail email = imap.FetchSingle(j, false);
                if (email != null) {
                    int numAttached = email.get_NumAttachedMessages();
                    if (numAttached > 0)  {
                        for (int k = 0; k < numAttached; k++) {

                            CkEmail attachedMsg = email.GetAttachedMessage(k);
                            int numAttachments = attachedMsg.get_NumAttachments();
                            for (int l = 0; i < numAttachments; l++) {
                                CkString fName = new CkString();
                                CkString fType = new CkString();
                                email.GetAttachmentContentType(l, fType);
                                email.GetAttachmentFilename(l, fName);
                                // email.SaveAttachedFile(l, "file"+l);
                                System.out.println("attachment type: " + fType.getUtf8());
                                System.out.println("attachment file: " + fName.getUtf8());
                            }
                        }
                    }
                }
            }
            System.out.println("num message: " + imap.get_NumMessages());
        } else {
            System.out.println("Unable to select mailbox: " + name);
        }

    }

asked Nov 29 '12 at 04:20

Stewart's gravatar image

Stewart
1222


The problem is here:

email.GetAttachmentContentType(l, fType);
email.GetAttachmentFilename(l, fName);

You are using the wrong object for the calls to GetAttachmentContentType and GetAttachmentFilename. Use attachedMsg instead of email.

link

answered Nov 29 '12 at 08:50

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

edited Nov 29 '12 at 08:50

Thank you... Doh!

link

answered Nov 29 '12 at 10:31

Stewart's gravatar image

Stewart
1222

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×14
×6
×1

Asked: Nov 29 '12 at 04:20

Seen: 1,988 times

Last updated: Nov 29 '12 at 10:31

powered by OSQA