예제 #1
0
 public static Address getEmailAddress(String paramString) {
   while (true) {
     try {
       boolean bool = TextUtils.isEmpty(paramString);
       Address localAddress;
       if (bool) {
         localAddress = null;
         return localAddress;
       }
       Rfc822Token[] arrayOfRfc822Token = Rfc822Tokenizer.tokenize(paramString);
       if (arrayOfRfc822Token.length <= 0) break label116;
       String str3 = arrayOfRfc822Token[0].getName();
       if (str3 != null) {
         str1 = Html.fromHtml(str3.trim()).toString();
         localObject2 = Html.fromHtml(arrayOfRfc822Token[0].getAddress()).toString();
         localAddress = new Address(str1, (String) localObject2);
         continue;
       }
     } finally {
     }
     String str1 = "";
     continue;
     label116:
     do {
       String str2 = Html.fromHtml(paramString).toString();
       localObject2 = str2;
       break;
       str1 = "";
     } while (paramString != null);
     Object localObject2 = "";
   }
 }
예제 #2
0
 void inviteBuddies() {
   Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mAddressList.getText());
   try {
     IImConnection conn = mApp.getConnection(mProviderId);
     IContactList list = getContactList(conn);
     if (list == null) {
       Log.e(
           ImApp.LOG_TAG,
           "<AddContactActivity> can't find given contact list:" + getSelectedListName());
       finish();
     } else {
       boolean fail = false;
       for (Rfc822Token recipient : recipients) {
         String username = recipient.getAddress();
         if (mDefaultDomain != null && username.indexOf('@') == -1) {
           username = username + "@" + mDefaultDomain;
         }
         if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
           log("addContact:" + username);
         }
         int res = list.addContact(username);
         if (res != ImErrorInfo.NO_ERROR) {
           fail = true;
           mHandler.showAlert(
               R.string.error, ErrorResUtils.getErrorRes(getResources(), res, username));
         }
       }
       // close the screen if there's no error.
       if (!fail) {
         finish();
       }
     }
   } catch (RemoteException ex) {
     Log.e(ImApp.LOG_TAG, "<AddContactActivity> inviteBuddies: caught " + ex);
   }
 }
  /**
   * Get a HashMap of address to RecipientEntry that contains all contact information for a contact
   * with the provided address, if one exists. This may block the UI, so run it in an async task.
   *
   * @param context Context.
   * @param inAddresses Array of addresses on which to perform the lookup.
   * @param callback RecipientMatchCallback called when a match or matches are found.
   */
  public static void getMatchingRecipients(
      Context context,
      BaseRecipientAdapter adapter,
      ArrayList<String> inAddresses,
      int addressType,
      Account account,
      RecipientMatchCallback callback) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
      query = Queries.EMAIL;
    } else {
      query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    HashSet<String> addresses = new HashSet<String>();
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
      Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
      addresses.add(tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
      bindString.append("?");
      if (i < addressesSize - 1) {
        bindString.append(",");
      }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    String[] addressArray = new String[addresses.size()];
    addresses.toArray(addressArray);
    HashMap<String, RecipientEntry> recipientEntries = null;
    Cursor c = null;

    try {
      c =
          context
              .getContentResolver()
              .query(
                  query.getContentUri(),
                  query.getProjection(),
                  query.getProjection()[Queries.Query.DESTINATION]
                      + " IN ("
                      + bindString.toString()
                      + ")",
                  addressArray,
                  null);
      recipientEntries = processContactEntries(c, null /* directoryId */);
      callback.matchesFound(recipientEntries);
    } finally {
      if (c != null) {
        c.close();
      }
    }
    //
    final Set<String> matchesNotFound = new HashSet<String>();

    getMatchingRecipientsFromDirectoryQueries(
        context, recipientEntries, addresses, account, matchesNotFound, query, callback);

    getMatchingRecipientsFromExtensionMatcher(adapter, matchesNotFound, callback);
  }
  /**
   * Get a HashMap of address to RecipientEntry that contains all contact information for a contact
   * with the provided address, if one exists. This may block the UI, so run it in an async task.
   *
   * @param context Context.
   * @param inAddresses Array of addresses on which to perform the lookup.
   * @return HashMap<String,RecipientEntry>
   */
  public static HashMap<String, RecipientEntry> getMatchingRecipients(
      Context context, ArrayList<String> inAddresses, int addressType) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
      query = Queries.EMAIL;
    } else {
      query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    String[] addresses = new String[addressesSize];
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
      Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
      addresses[i] = (tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
      bindString.append("?");
      if (i < addressesSize - 1) {
        bindString.append(",");
      }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
    Cursor c =
        context
            .getContentResolver()
            .query(
                query.getContentUri(),
                query.getProjection(),
                query.getProjection()[Queries.Query.DESTINATION]
                    + " IN ("
                    + bindString.toString()
                    + ")",
                addresses,
                null);

    if (c != null) {
      try {
        if (c.moveToFirst()) {
          do {
            String address = c.getString(Queries.Query.DESTINATION);
            recipientEntries.put(
                address,
                RecipientEntry.constructTopLevelEntry(
                    c.getString(Queries.Query.NAME),
                    c.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
                    c.getString(Queries.Query.DESTINATION),
                    c.getInt(Queries.Query.DESTINATION_TYPE),
                    c.getString(Queries.Query.DESTINATION_LABEL),
                    c.getLong(Queries.Query.CONTACT_ID),
                    c.getLong(Queries.Query.DATA_ID),
                    c.getString(Queries.Query.PHOTO_THUMBNAIL_URI)));
            if (Log.isLoggable(TAG, Log.DEBUG)) {
              Log.d(
                  TAG,
                  "Received reverse look up information for "
                      + address
                      + " RESULTS: "
                      + " NAME : "
                      + c.getString(Queries.Query.NAME)
                      + " CONTACT ID : "
                      + c.getLong(Queries.Query.CONTACT_ID)
                      + " ADDRESS :"
                      + c.getString(Queries.Query.DESTINATION));
            }
          } while (c.moveToNext());
        }
      } finally {
        c.close();
      }
    }
    return recipientEntries;
  }
  /**
   * Try to parse the hdrPart string as e-mail headers.
   *
   * @param hdrPart The string to parse.
   * @return Null if the entire string were e-mail headers. The part of the string in which no
   *     headers were found.
   */
  private String parseMmsHeaders(String hdrPart) {
    String[] headers = hdrPart.split("\r\n");
    String header;
    hasHeaders = false;

    for (int i = 0, c = headers.length; i < c; i++) {
      header = headers[i];

      /* We need to figure out if any headers are present, in cases where devices do not follow the e-mail RFCs.
       * Skip empty lines, and then parse headers until a non-header line is found, at which point we treat the
       * remaining as plain text.
       */
      if (header.trim() == "") continue;
      String[] headerParts = header.split(":", 2);
      if (headerParts.length != 2) {
        // We treat the remaining content as plain text.
        StringBuilder remaining = new StringBuilder();
        for (; i < c; i++) remaining.append(headers[i]);

        return remaining.toString();
      }

      String headerType = headerParts[0].toUpperCase();
      String headerValue = headerParts[1].trim();

      // Address headers
      /* TODO: If this is empty, the MSE needs to fill it in before sending the message.
       * This happens when sending the MMS, not sure what happens for e-mail.
       */
      if (headerType.contains("FROM")) {
        Rfc822Token tokens[] = Rfc822Tokenizer.tokenize(headerValue);
        from = new ArrayList<Rfc822Token>(Arrays.asList(tokens));
      } else if (headerType.contains("TO")) {
        Rfc822Token tokens[] = Rfc822Tokenizer.tokenize(headerValue);
        to = new ArrayList<Rfc822Token>(Arrays.asList(tokens));
      } else if (headerType.contains("CC")) {
        Rfc822Token tokens[] = Rfc822Tokenizer.tokenize(headerValue);
        cc = new ArrayList<Rfc822Token>(Arrays.asList(tokens));
      } else if (headerType.contains("BCC")) {
        Rfc822Token tokens[] = Rfc822Tokenizer.tokenize(headerValue);
        bcc = new ArrayList<Rfc822Token>(Arrays.asList(tokens));
      } else if (headerType.contains("REPLY-TO")) {
        Rfc822Token tokens[] = Rfc822Tokenizer.tokenize(headerValue);
        replyTo = new ArrayList<Rfc822Token>(Arrays.asList(tokens));
      } // Other headers
      else if (headerType.contains("SUBJECT")) {
        subject = headerValue;
      } else if (headerType.contains("MESSAGE-ID")) {
        messageId = headerValue;
      } else if (headerType.contains("DATE")) {
        /* TODO: Do we need the date? */
      } else if (headerType.contains("CONTENT-TYPE")) {
        String[] contentTypeParts = headerValue.split(";");
        contentType = contentTypeParts[0];
        // Extract the boundary if it exists
        for (int j = 1, n = contentTypeParts.length; j < n; j++) {
          if (contentTypeParts[j].contains("boundary")) {
            boundary = contentTypeParts[j].split("boundary[\\s]*=", 2)[1].trim();
          }
        }
      } else if (headerType.contains("CONTENT-TRANSFER-ENCODING")) {
        encoding = headerValue;
      } else {
        if (D) Log.w(TAG, "Skipping unknown header: " + headerType + " (" + header + ")");
      }
    }
    return null;
  }
  /**
   * Get a HashMap of address to RecipientEntry that contains all contact information for a contact
   * with the provided address, if one exists. This may block the UI, so run it in an async task.
   *
   * @param context Context.
   * @param inAddresses Array of addresses on which to perform the lookup.
   * @param callback RecipientMatchCallback called when a match or matches are found.
   * @return HashMap<String,RecipientEntry>
   */
  public static void getMatchingRecipients(
      Context context,
      ArrayList<String> inAddresses,
      int addressType,
      Account account,
      RecipientMatchCallback callback) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
      query = Queries.EMAIL;
    } else {
      query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    HashSet<String> addresses = new HashSet<String>();
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
      Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
      addresses.add(tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
      bindString.append("?");
      if (i < addressesSize - 1) {
        bindString.append(",");
      }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    String[] addressArray = new String[addresses.size()];
    addresses.toArray(addressArray);
    HashMap<String, RecipientEntry> recipientEntries = null;
    Cursor c = null;

    try {
      c =
          context
              .getContentResolver()
              .query(
                  query.getContentUri(),
                  query.getProjection(),
                  query.getProjection()[Queries.Query.DESTINATION]
                      + " IN ("
                      + bindString.toString()
                      + ")",
                  addressArray,
                  null);
      recipientEntries = processContactEntries(c);
      callback.matchesFound(recipientEntries);
    } finally {
      if (c != null) {
        c.close();
      }
    }
    // See if any entries did not resolve; if so, we need to check other
    // directories
    final Set<String> matchesNotFound = new HashSet<String>();
    if (recipientEntries.size() < addresses.size()) {
      final List<DirectorySearchParams> paramsList;
      Cursor directoryCursor = null;
      try {
        directoryCursor =
            context
                .getContentResolver()
                .query(DirectoryListQuery.URI, DirectoryListQuery.PROJECTION, null, null, null);
        paramsList = BaseRecipientAdapter.setupOtherDirectories(context, directoryCursor, account);
      } finally {
        if (directoryCursor != null) {
          directoryCursor.close();
        }
      }
      // Run a directory query for each unmatched recipient.
      HashSet<String> unresolvedAddresses = new HashSet<String>();
      for (String address : addresses) {
        if (!recipientEntries.containsKey(address)) {
          unresolvedAddresses.add(address);
        }
      }

      matchesNotFound.addAll(unresolvedAddresses);

      Cursor directoryContactsCursor = null;
      for (String unresolvedAddress : unresolvedAddresses) {
        for (int i = 0; i < paramsList.size(); i++) {
          try {
            directoryContactsCursor =
                doQuery(
                    unresolvedAddress,
                    1,
                    paramsList.get(i).directoryId,
                    account,
                    context.getContentResolver(),
                    query);
          } finally {
            if (directoryContactsCursor != null && directoryContactsCursor.getCount() == 0) {
              directoryContactsCursor.close();
              directoryContactsCursor = null;
            } else {
              break;
            }
          }
        }
        if (directoryContactsCursor != null) {
          try {
            final Map<String, RecipientEntry> entries =
                processContactEntries(directoryContactsCursor);

            for (final String address : entries.keySet()) {
              matchesNotFound.remove(address);
            }

            callback.matchesFound(entries);
          } finally {
            directoryContactsCursor.close();
          }
        }
      }
    }

    callback.matchesNotFound(matchesNotFound);
  }