Find number of attachments

How can I find the number of attachments in a message?
I've done some research, but still can't figure it out :(

So far I have found the code below.
Will the "int cnt = mp.getCount();" get the number of attachments in the message?
I haven't tested the code yet, so if someone sees something obvious that can be improved upon please share :)
* A mail message with an attachment is represented in MIME as a multipart message.
* After using getContent() to get the content of a mail message, the attachment will be in the form of a MimeMultipart object.
* To save the data in a body part e.g. an attachment into a file, use the getInputStream method to access the attachment content and copy the data to a FileOutputStream.
public void writeFiles(Message msg) {
     try {
          Object o = msg.getContent();
          if (msg.isMimeType("multipart/mixed")) {
               Multipart mp = (Multipart) o;
               int cnt = mp.getCount();
               for (int i = 0; i < cnt; i++) {
                    Part part = mp.getBodyPart(i);
                    if (!part.isMimeType("text/plain") && !part.isMimeType("text/html") && !part.isMimeType("multipart/*")) {
                         String disp = part.getDisposition();
                         if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) {                              
                              String FileName = part.getFileName();
                              FileOutputStream out = new FileOutputStream(FileName);
                              InputStream is = part.getInputStream();
                              int c;
                              while ((c = is.read()) != -1)
                                   out.write(c);
                              out.flush();
                              out.close();
     } catch (MessagingException mex) {
          //Work with the exception
     } catch (java.io.IOException ioe) {
          //Work with the exception
}

Similar Messages

  • How to count number of attachments in a mailbox?

    Hi everybody,
    I want to count the number of attachments in mailbox. Kindly help me.
    Thanks & regards,
    Talib Hussain

    Hi Talib,
    in Your case i think you will need to combine Get-mailboxfolderstatistic and search-mailbox.
    Is Your goal to only search Your mailbox on the Whole organization?
    If only on Your mailbox you can use Power Query in Excel to filter out only Messages With attachment.
    You could also use built in search folder in Outlook to only list mails With attachment.Again this Works only on Your private mailbox and not for Whole organization.
    Could be some great minds out there that could create a script for Your needs.
    In Our case we used this command to search for all mailboxes with attachment greater than 25mb and export them to pst file (individual pst files)
    $MBX = Get-Mailbox
    $MBX –resultsize unlimited
    | foreach {New-MailboxExportRequest -Mailbox $_.Identity -ContentFilter {Size -gt '25MB'} -FilePath ('\\Server\Share\path\ ‘ + $_.Alias + '(' + $_.DisplayName + ').PST')}
    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

  • Is it possible to limit the number of attachments

    Is is possible to limit the number of attachments that the mail server will receive in a message. For example if the email has 5 or more attachments reject it or through it in the bitbucket.
    The reason I ask is I have a remote site that is sending me 500+ email messages with 40 attachments in each. Well with virus scanning in the conversion channel it really backs things up.
    I have looked in the manual but have not been able to find anything.
    I am running ims5.2 patch 1.15 on HP-UX. Soon it will be patch 1.25 when school is out.
    Thanks,
    Gary

    Since each message is usually in a separate MIMEpart, you could use the conversion channel to do what you're asking, but . . .
    Routing every message through conversion will be a pretty big performance hit.
    How about simply blocking that particular site with an
    ORIG_SEND_ACCESS
    mapping entry in your mappings file?

  • How to find number of lines in an internal table

    Dear all,
    how to find number of records present in an internal table.

    DESCRIBE TABLE
    Syntax
    DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].
    Extras:
    1. ... KIND knd
    2. ... LINES lin
    3. ... OCCURS n
    Effect
    This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.
    In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.
    Notes
    For detailed information about an internal table, you should use the methods of RTTS of the DESCRIBE TABLE statement.
    Without the specification of an addition, the statement DESCRIBE TABLE only sets the system fields sy-tfill and sy-tleng.
    Addition 1
    ... KIND knd
    Effect
    The table type of the internal table itab is determined and a corresponding one-digit identification is assigned to the data object knd. A character-type data type is expected for the data object. The identifications are "T" for standard tables, "S" for sorted tables and "H" for hashed tables. These values are also defined as constants sydes_kind-standard, sydes_kind-sorted, and sydes_kind-hashed in the type group SYDES.
    Addition 2
    ... LINES lin
    Effect
    The current number of table rows of the internal table itab is determined and is assigned to the data object lin.The data type i is expected for the data object.
    Note
    As of release 6.10, the current number of rows of an internal table can also be determined using the in-built function lines.
    Addition 3
    ... OCCURS n
    Effect
    The initial memory requirement defined during the creation of the internal table with the addition INITIAL SIZE or the obsolete addition OCCURS is determined and assigned to the data object n. The data type i is expected for the data object.
    Example
    Descending sorting of a generically typed internal table in a subprogram. Since sorted tables cannot be sorted in a descending order, the table type is checked to avoid an exception that cannot be handled.
    TYPE-POOLS sydes.
    FORM sort_descending CHANGING itab TYPE ANY TABLE.
      DATA tabkind(1) TYPE c.
      DESCRIBE TABLE itab KIND tabkind.
      IF tabkind = sydes_kind-standard OR
         tabkind = sydes_kind-hashed.
        SORT itab DESCENDING.
      ELSEIF tabkind = sydes_kind-sorted.
        MESSAGE '...' TYPE 'E'.
      ELSE.
        MESSAGE '...' TYPE 'E'.
      ENDIF.
    ENDFORM.
    DESCRIBE FIELD INTO
    Note
    This statement is for internal use only.
    It cannot be used in application programs.
    Syntax
    DESCRIBE FIELD dobj INTO td.
    Effect
    All characteristics of the field f, its components , sub-components etc. are displayed in the field td (type description). td has to be of the type SYDES_DESC, defined in Type Group SYDES. Because of this, the type group SYDES must be integrated into the ABAP-program with a TYPE-POOLS statement .
    The structure SYDES_DESC has two table-type components TYPES and NAMES:
    In TYPES, the tree structure of the type belonging to f is displayed. The components of a node are stored in the table TYPES in a continuous manner. Beginning and end of the line area that represents the components are stored in TYPES-FROM and TYPES-TO. The reference to the superior node can be found in TYPES-BACK. If no superior resp. subordinate node exists, then this is marked by the value 0 (For the relevance of further components, refer to the following sections).
    The names of components, types etc. are not stored directly in TYPES. Instead, the components TYPES-IDX_... hold an index in the name table NAMES. The value 0 indicates that there is no reference to the name table.
    NAMES contains the possibly fragmented names in the component NAMES-NAME. If a name continues in the following line, this is indicated by an asterisk ('*') in the component NAMES-CONTINUE.
    The type description table (TYPES) not only stores information about the tree structure but also further information about the type of f resp. its components. This includes especially all information that can be determined using the usual additions to DESCRIBE FIELD. In detail, TYPES contains the following columns:
    IDX_NAME
    Component Name
    IDX_USER_TYPE
    Name of a user-defined type, i.e., a type that was defined through its TYPES-statement. Derived types (... TYPE A-B) and structures from the ABAP-Dictionary are not considered to be user-defined types.
    CONTEXT
    For user-defined types only: The context, in which the type is defined. Possible values are defined in the constant SYDES_CONTEXT of the type group SYDES. Please only use these constants to carry out a comparison. In detail, we distinguish between the following type contexts:
    SYDES_CONTEXT-PROGRAM: Program-global type
    SYDES_CONTEXT-FORM   : FORM-local type
    SYDES_CONTEXT-FUNCTION: FUNCTION-local type
    SYDES_CONTEXT-METHOD : METHOD-local type
    IDX_CONTEXT_NAME
    For user-defined types only:
    With a local context: The name of the FORM or FUNCTION, whose type was defined. The name of the associated program is then the first entry in the name table.
    With a global context: The name of the program in which the type was defined.
    IDX_EDIT_MASK
    Conversion routine from the ABAP-Dictionary, is in accordance with the addition EDIT MASK at simple DESCRIBE.
    IDX_HELP_ID
    Help-Id when referencing to fields from the ABAP-Dictionary
    LENGTH
    Internal length, corresponds to the addition LENGTH at simple DESCRIBE
    OUTPUT_LENGTH
    Output length, corresponds to the addition OUTPUT-LENGTH at simple DESCRIBE
    DECIMALS
    Number of decimal digits, corresponds to the addition DECIMALS at simple DESCRIBE
    TYPE
    ABAP-Type, corresponds to the addition TYPE at simple DESCRIBE
    TABLE_KIND
    A table type is stored here for the components which represent an internal table. The same values are returned as with the variant DESCRIBE TABLE itab KIND k. Components which do not represent a table get the return value set to SYDES_KIND-UNDEFINED (see type group SYDES).
    Example
    Example definition of the complex data type EMPLOYEE_STRUC:
    PROGRAM DESCTEST.
    TYPES: BEGIN OF name_struc,
             first  TYPE c LENGTH 20,
             last   TYPE c LENGTH 20,
           END OF name_struc,
           BEGIN OF absence_time_struc,
             day        TYPE d,
             from       TYPE t,
             to         TYPE t,
           END OF absence_time_struc,
           phone_number TYPE n LENGTH 20,
           BEGIN OF employee_struc,
             id         LIKE sbook-customid,
             name       TYPE name_struc,
             BEGIN OF address,
               street  TYPE c LENGTH 30,
               zipcode TYPE n LENGTH 4,
               place   TYPE c LENGTH 30,
             END OF address,
             salary_per_month TYPE p LENGTH 10 DECIMALS 3,
             absent           TYPE STANDARD TABLE OF absence_time_struc
                                   WITH NON-UNIQUE DEFAULT KEY,
             phone            TYPE STANDARD TABLE OF phone_number
                                   WITH NON-UNIQUE DEFAULT KEY,
           END OF employee_struc.
    You can determine the structure of the type EMPLOYEE_STRUC by collecting the type group SYDES as follows:
    TYPE-POOLS: sydes.
    DATA: employee TYPE employee_struc,
          td       TYPE sydes_desc.
    DESCRIBE FIELD employee INTO td.
    The following table shows a few selected columns of the type description table TD-TYPES. For a better overview, the names of the columns IDX_NAME, IDX_UERR_TYPE and IDX_EDIT_MASK have been shortened:
        |FROM| TO |BACK|NAME|UTYP|EMSK|TYPE
    |--||||||--
      1 |  2 |  7 |  0 |  0 |  2 |  0 |  v
      2 |  0 |  0 |  1 |  6 |  0 |  4 |  N
      3 |  8 |  9 |  1 |  7 |  5 |  0 |  u
      4 | 10 | 12 |  1 |  8 |  0 |  0 |  u
      5 |  0 |  0 |  1 |  9 |  0 |  0 |  P
      6 | 13 | 13 |  1 | 11 |  0 |  0 |  h
      7 | 17 | 17 |  1 | 12 |  0 |  0 |  h
      8 |  0 |  0 |  3 | 13 |  0 |  0 |  C
      9 |  0 |  0 |  3 | 14 |  0 |  0 |  C
    10 |  0 |  0 |  4 | 15 |  0 |  0 |  C
    11 |  0 |  0 |  4 | 16 |  0 |  0 |  N
    12 |  0 |  0 |  4 | 17 |  0 |  0 |  C
    13 | 14 | 16 |  6 |  0 | 18 |  0 |  u
    14 |  0 |  0 | 13 | 20 |  0 |  0 |  D
    15 |  0 |  0 | 13 | 21 |  0 |  0 |  T
    16 |  0 |  0 | 13 | 22 |  0 |  0 |  T
    17 |  0 |  0 |  7 |  0 |  0 |  0 |  N
    Please note that the entries in rows 6 and 7 represent internal tables (ABAP-Type h). There is always an entry for the corresponding row type (rows 13 and 17) to an internal table.
    The indices in the rows 5 to 7 refer to entries in the name table TD-NAMES. If you look, e.g., at row 3, you find the corresponding component name in TD-NAMES from row 7 (NAME) onward and the corresponding user type from row 5 (NAME_STRUC) onward.
    In the name table TD-NAMES you find the following entries. Note that the names SALARY_PER_MONTH and ABSENCE_TIME_STRUC are stored in two parts:
        |CONTINUE|NAME                   |CONTINUE|NAME
    |--|     -||--
      1 |        |DESCTEST            12 |        |PHONE
      2 |        |EMPLOYEE_STRUC      13 |        |FIRST
      3 |        |SBOOK-CUSTOMID      14 |        |LAST
      4 |        |==ALPHA             15 |        |STREET
      5 |        |NAME_STRUC          16 |        |ZIPCODE
      6 |        |ID                  17 |        |PLACE
      7 |        |NAME                18 |   *    |ABSENCE_TIME_ST
      8 |        |ADDRESS             19 |        |RUC
      9 |   *    |SALARY_PER_MONT     20 |        |DAY
    10 |        |H                   21 |        |FROM
    11 |        |ABSENT              22 |        |TO

  • How to find number of files in a folder using pl/sql

    please someone guide as to how to find number of files in a folder using pl/sql
    Regards

    The Java option works well.
    -- results table that will contain a file list result
    create global temporary table directory_list
            directory       varchar2(1000),
            filename        varchar2(1000)
    on commit preserve rows
    -- allowing public access to this temp table
    grant select, update, insert, delete on directory_list to public;
    create or replace public synonym directory_list for directory_list;
    -- creating the java proc that does the file listing
    create or replace and compile java source named "ListFiles" as
    import java.io.*;
    import java.sql.*;
    public class ListFiles
            public static void getList(String directory, String filter)
            throws SQLException
                    File path = new File( directory );
                    final String ExpressionFilter =  filter;
                    FilenameFilter fileFilter = new FilenameFilter() {
                            public boolean accept(File dir, String name) {
                                    if(name.equalsIgnoreCase(ExpressionFilter))
                                            return true;
                                    if(name.matches("." + ExpressionFilter))
                                            return true;
                                    return false;
                    String[] list = path.list(fileFilter);
                    String element;
                    for(int i = 0; i < list.length; i++)
                            element = list;
    #sql {
    insert
    into directory_list
    ( directory, filename )
    values
    ( :directory, :element )
    -- creating the PL/SQL wrapper for the java proc
    create or replace procedure ListFiles( cDirectory in varchar2, cFilter in varchar2 )
    as language java
    name 'ListFiles.getList( java.lang.String, java.lang.String )';
    -- punching a hole in the Java VM that allows access to the server's file
    -- systems from inside the Oracle JVM (these also allows executing command
    -- line and external programs)
    -- NOTE: this hole MUST be secured using proper Oracle security (e.g. AUTHID
    -- DEFINER PL/SQL code that is trusted)
    declare
    SCHEMA varchar2(30) := USER;
    begin
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.io.FilePermission',
    '<<ALL FILES>>',
    'execute, read, write, delete'
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.lang.RuntimePermission',
    'writeFileDescriptor',
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.lang.RuntimePermission',
    'readFileDescriptor',
    commit;
    end;
    To use:
    SQL> exec ListFiles('/tmp', '*.log' );
    PL/SQL procedure successfully completed.
    SQL> select * from directory_list;
    DIRECTORY FILENAME
    /tmp X11_newfonts.log
    /tmp ipv6agt.crashlog
    /tmp dtappint.log
    /tmp Core.sd-log
    /tmp core_intg.sd-log
    /tmp da.sd-log
    /tmp dhcpclient.log
    /tmp oracle8.sd-log
    /tmp cc.sd-log
    /tmp oms.log
    /tmp OmniBack.sd-log
    /tmp DPISInstall.sd-log
    12 rows selected.
    SQL>

  • How to force user to upload specific number of attachments?

    I have a form where users select checkboxes to attach a document.  I need to script that will compare the number of checkboxs selected with the number of attachments, and pop up an error message if these aren't the same.
    Suggestions?
    Thanks!

    Hi,
    Maybe something along the lines of;
    var selectedCheckboxesCount = Subform1.resolveNodes('#field.[ui.oneOfChild.className == "checkButton" and $ == 1]').length;
    var attachmentCount = event.target.dataObjects == null ? 0 : event.target.dataObjects.length;
    if (selectedCheckboxesCount != attachmentCount)
    app.alert("Something is missing")
    Line 1 assumes all your checkboxes are in a subform called Subform1 and that they have the default value for true (which is 1), you may need to change these two things.
    Regards
    Bruce

  • How to create Dynamic number of attachments in BPM Process ?

    Hi All,
    I have a requirement to create a dynamic number of attachments, as per need. I am aware of attachment.create() but i believe with this i can only create only the fixed number of attachments. Is there any way by which i can play around with create() api or is there any other API to fullfill the requirement??
    Any response is well appreciated.
    Regards,

    Hi,
    You can create the n-items in the region by creating items in the controller. i mena to see say by looping..
    Thanks,
    Kumar

  • Number of attachments not showing up in Sent mail list

    Since I migrated mail from my MacBook Pro running Leopard to my shiny new MacBook Pro running Lion (I used Migration Assistant), when I look at my Sent Mail box I don't see the number of attachments listed (I'm using the Classic mail format).  I can see emails previous to my migration showing the number of attachments in the Sent mailbox.  When I look at View Columns, Attachment is checked. I've executed the View Rebuild command on the Sent folder.  References to attachment (the paper clip) doesn't appear in the newer Lion mode either.  I also did a Disk Utility rebuild permissions command and the number of attachments still don't show up.  I do see the number of attachments noted in the InBox.  Maybe someone has some insight on this problem?

    really nobody else has ever heard of this issue?

  • Find number of occurances of a particular character

    Hi,
    is there any keyword to determine number of times a particular character is present in the string,
    E.g. VAR1 = 'ghghj#ghjgjgh#ghjghjg#ghjg#'.
    I want to find number of occurances of # in VAR1.
    Regards,
    Raghavendra

    Hi,
           use folowing logic.
           data:begin 0f itab,
                    var1 type c,
                     var2 type c,
                     var3 type c,
                      var4 type c,
                  end of itab.
      split var1 at '#' into itab-var1 itab-var2 itab-var3 itab-var4.
        if not itab-var1 is initial.
            count = count + 1.
        endif.
           if not itab-var2is initial.
            count = count + 1.
        endif.
        if not itab-var3is initial.
            count = count + 1.
        endif.
        if not itab-var4is initial.
            count = count + 1.
        endif.
    write count.
    regards
    amole

  • I can open all emails ok but can't find or open attachments.

    I can open all emails ok but can't find or open attachments.
    The attachment bar at the bottom of incoming emails has no ''paperclip'' to select and open attached documents

    If the menu bar is hidden then press the F10 key or hold down the Alt key, that should make the menu bar appear.
    * Go to "View > Toolbars" and check-mark "Menu Bar" with a click if you want to make that permanent
    See [[Menu bar is missing]]
    Make sure that all the toolbars like the "Navigation Toolbar" and the "Bookmarks Toolbar" are visible: "View > Toolbars"
    * If items are missing then open the Customize window via "View > Toolbars > Customize" or via "Firefox > Options > Toolbar Layout"
    * If a missing item is in the toolbar palette then drag it back from the Customize window on the toolbar
    * If you do not see an item on a toolbar and in the toolbar palette then click the "Restore Default Set" button to restore the default toolbar set up.
    See also:
    * http://kb.mozillazine.org/Toolbar_customization
    * [[Back and forward or other toolbar buttons are missing]]

  • Maximum number of attachments for an e-mail

    Could anyone tell me what is the maximum number of attachments can be included in an e-mail? or size limit? Does the limitation imposed by mail server?
    Many thanks.

    The server might declare the maximum message size it accepts using the SMTP SIZE extension.
    You can query for the value using:
    ((SMTPTransport)transport).getExtensionParameter("SIZE")
    That's the total size of a message. Note that not all servers will return this information, even
    though they might enforce a limit.
    Computing the actual size of a message can be expensive.
    The simplest approach is something like this:
    CountingOutputStream cos = new CountingOutputStream();
    msg.writeTo(new CRLFOutputStream(cos));
    int size = cos.getSize();
    CRLFOutputStream is in the JavaMail download bundle in the demo directory.
    You have to write CountingOutputStream by subclassing OutputStream and counting the
    number of bytes written without doing anything with them.

  • Function module for finding number of records in table

    Do we have any function module to find number of records in a table?
    Thanks,
    Shweta

    use the EM_GET_NUMBER_OF_ENTRIES. You just have to write your table name into the input table IT_TABLES in the TABNAME field

  • How to build a wsdl which can cater dynamically to number of attachments

    We have a WebService client that calls a Webservice on the Server.
    When the client calls the webservice , it passes the SOAP message(Header,Body & MIME attachments)and these attachments vary in number based on different business requirements.
    We know how to build WSDL for server with static number of attachments,but no clue on how to build a wsdl which can cater dynamically to number of attachments comming from client request.
    - thanks in advance

    Hello,
    We may have multiple approaches here depending of :
    - which version of the product you are using
    - what are your clients in term of stack, and API they are willing to use
    - which encoding did you use for your WS (swa, swaRef or dime)
    So for my answer I am documenting how to do it on OracleAS 10gR3 (10.1.3), using swaRef approach.
    The easiest way is to exchange array of binary data and describle that in the WSDL, so in my case the WSDL element that is used will look like that:
    <element name="filesResponseElement">
    <complexType>
    <sequence>
    <element name="result" type="ns1:swaRef" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    </element>
    This will generate from the Java code an array of AttachmentPart[].
    Regards
    Tugdual Grall

  • Count the number of attachments

    Hello how do I count the number of attachments in a pdf file?

    solved
    // Decalre some variables
    var myDoc = event.target;
    // Get the attachments
    if(myDoc.dataObjects!=null){
            app.alert("yes");
    else{
        app.alert("no");

  • Find Number of Users Currently Logged on to a SharePoint 2013 on premise server?

    Hello,
    We would like to know which current users are logged in our SharePoint farm.
    Is there a simple powershell script which we can run? or enable a feature
    Thanks,
    Dennis

    SharePoint is a web technology, which means it is connectionless by design.  So there really isn't such a thing as the number of users being logged on being tracked by the server.  The closest you can come is to have the server report how many
    active sessions haven't timed out yet.  Not quite the same thing since some of the sessions will be people who stopped using the system during the last half hour or so who's sessions haven't expired yet.  But its the closest you can come. Here's
    a deeper explanation and one potential solution.
    http://blog.furuknap.net/find-number-of-users-currently-logged-on-to-a-sharepoint-site
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

Maybe you are looking for

  • Problem booting Solaris 10 on ProLiant server after installation.

    Hi all! I have a brand new HP ProLiant DL360 G5 server. It contains 6 internal hard drives. RAID 5 is configured on these drives using built-in HP Smart Array P400i controller. I've just installed Solaris 10 8/07 on this server. Solaris requires a dr

  • Link between Acrobat 3D and Flash (Macromedia) objects?

    Since Adobe acquired Macromedia(*) will we see a convergence of some sort between the Acrobat 3D capabilities and the ones already in Flash, for example the capabiliy to manipulate 3D objects interactively in Flash content? Thanks! * http://www.adobe

  • Custom Date Selection

    Hi, Can the behaviour of date selection using af:selectInputDate or af:chooseDate be changed? We want the user to use af:selectInputDate (or af:chooseDate) to select a date from a list of dates. Dates that are not in the provided list should be disab

  • Popup check box screen for fields selection using user structure

    Hi all, could you please help how can i get the popup screen in the program when the user wants to choose the wanted fields. for ex: in the table after clicking the contents display the selection fields will be displayed. there in setting -> list for

  • Downloads say FF4 is there, but FF screen says I need to download it

    I've got a macbook and have downloaded FF4 - it says it is saved in my downloads, but my firefox icon at bottom of screen only brings up previous FFversion which keeps telling me about the new one i.e. 4. I am very untechnical, so if I need to do any