public <T extends Item> T getItem(Class<T> c) {
    for (int i = 0; i < items.length; i++) {
      if (c.isInstance(items[i])) return c.cast(items[i]);
    }

    return null;
  }
  /**
   * Return the first fetch response item of the given class for the given message number.
   *
   * @param r the responses
   * @param msgno the message number
   * @param c the class
   * @param	<T> the type of fetch item
   * @return the fetch item
   */
  public static <T extends Item> T getItem(Response[] r, int msgno, Class<T> c) {
    if (r == null) return null;

    for (int i = 0; i < r.length; i++) {

      if (r[i] == null
          || !(r[i] instanceof FetchResponse)
          || ((FetchResponse) r[i]).getNumber() != msgno) continue;

      FetchResponse f = (FetchResponse) r[i];
      for (int j = 0; j < f.items.length; j++) {
        if (c.isInstance(f.items[j])) return c.cast(f.items[j]);
      }
    }

    return null;
  }
  /**
   * Return all fetch response items of the given class for the given message number.
   *
   * @param r the responses
   * @param msgno the message number
   * @param c the class
   * @param	<T> the type of fetch items
   * @return the list of fetch items
   * @since JavaMail 1.5.2
   */
  public static <T extends Item> List<T> getItems(Response[] r, int msgno, Class<T> c) {
    List<T> items = new ArrayList<T>();

    if (r == null) return items;

    for (int i = 0; i < r.length; i++) {

      if (r[i] == null
          || !(r[i] instanceof FetchResponse)
          || ((FetchResponse) r[i]).getNumber() != msgno) continue;

      FetchResponse f = (FetchResponse) r[i];
      for (int j = 0; j < f.items.length; j++) {
        if (c.isInstance(f.items[j])) items.add(c.cast(f.items[j]));
      }
    }

    return items;
  }