How to fetch messages using IMAPFolder ?

Dear Friends,
Anybody knows how to show messages with IMAPFolder ?
Thank u.
Chirag Patel

I have never seen the class IMAPFolder. Here is a class I wrote that returns a table row that has message information from a folder.
Use the messagelist method and pass in the folder you want along with the connection url to your server.
=======================================================================
=======================================================================
import java.util.*;
import java.util.Properties;
import java.net.*;
import java.io.*;
import java.lang.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class EmailListMessages {
     static String outputString = "";
     public String timeoutVal = "5000";
     public String messagelist(String mbox, String url, int timeout) throws Exception {
          timeoutVal = timeout + "";
          return messagelist(mbox,url);
     public String messagelist(String mbox, String url) throws Exception{
          int optind;
     int port = -1;
     boolean verbose = false;
     boolean debug = false;
     boolean showStructure = false;
          Store store = null;
          outputString = "";
          try {
          // Get a Properties object
          Properties props = System.getProperties();
               props.put("mail.imap.connectiontimeout",timeoutVal);
               props.put("mail.imap.timeout",timeoutVal);
          // Get a Session object
          Session session = Session.getDefaultInstance(props, null);
          session.setDebug(debug);
          // Get a Store object
               URLName urln = new URLName(url);
               store = session.getStore(urln);
               store.connect();
     } catch (Exception e) {outputString = "Error:Host Connection";}
          // Open the Folder
          Folder folder = store.getDefaultFolder();
          if (folder == null) {
     outputString = "No default folder error";
               return outputString;
     folder = folder.getFolder(mbox);
     if (folder == null) {
     outputString = "Invalid folder error";
               return outputString;
     // try to open read/write and if that fails try read-only
     try {
               folder.open(Folder.READ_WRITE);
     } catch (MessagingException ex) {folder.open(Folder.READ_ONLY);}
     int totalMessages = folder.getMessageCount();
     if (totalMessages == 0) {
               outputString = "(No Messages)";
               folder.close(true);
               store.close();
               return outputString;
          // Attributes & Flags for all messages ..
          Message[] msgs = folder.getMessages();
          // Use a suitable FetchProfile
          FetchProfile fp = new FetchProfile();
          fp.add(FetchProfile.Item.ENVELOPE);
          fp.add(FetchProfile.Item.FLAGS);
          fp.add("X-Mailer");
          folder.fetch(msgs, fp);
          for (int i = 0; i < msgs.length; i++) {
          dumpEnvelope(msgs,mbox);
          folder.close(false);
          store.close();
          return outputString;
     public static void dumpEnvelope(Message m, String mbox) throws Exception {
          String fromString = "";
          String subjectString = "";
          String dtString = "";
          String flagString = "";
          Address[] a;
          int msgNumber = m.getMessageNumber();
          if (mbox.equals("Sent"))
               // TO
               if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
               for (int j = 0; j < a.length; j++)
                    fromString = a[j].toString();
               fromString = ("<td><a href='EmailViewMessage.jsp?messageNumber=" + msgNumber + "&folderName=" + mbox + "'>" + fromString + "</a></td>");     
          else
               // FROM
               if ((a = m.getFrom()) != null) {
               for (int j = 0; j < a.length; j++)
                    fromString = a[j].toString();
               fromString = ("<td><a href='EmailViewMessage.jsp?messageNumber=" + msgNumber + "&folderName=" + mbox + "'>" + fromString + "</a></td>");     
          // SUBJECT
          subjectString = m.getSubject();
          subjectString = ("<td>" + subjectString + "</td>");
          // DATE
          Date d = m.getSentDate();
          dtString = "UNKNOWN";
          if (d != null) dtString = d.toString();
          dtString = ("<td>" + dtString + "</td>");
          // FLAGS
          Flags flags = m.getFlags();
          StringBuffer sb = new StringBuffer();
          Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
          boolean first = true;
          for (int i = 0; i < sf.length; i++) {
          String s;
          Flags.Flag f = sf[i];
          if (f == Flags.Flag.ANSWERED)
               s = "\\Answered";
          else if (f == Flags.Flag.DELETED)
               s = "\\Deleted";
          else if (f == Flags.Flag.DRAFT)
               s = "\\Draft";
          else if (f == Flags.Flag.FLAGGED)
               s = "\\Flagged";
          else if (f == Flags.Flag.RECENT)
               s = "\\Recent";
          else if (f == Flags.Flag.SEEN)
               s = "\\Seen";
          else
               continue;     // skip it
          if (first)
               first = false;
          else
               sb.append(' ');
          sb.append(s);
          String[] uf = flags.getUserFlags(); // get the user flag strings
          for (int i = 0; i < uf.length; i++) {
          if (first)
               first = false;
          else
               sb.append(' ');
          sb.append(uf[i]);
          flagString = sb.toString();
          String testString = "\\Seen";
          if (!flagString.equals(testString))
               flagString = ("<td>New</td>");
          else
               flagString = ("<td> </td>");
          outputString = (outputString + "<tr bgcolor='#a9a9a9'>" + fromString + subjectString + dtString + flagString + "</tr>");

Similar Messages

  • How to fetch message comments using JMA API?

    Hi All,
    From telnet <host> 143, and tring get comments associated with a message works well as shown below.
    2 fetch 8 COMMENT ("/message/vendor/ms/follow-up-flag-status" ("value.shared"))
    * 8 FETCH (COMMENT ("/message/vendor/ms/follow-up-flag-status" ("value.shared" "completed")))
    How to fetch the same details using Java Mail API. I couldn't get any of these flags when added to FetchProfile before fetching. The last option is using IMAPFolder.ProtocolCommand.
    Please suggest if there is a better way to fetch message meta data as "comment" using JMA
    Regards,
    Venkat

    I don't know what JMA is. I assume you meant JavaMail.
    Sorry, there's no direct support for fetching that data.
    You might be able to get this to work using IMAPFolder.ProtocolCommand.

  • How to monitor messages using CIDX Communication Channel

    I created a CIDX Communication Channel. XI failed to get a message from the source. How to monitor the messages using CIDX communication channel.

    Not sure about the monitoring but u may recheck the communication channel settings as shown:
    Sender
    http://help.sap.com/saphelp_nw2004s/helpdata/en/0a/512041cfb7f423e10000000a155106/content.htm
    Receiver
    http://help.sap.com/saphelp_nw2004s/helpdata/en/68/1b20410e91f523e10000000a155106/content.htm
    Regards,
    Prateek

  • How to raise message using the attributes created in Theme

    Hi,
    I have created an attribute in the theme of the internet service.
    I want to raise a message using alert, how can i use this attribute in the javascript method?
    Regards
    Sohit

    Hi,
    try
    <script language="javascript">
    alert('Attribute:' + `yourAttribute`);
    </script>
    mind the backtics `` !!!
    kind regards,
    ralph

  • How to receive messages using my iPad number than receiving messages from email

    HOw do I receive messages using my iPad number not my email address

    You are probably going to have to sign out of/turn off Messages on the phone and the iPad and then start all over again and enable messages on the phone first so that the number is accessible again to use on the iPad in Settings>Messages>Send and Receive at>You can be reached by iMessages at. You need to be able to select your phone number in there.
    This kb article explains it in detail.
    http://support.apple.com/kb/HT5538

  • How to display message using default lock in ORACLE 9i?

    I am using ORACLE 9i I am inserting a same record in a same table (which is having primary key) of same user with different sql editor (or from different machines).
    with same time.
    One person is able to insert the record..
    But other one is in processing state, once the inserted person give commit,then only other person got the message "Primary key constraint voilated".
    This is bcoz of concurrency in oracle. For this purpose Oracle uses default lock.
    Is it possible to give message to other person like "One user is using this table..", after a record is inserted and before commit is get issued by the inserted user?
    how can i do this?
    Thanks a lot for your help

    [url http://forums.oracle.com/forums/thread.jspa?threadID=543335&tstart=0]duplicate thread

  • How to fetch rows using exec_sql

    hello to all
    i want to open a cursor and fetch some field values dynamically."the fields to be fetched will be selected by the user" i.e i have to get the data of the fields selected by the user.
    for this i am using the exec_sql method.
    its giving a message as 'FRM-01747: invalid user.table.column,table.column or column specification"
    i don't where i am wrong in the code.
    this is my code to fetch the values
    Declare
         Con_id EXEC_SQL.CONNTYPE;
         Cur_id EXEC_SQL.CURSTYPE;
         sqlstr varchar2(3000);
         fld1 number(20,2);
         fld2 number(20,2);
         fld3 number(20,2);
         fld4 number(20,2);
         fld5 number(20,2);
         fld6 number(20,2);
         fld7 number(20,2);
         fld8 number(20,2);
         nEmpno number(10,4);
         nIgn PLS_INTEGER;
         totRows number(5);
         a number;
    Begin
    --1
    Con_id := EXEC_SQL.DEFAULT_CONNECTION;--('scott/tiger@siil');
    go_block('BlkDet');
    Cur_id := EXEC_SQL.OPEN_CURSOR();
    sqlstr := 'Select A.EmpNo,A.'||:BlkMain.LstFld1||',A.';
    sqlstr := sqlstr||:BlkMain.LstFld2||',A.';
    sqlstr := sqlstr||:BlkMain.LstFld3||',A.';
    sqlstr := sqlstr||:BlkMain.LstFld4||',B.';
    sqlstr := sqlstr||:BlkMain.LstFld1||',B.';
    sqlstr := sqlstr||:BlkMain.LstFld2||',B.';
    sqlstr := sqlstr||:BlkMain.LstFld3||',B.';
    sqlstr := sqlstr||:BlkMain.LstFld4;
    sqlstr := sqlstr||' from Tempsalmast A, SalMast B';
    sqlstr := SqlStr||' where A.EmpNo=B.EmpNo';
    Message(SqlStr);
    Message(SqlStr);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,1,nEmpNo);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,2,Fld1);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,3,Fld2);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,4,Fld3);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,5,Fld4);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,6,Fld5);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,7,Fld6);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,8,Fld7);
    EXEC_SQL.DEFINE_COLUMN(Con_id,Cur_id,9,Fld8);
    EXEC_SQL.PARSE(Con_id,Cur_id,sqlstr,EXEC_SQL.V7);
    nIgn:=EXEC_SQL.EXECUTE(Con_id,Cur_id);
    while (EXEC_SQL.FETCH_ROWS(Con_id,Cur_id)>0) Loop
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,1,nEmpNo);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,2,Fld1);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,3,Fld2);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,4,Fld3);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,5,Fld4);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,6,Fld5);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,7,Fld6);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,8,Fld7);
    EXEC_SQL.COLUMN_VALUE(Con_id,Cur_id,9,Fld8);
    :BlkDet.TxtEmpNo:=nEmpNo;
    :BlkDet.DisFld1 :=Fld1;
    :BlkDet.DisFld2 :=Fld2;
    :BlkDet.DisFld3 :=Fld3;
    :BlkDet.DisFld4 :=Fld4;
    :BlkDet.TxtFld1 :=Fld5;
    :BlkDet.TxtFld2 :=Fld6;
    :BlkDet.TxtFld3 :=Fld7;
    :BlkDet.TxtFld4 :=Fld8;
    next_record;
    end Loop;
    --next_record;
    end;
    exception
         when others then
         Message(Dbms_Error_Text);
         Message(Dbms_Error_Text);
    can any body pls. help me out
    aditya

    Fetching rows to display them is a task for the client tool. You need to define a ref cursor therefore.
    If you just want to play around, here we go
    SQL> DECLARE
      2    type t1 is table of emp%rowtype index by binary_integer;
      3    var1 t1;
      4    v_counter number:=0;
      5  BEGIN
      6    select * bulk collect into var1 from emp;
      7    for vr in 1..var1.count loop
      8      dbms_output.put_line(var1(vr).ename);
      9      update dept set deptno=var1.deptno Here also Error occured.
    10    end loop;
    11  END;
    12  /
    SCOTT
    ADAMS
    PL/SQL procedure successfully completed.
    SQL>

  • How to fetch substring using regular expression

    Hi,
    I am new to using regular expression and would like to know some basic details of how to use them in Java.
    I have a String example= "http://www.google.com/foobar.html#*q*=database&aq=f&aqi=g10&fp=c9fe100d9e542c1e" and would like to get the value of "q" parameter (in bold) using regular expression in java.
    For the same example, when we tried using javascript:
    match = example.match("/^http:\/\/(?:(?!mail\.)[^\.]+?\.)?google\.[^\?#]+(?:.*[\?#&](?:as_q|q)=([^&]+))?/i}");
    document.write('
    ' + match);
    We are getting the output as: http://www.google.com/foobar.html#q=database,*database* where the bold text is the value of "q" parameter.
    In Java we are trying to get the value of the q parameter separately or atleast resembles the output given by JavaScript. Please help me resolving this issue.
    Regards
    Praveen

    BalusC wrote:
    Regex is a cumbersome solution for fixed patterns like URL's. String#substring() in combination with String#indexOf would most likely already suffice.I usually agree, although, in this case, finding the exact parameter might be difficult without a small regex, perhaps:
    "\\wq=\\s*"in conjunction with Pattern/Matcher, used similarly to an indexOf() to find the start of the parameter value.
    Winston

  • How to send message using Head,PUT,DELETE method

    we can use Get,Post method in a form, but how to use Head,Put,DELETE method to submit. I try to use "method=head" in form tag, and write some code in doHead() method in servlet, but after I submit the form, the doHead() is not called by the servlet.

    In HTML there is no Tag that support HEAD or PUT. You might create your own HTTP Client and implement HEAD and PUT Requests. Have a look at the HTTP Protocol to learn what they are used for and how they are to be implemented.

  • How to fetch data using Substring & Instring

    Hi ,
    I have data like
    a_76488b_2780c
    a_76488b_2780c_
    a_76488b_c2780
    a_76488b_c2780
    a_31487b_5542
    a_76488b_2780
    i want to fetch data like last 4 numeric digit only
    2780
    2780
    2780
    2780
    5542
    2780

    I don't know what you have against rexexp_replace, but this works if you want all the digits after the second underscore:
    WITH t AS
            (SELECT 'a_76488b_2780c' str FROM DUAL
             UNION ALL
             SELECT 'a_76488b_2780c_' FROM DUAL
             UNION ALL
             SELECT 'a_76488b_c2780' FROM DUAL
             UNION ALL
             SELECT 'a_76488b_c2780' FROM DUAL
             UNION ALL
             SELECT 'a_31487b_5542' FROM DUAL
             UNION ALL
             SELECT 'a_76488b_2780' FROM DUAL
    SELECT replace(after_second_und
                  ,replace(translate(after_second_und
                                    ,'0123456789'
                          ,NULL
                  ,NULL
                  ) your_number
    FROM   (SELECT   SUBSTR(str,instr(str,'_',1,2)+1) after_second_und
            FROM t
    YOUR_NUMBER
    2780
    2780
    2780
    2780
    5542
    2780

  • Fetching Messages mail ?

    how to Fetching Messages ?

    Use the JavaMail api. If you could give more information maybe I could too.

  • Fetch data using structure with full working example

    does any body tell me how to fetch data using structure with full working example
    the structure name is RSTXT and the field is TXLINE
    the data in the form of text is entered from the functional side using t-code ME52N
    from there i have to fetch the data
    in smartform or in report

    using this code to get text from ME52N  this is a structure still not getting output  
    DATA:BEGIN OF TA_ROW occurs 0,
          TXZ01(1000) TYPE C,
          END OF TA_ROW.
      DATA:BEGIN OF IT_ROW OCCURS 0,
          TXZ01(1000) TYPE C,
          END OF IT_ROW.
       DATA: thread LIKE thead.
       DATA: headerid TYPE char24.
       DATA: it_text LIKE tline OCCURS 0 WITH HEADER LINE.
       data:wa_banfn like eban-banfn.
       thread-tdid = 'B01'.
       thread-tdname = headerid.
       thread-tdobject = 'EBAN'.
         select txz01 from eban into corresponding fields of table ta_row
          where banfn = wa_banfn.
       headerid = '  '.
       CALL FUNCTION 'READ_TEXT'
         EXPORTING
      CLIENT                        = SY-MANDT
           id                            = thread-tdid
           language                      = sy-langu
           name                          = thread-tdname
           object                        = thread-tdobject
      ARCHIVE_HANDLE
                                    = 0
      LOCAL_CAT                     = ' '
    IMPORTING
      HEADER                        =
         TABLES
    lines                         = it_text
        EXCEPTIONS
          id                            = 1
          language                      = 2
          name                          = 3
          not_found                     = 4
          object                        = 5
          reference_check               = 6
          wrong_access_to_archive       = 7
          OTHERS                        = 8.
         LOOP AT it_text.
         CLEAR ta_row.
       BREAK-POINT.
      FROM THIS POINT TEXT IS COMING
         ta_row-txz01 = it_text-tdline.
         APPEND ta_row TO it_row.
         ENDLOOP.

  • How to fetch a package's commit messages as text?

    I use a set of my own scripts for building everything from abs/aur from source.  I track dependencies, including makedepends, package groups, package splits, etc by scanning PKGBULDs to extract the info into my database.  My build script attempts to automatically show me the README and configuration options via "configure --help" or "cmake -LH", and after the package is built it shows me the namcap output so that I can approve the build and go on or change the PKGBUILD to correct errors.
    I would really like to have my build script also show me the changelog, as a text file, for the package by fetching the commit messages from the Arch web interface, such as http://projects.archlinux.org/svntogit/ … &showmsg=1, but I don't know how to fetch that dynamic page as a text file. 
    If it were a simple static page like the main page for archlinux.org I could get it with lynx -dump or html2text, but these don't give me anything useful for the package's "View Changes" pages.
    I hope that seems like a simple problem to someone.  Please give me a clue how to fetch dynamic pages like that as text...
    Last edited by sitquietly (2012-02-03 20:56:44)

    karol wrote:Have you seen https://bbs.archlinux.org/viewtopic.php?id=134591 ?
    Yes, of course, and it may be helpful if I have to dig into it's code, but by itself it gives markup (colorized text intended for a terminal emulator) rather than plain text.  If I dump its output into vim I still have what looks like trash.  I could filter out the markup.  Argh.
    Any other help out there??

  • E63 - how to reply to a message using 1 click inst...

    Dear all,
    I would be interested to know how one replies to a text message using 1 click instead of 3, via Nokia E63. The reply sequence that I currently have to follow is
    1) click Options
    2) select Reply
    3) then select Via text message
    Is there a direct means to get to the reply window with one click instead of three clicks?
    I hope there is one because it takes time and becomes inconvenient to wait.
    Thank you for assistance in this regard.
    Regards,
    S Ahmad
    Solved!
    Go to Solution.

    Hi sahmad7
    I tried replying a message in one step but didn't succeed.
    The least steps number I was able to do is 2
    Before entering the message press Options then reply, and the phone will open SMS writing screen directly.
    Other than that, try to get a program that is able to do that.
    I hope that helps you, and please let me know
    Phones I bought from 1st till now:
    3210 / 3310 / 3410 / 6310 / 6600 / 6020 / N72 / E51 / X2-00 / 5310 xpress Music / E90 Communicator
    If you like my post or it helped you, Give me Kodo

  • I have an iMac, and have a Verizon DSL account. Recently, my Mac Mail keeps requesting the passwords on my account every few minutes, and will not allow me to send messages using Mac Mail. I cannot edit the outgoing server; how can I send emails?

    I have an iMac, and have a Verizon DSL account (3 email addresses). Recently, my Mac Mail keeps requesting the passwords on my accounts every few minutes, and will not allow me to send messages using Mac Mail (the message says that the outgoing server was rejected. I cannot edit the outgoing server, and the keychain will not save my passwords (the ports are valid). How can I change the outgoing server to send emails, and how can I avoid having Mail request my passwords every 2 minutes? Verizon, as usual, will not provide support to iMacs.

    Is there an email saved in your drafts or outbox folder?  I suspect that Mail is continually trying to send it, and each time Google is rejecting the email message.
    You can open the message and then delete it from your Outbox folder.  Then try removing all @gmail email addresses from it and seeing whether you can send to the other folks.  I suspect that will work.
    With email, if an SMTP server *can* verify email addresses, sometimes it will and it will refuse to send messages.  If a message has to be relayed across servers, no verification is done, and you'll get a bounce if an email address is bad.

Maybe you are looking for

  • Problem with trial version

    I have downloaded the trial but when I try to open it I get an error and the log is below. What have I done wrong? !SESSION 2007-10-29 02:40:49.722 eclipse.buildId=unknown java.version=1.4.2_12 java.vendor=Sun Microsystems Inc. BootLoader constants:

  • LDAP error 32 no such object   (other LDAP  tool finds the object...)

    While I used a separate LDAP search, I can successfully find a specific uid, with base set to "o=WebAuth" Using the JAAS Authentication sample, I get this error: javax.enterprise.system.stream.out [LDAP Complete Message error code 32 - No Such Object

  • Why can I only see artists that start with the letter "A"?

    On one iPhone, iTunes Match is fine (except that navigation through the iPod app is PAINFULLY slow!!!) On the other iPhone, iTunes Match only shows artists whose names start with the letter A. I've gone through playlist mode and downloaded other stuf

  • Sending variables between swfs

    I'm loading one swf into another and trying to send a variable to the loaded swf. I'm using the code at the bottom to load the swf and send the variable. In the loaded swf I'm using: [Bindable] public var myName:String Then in a function: myName = Ap

  • Being charged a premium for rsd repair prioity

    just took my black macbook for the rsd (finally got fed up). now, the guy at the counter said for it to be looked at I'd have to wait until Sept 19th (one week away) but if I paid a premium (not covered by apple care) I could get it looked at right a