code: public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
          DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null,
                  namespace);
          Form extendedInfo = Form.getFormFrom(info);
          if (extendedInfo != null) {
              String value = extendedInfo.getField("number_of_messages").getFirstValue();
              return Integer.parseInt(value);
          }
          return 0;
      }
docs: Returns the number of offline messages for the user of the connection.
  
  @return the number of offline messages for the user of the connection.
  @throws XMPPErrorException If the user is not allowed to make this request or the server does
  not support offline message retrieval.
  @throws NoResponseException if there was no response from the server.
  @throws NotConnectedException
  @throws InterruptedException