void nsImapUrl::ParseImapPart()

in mailnews/imap/src/nsImapUrl.cpp [374:593]


void nsImapUrl::ParseImapPart(char* imapPartOfUrl) {
  m_tokenPlaceHolder = imapPartOfUrl;
  m_urlidSubString = m_tokenPlaceHolder ? NS_strtok(IMAP_URL_TOKEN_SEPARATOR,
                                                    &m_tokenPlaceHolder)
                                        : (char*)NULL;

  if (!m_urlidSubString) {
    m_validUrl = false;
    return;
  }

  if (!PL_strcasecmp(m_urlidSubString, "fetch")) {
    m_imapAction = nsImapMsgFetch;
    ParseUidChoice();
    PR_FREEIF(m_sourceCanonicalFolderPathSubString);
    ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    ParseListOfMessageIds();
    // if fetched by spam filter, the action will be changed to
    // nsImapMsgFetchPeek
  } else {
    if (!PL_strcasecmp(m_urlidSubString, "header")) {
      m_imapAction = nsImapMsgHeader;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
    } else if (!PL_strcasecmp(m_urlidSubString, "customFetch")) {
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseCustomMsgFetchAttribute();
    } else if (!PL_strcasecmp(m_urlidSubString, "previewBody")) {
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseNumBytes();
    } else if (!PL_strcasecmp(m_urlidSubString, "deletemsg")) {
      m_imapAction = nsImapDeleteMsg;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
    } else if (!PL_strcasecmp(m_urlidSubString, "uidexpunge")) {
      m_imapAction = nsImapUidExpunge;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
    } else if (!PL_strcasecmp(m_urlidSubString, "deleteallmsgs")) {
      m_imapAction = nsImapDeleteAllMsgs;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "addmsgflags")) {
      m_imapAction = nsImapAddMsgFlags;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseMsgFlags();
    } else if (!PL_strcasecmp(m_urlidSubString, "subtractmsgflags")) {
      m_imapAction = nsImapSubtractMsgFlags;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseMsgFlags();
    } else if (!PL_strcasecmp(m_urlidSubString, "setmsgflags")) {
      m_imapAction = nsImapSetMsgFlags;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseMsgFlags();
    } else if (!PL_strcasecmp(m_urlidSubString, "onlinecopy")) {
      m_imapAction = nsImapOnlineCopy;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "onlinemove")) {
      m_imapAction = nsImapOnlineMove;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "onlinetoofflinecopy")) {
      m_imapAction = nsImapOnlineToOfflineCopy;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "onlinetoofflinemove")) {
      m_imapAction = nsImapOnlineToOfflineMove;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "offlinetoonlinecopy")) {
      m_imapAction = nsImapOfflineToOnlineMove;
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "search")) {
      m_imapAction = nsImapSearch;
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseSearchCriteriaString();
    } else if (!PL_strcasecmp(m_urlidSubString, "test")) {
      m_imapAction = nsImapTest;
    } else if (!PL_strcasecmp(m_urlidSubString, "select")) {
      m_imapAction = nsImapSelectFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      if (m_tokenPlaceHolder && *m_tokenPlaceHolder)
        ParseListOfMessageIds();
      else
        m_listOfMessageIds = PL_strdup("");
    } else if (!PL_strcasecmp(m_urlidSubString, "liteselect")) {
      m_imapAction = nsImapLiteSelectFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "selectnoop")) {
      m_imapAction = nsImapSelectNoopFolder;
      m_listOfMessageIds = PL_strdup("");
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "expunge")) {
      m_imapAction = nsImapExpungeFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      m_listOfMessageIds = PL_strdup("");  // no ids to UNDO
    } else if (!PL_strcasecmp(m_urlidSubString, "create")) {
      m_imapAction = nsImapCreateFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "ensureExists")) {
      m_imapAction = nsImapEnsureExistsFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "discoverchildren")) {
      m_imapAction = nsImapDiscoverChildrenUrl;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "discoverallboxes")) {
      m_imapAction = nsImapDiscoverAllBoxesUrl;
    } else if (!PL_strcasecmp(m_urlidSubString,
                              "discoverallandsubscribedboxes")) {
      m_imapAction = nsImapDiscoverAllAndSubscribedBoxesUrl;
    } else if (!PL_strcasecmp(m_urlidSubString, "delete")) {
      m_imapAction = nsImapDeleteFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "deletefolder")) {
      m_imapAction = nsImapDeleteFolderAndMsgs;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "rename")) {
      m_imapAction = nsImapRenameFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "movefolderhierarchy")) {
      m_imapAction = nsImapMoveFolderHierarchy;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      if (m_tokenPlaceHolder && *m_tokenPlaceHolder)  // handle promote to root
        ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "list")) {
      m_imapAction = nsImapLsubFolders;
      ParseFolderPath(&m_destinationCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "biff")) {
      m_imapAction = nsImapBiff;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
    } else if (!PL_strcasecmp(m_urlidSubString, "netscape")) {
      m_imapAction = nsImapGetMailAccountUrl;
    } else if (!PL_strcasecmp(m_urlidSubString, "appendmsgfromfile")) {
      m_imapAction = nsImapAppendMsgFromFile;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "appenddraftfromfile")) {
      m_imapAction = nsImapAppendDraftFromFile;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseUidChoice();
      if (m_tokenPlaceHolder && *m_tokenPlaceHolder)
        ParseListOfMessageIds();
      else
        m_listOfMessageIds = strdup("");
    } else if (!PL_strcasecmp(m_urlidSubString, "subscribe")) {
      m_imapAction = nsImapSubscribe;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "unsubscribe")) {
      m_imapAction = nsImapUnsubscribe;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "refreshacl")) {
      m_imapAction = nsImapRefreshACL;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "refreshfolderurls")) {
      m_imapAction = nsImapRefreshFolderUrls;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "refreshallacls")) {
      m_imapAction = nsImapRefreshAllACLs;
    } else if (!PL_strcasecmp(m_urlidSubString, "listfolder")) {
      m_imapAction = nsImapListFolder;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "upgradetosubscription")) {
      m_imapAction = nsImapUpgradeToSubscription;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "folderstatus")) {
      m_imapAction = nsImapFolderStatus;
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
    } else if (!PL_strcasecmp(m_urlidSubString, "verifyLogon")) {
      m_imapAction = nsImapVerifylogon;
    } else if (m_imapAction == nsIImapUrl::nsImapUserDefinedMsgCommand) {
      m_command = m_urlidSubString;  // save this
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
    } else if (m_imapAction == nsIImapUrl::nsImapMsgStoreCustomKeywords) {
      ParseUidChoice();
      ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
      ParseListOfMessageIds();
      bool addKeyword = (m_tokenPlaceHolder && *m_tokenPlaceHolder != '>');
      // if we're not adding a keyword, m_tokenPlaceHolder will now look like
      // >keywordToSubtract> and strtok will leave flagsPtr pointing to
      // keywordToSubtract. So detect this case and only set the
      // customSubtractFlags.
      char* flagsPtr = m_tokenPlaceHolder ? NS_strtok(IMAP_URL_TOKEN_SEPARATOR,
                                                      &m_tokenPlaceHolder)
                                          : (char*)nullptr;
      if (addKeyword) {
        m_customAddFlags.Assign(flagsPtr);
        flagsPtr = m_tokenPlaceHolder ? NS_strtok(IMAP_URL_TOKEN_SEPARATOR,
                                                  &m_tokenPlaceHolder)
                                      : (char*)nullptr;
      }
      m_customSubtractFlags.Assign(flagsPtr);
    } else {
      m_validUrl = false;
    }
  }
}