home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / imap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  18.4 KB  |  481 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. #ifndef __imap__
  19. #define __imap__
  20.  
  21. #include "structs.h"
  22. #include "msgcom.h"
  23.  
  24.  
  25. /* used for communication between libmsg and libnet */
  26. #define kNoFlags     0x00    /* RFC flags */
  27. #define kMarked      0x01
  28. #define kUnmarked    0x02
  29. #define kNoinferiors 0x04
  30. #define kNoselect    0x08
  31. #define kImapTrash   0x10    /* Navigator flag */
  32. #define kJustExpunged 0x20    /* This update is a post expunge url update. */
  33. #define kPersonalMailbox    0x40    /* this mailbox is in the personal namespace */
  34. #define kPublicMailbox        0x80    /* this mailbox is in the public namespace */
  35. #define kOtherUsersMailbox    0x100    /* this mailbox is in the other users' namespace */
  36.  
  37. /* flags for individual messages */
  38. /* currently the ui only offers \Seen and \Flagged */
  39. #define kNoImapMsgFlag            0x0000
  40. #define kImapMsgSeenFlag        0x0001
  41. #define kImapMsgAnsweredFlag    0x0002
  42. #define kImapMsgFlaggedFlag        0x0004
  43. #define kImapMsgDeletedFlag        0x0008
  44. #define kImapMsgDraftFlag        0x0010
  45. #define kImapMsgRecentFlag        0x0020
  46. #define    kImapMsgForwardedFlag    0x0040        /* Not always supported, check mailbox folder */
  47. #define kImapMsgMDNSentFlag        0x0080        /* Not always supported. check mailbox folder */
  48.  
  49. #define kImapMsgSupportUserFlag 0x8000        /* This seems to be the most cost effective way of
  50.                                              * piggying back the server support user flag
  51.                                              * info.
  52.                                              */
  53.  
  54. typedef enum {
  55.     kPersonalNamespace = 0,
  56.     kOtherUsersNamespace,
  57.     kPublicNamespace,
  58.     kDefaultNamespace,
  59.     kUnknownNamespace
  60. } EIMAPNamespaceType;
  61.  
  62.  
  63. typedef int32 imap_uid;
  64.  
  65. #ifdef XP_CPLUSPLUS
  66. class TImapFlagAndUidState;
  67. #else
  68. typedef struct TImapFlagAndUidState TImapFlagAndUidState;
  69. #endif
  70.  
  71. /* forward declaration */
  72. typedef void ImapActiveEntry;
  73.  
  74. /* url used to signify that filtering is complete so
  75.    we can tell the fe that the inbox thread pane is 
  76.    loaded */
  77. #define kImapFilteringCompleteURL "Mailbox://?filteringcomplete"
  78.  
  79. /* url used to signify that online/offline synch is complete */
  80. #define kImapOnOffSynchCompleteURL "Mailbox://?onoffsynchcomplete"
  81.  
  82. /* if a url creator does not know the hierarchySeparator, use this */
  83. #define kOnlineHierarchySeparatorUnknown ' '
  84.  
  85. struct mailbox_spec {
  86.     int32               folder_UIDVALIDITY;
  87.     int32            number_of_messages;
  88.     int32               number_of_unseen_messages;
  89.     int32            number_of_recent_messages;
  90.     
  91.     uint32            box_flags;
  92.     
  93.     char          *allocatedPathName;
  94.     char            hierarchySeparator;
  95.     const char        *hostName;
  96.     
  97.     TNavigatorImapConnection *connection;
  98.     TImapFlagAndUidState     *flagState;
  99.     
  100.     XP_Bool            folderSelected;
  101.     XP_Bool            discoveredFromLsub;
  102.  
  103.     const char        *smtpPostAddress;
  104. };
  105.  
  106. typedef struct mailbox_spec mailbox_spec;
  107.  
  108.  
  109. enum EIMAPSubscriptionUpgradeState {
  110.     kEverythingDone,
  111.     kBringUpSubscribeUI
  112. };
  113.  
  114. enum ImapOnlineCopyState {
  115.     kInProgress,
  116.     kSuccessfulCopy,
  117.     kFailedCopy,
  118.     kSuccessfulDelete,
  119.     kFailedDelete,
  120.     kReadyForAppendData,
  121.     kFailedAppend
  122. };
  123.  
  124. struct folder_rename_struct {
  125.     char         *fOldName;
  126.     char        *fNewName;
  127. };
  128.  
  129.  
  130. typedef struct folder_rename_struct folder_rename_struct;
  131.  
  132.  
  133. /* this file defines the syntax of the imap4 url's and offers functions
  134.    that create url strings.  If the functions do not offer enough 
  135.    functionality then let kevin know before you starting creating strings
  136.    from scratch. */
  137. #include "xp_mcom.h"
  138.  
  139. XP_BEGIN_PROTOS
  140.  
  141. /* need mailbox status urls to get the number of message and the
  142.   number of unread messages */
  143.  
  144. /* Selecting a mailbox */
  145. /* imap4://HOST?select?MAILBOXPATH */
  146. char *CreateImapMailboxSelectUrl(const char *imapHost, 
  147.                                  const char *mailbox,
  148.                                  char  hierarchySeparator,
  149.                                  const char *undoDeleteIdentifierList);
  150.  
  151. /* lite select, used to verify UIDVALIDITY while going on/offline */
  152. char *CreateImapMailboxLITESelectUrl(const char *imapHost, 
  153.                                      const char *mailbox,
  154.                                      char  hierarchySeparator);
  155.  
  156. /* expunge, used in traditional imap delete model */
  157. char *CreateImapMailboxExpungeUrl(const char *imapHost, 
  158.                                      const char *mailbox,
  159.                                      char  hierarchySeparator);
  160.  
  161. /* Creating a mailbox */
  162. /* imap4://HOST?create?MAILBOXPATH */
  163. char *CreateImapMailboxCreateUrl(const char *imapHost, const char *mailbox, char  hierarchySeparator);
  164.  
  165. /* discover the children of this mailbox */
  166. char *CreateImapChildDiscoveryUrl(const char *imapHost, const char *mailbox, char  hierarchySeparator);
  167.  
  168. /* discover the n-th level children of this mailbox */
  169. char *CreateImapLevelChildDiscoveryUrl(const char *imapHost, const char *mailbox, char  hierarchySeparator, int n);
  170.  
  171. /* discover the mailboxes of this account  */
  172. char *CreateImapAllMailboxDiscoveryUrl(const char *imapHost);
  173.  
  174. /* discover the mailboxes of this account, and the subscribed mailboxes  */
  175. char *CreateImapAllAndSubscribedMailboxDiscoveryUrl(const char *imapHost);
  176.  
  177. /* deleting a mailbox */
  178. /* imap4://HOST?delete?MAILBOXPATH */
  179. char *CreateImapMailboxDeleteUrl(const char *imapHost, const char *mailbox, char  hierarchySeparator);
  180.  
  181. /* renaming a mailbox */
  182. /* imap4://HOST?rename?OLDNAME?NEWNAME */
  183. char *CreateImapMailboxRenameLeafUrl(const char *imapHost, 
  184.                                      const char *oldBoxPathName,
  185.                                      char  hierarchySeparator,
  186.                                      const char *newBoxLeafName);
  187.  
  188. /* renaming a mailbox, moving hierarchy */
  189. /* imap4://HOST?movefolderhierarchy?OLDNAME?NEWNAME */
  190. /* oldBoxPathName is the old name of the child folder */
  191. /* destinationBoxPathName is the name of the new parent */
  192. char *CreateImapMailboxMoveFolderHierarchyUrl(const char *imapHost, 
  193.                                               const char *oldBoxPathName,
  194.                                               char  oldHierarchySeparator,
  195.                                               const char *destinationBoxPathName,
  196.                                               char  newHierarchySeparator);
  197.  
  198. /* listing available mailboxes */
  199. /* imap4://HOST?list */
  200. char *CreateImapListUrl(const char *imapHost,
  201.                         const char *mailbox,
  202.                         const char hierarchySeparator);
  203.  
  204. /* biff */
  205. char *CreateImapBiffUrl(const char *imapHost,
  206.                         const char *mailbox,
  207.                         char  hierarchySeparator,
  208.                         uint32 uidHighWater);
  209.  
  210.  
  211.  
  212. /* fetching RFC822 messages */
  213. /* imap4://HOST?fetch?<UID/SEQUENCE>?MAILBOXPATH?x */
  214. /*   'x' is the message UID or sequence number list */
  215. /* will set the 'SEEN' flag */
  216. char *CreateImapMessageFetchUrl(const char *imapHost,
  217.                                 const char *mailbox,
  218.                                 char  hierarchySeparator,
  219.                                 const char *messageIdentifierList,
  220.                                 XP_Bool messageIdsAreUID);
  221.                                 
  222.                                 
  223. /* fetching the headers of RFC822 messages */
  224. /* imap4://HOST?header?<UID/SEQUENCE>?MAILBOXPATH?x */
  225. /*   'x' is the message UID or sequence number list */
  226. /* will not affect the 'SEEN' flag */
  227. char *CreateImapMessageHeaderUrl(const char *imapHost,
  228.                                  const char *mailbox,
  229.                                  char  hierarchySeparator,
  230.                                  const char *messageIdentifierList,
  231.                                  XP_Bool messageIdsAreUID);
  232.                                  
  233.  
  234. /* search an online mailbox */
  235. /* imap4://HOST?search?<UID/SEQUENCE>?MAILBOXPATH?SEARCHSTRING */
  236. char *CreateImapSearchUrl(const char *imapHost,
  237.                           const char *mailbox,
  238.                           char  hierarchySeparator,
  239.                           const char *searchString,
  240.                           XP_Bool messageIdsAreUID);
  241.  
  242. /* delete messages */
  243. /* imap4://HOST?deletemsg?<UID/SEQUENCE>?MAILBOXPATH?x */
  244. /*   'x' is the message UID or sequence number list */
  245. char *CreateImapDeleteMessageUrl(const char *imapHost,
  246.                                  const char *mailbox,
  247.                                  char  hierarchySeparator,
  248.                                  const char *messageIds,
  249.                                  XP_Bool idsAreUids);
  250.                                  
  251. /* delete all messages */
  252. /* imap4://HOST?deleteallmsgs?MAILBOXPATH */
  253. char *CreateImapDeleteAllMessagesUrl(const char *imapHost,
  254.                                      const char *mailbox,
  255.                                      char  hierarchySeparator);
  256.  
  257. /* store +flags url */
  258. /* imap4://HOST?store+flags?<UID/SEQUENCE>?MAILBOXPATH?x?f */
  259. /*   'x' is the message UID or sequence number list */
  260. /*   'f' is the byte of flags */
  261. char *CreateImapAddMessageFlagsUrl(const char *imapHost,
  262.                                    const char *mailbox,
  263.                                    char  hierarchySeparator,
  264.                                    const char *messageIds,
  265.                                    imapMessageFlagsType flags,
  266.                                    XP_Bool idsAreUids);
  267. /* store -flags url */
  268. /* imap4://HOST?store-flags?<UID/SEQUENCE>?MAILBOXPATH?x?f */
  269. /*   'x' is the message UID or sequence number list */
  270. /*   'f' is the byte of flags */
  271. char *CreateImapSubtractMessageFlagsUrl(const char *imapHost,
  272.                                         const char *mailbox,
  273.                                            char  hierarchySeparator,
  274.                                         const char *messageIds,
  275.                                         imapMessageFlagsType flags,
  276.                                         XP_Bool idsAreUids);
  277.  
  278. /* set flags url, make the flags match */
  279. char *CreateImapSetMessageFlagsUrl(const char *imapHost,
  280.                                         const char *mailbox,
  281.                                            char  hierarchySeparator,
  282.                                         const char *messageIds,
  283.                                         imapMessageFlagsType flags,
  284.                                         XP_Bool idsAreUids);
  285.  
  286.  
  287. /* copy messages from one online box to another */
  288. /* imap4://HOST?onlineCopy?<UID/SEQUENCE>?
  289.          SOURCEMAILBOXPATH?x?DESTINATIONMAILBOXPATH */
  290. /*   'x' is the message UID or sequence number list */
  291. char *CreateImapOnlineCopyUrl(const char *imapHost,
  292.                               const char *sourceMailbox,
  293.                               char  sourceHierarchySeparator,
  294.                               const char *messageIds,
  295.                               const char *destinationMailbox,
  296.                               char  destinationHierarchySeparator,
  297.                               XP_Bool idsAreUids,
  298.                               XP_Bool isMove);    /* cause delete after copy */
  299.  
  300. /* copy a message from an online box to an offline box */
  301. /* imap4://HOST?ontooffCopy?SOURCEMAILBOXPATH?number=x?
  302.          DESTINATIONMAILBOXPATH */
  303. /*   'x' is the message sequence number */
  304. char *CreateImapOnToOfflineCopyUrl( const char *imapHost,
  305.                                       const char *sourceMailbox,
  306.                                       char  sourceHierarchySeparator,
  307.                                       const char *messageIds,
  308.                                       const char *destinationMailbox,
  309.                                       XP_Bool idsAreUids,
  310.                                       XP_Bool isMove);    /* cause delete after copy */
  311.  
  312. /* copy messages from an offline box to an online box */
  313. /* imap4://HOST?offtoonCopy?DESTINATIONMAILBOXPATH */
  314. /*   the number of messages and their sizes are negotiated later */
  315. char *CreateImapOffToOnlineCopyUrl(const char *imapHost,
  316.                                    const char *destinationMailbox,
  317.                                      char  destinationHierarchySeparator);
  318.  
  319. /* Subscribe to a mailbox on the given IMAP host */
  320. char *CreateIMAPSubscribeMailboxURL(const char *imapHost, const char *mailboxName);
  321.  
  322. /* Unsubscribe from a mailbox on the given IMAP host */
  323. char *CreateIMAPUnsubscribeMailboxURL(const char *imapHost, const char *mailboxName);
  324.  
  325. /* get mail account rul */
  326. /* imap4://HOST?NETSCAPE */
  327. char *CreateImapManageMailAccountUrl(const char *imapHost);
  328.  
  329. /* append message from file */
  330. /* imap4://HOST?appendmsgfromfile?MSGFILEPATH?DESTINATIONMAILBOXPATH */
  331. char *CreateImapAppendMessageFromFileUrl(const char *imapHost,
  332.                                          const char *destinationMailboxPath,
  333.                                          const char hierarchySeparator,
  334.                                          XP_Bool isDraft);
  335.  
  336. /* refresh the ACL for a folder */
  337. char *CreateIMAPRefreshACLForFolderURL(const char *imapHost, const char *mailbox);
  338.  
  339. /* refresh the ACL for all folders on given host*/
  340. char *CreateIMAPRefreshACLForAllFoldersURL(const char *imapHost);
  341.  
  342. /* Run the auto-upgrade to IMAP Subscription */
  343. char *CreateIMAPUpgradeToSubscriptionURL(const char *imapHost, XP_Bool subscribeToAll);
  344.  
  345. NET_StreamClass *CreateIMAPDownloadMessageStream(ImapActiveEntry *ce, uint32 msgSize);
  346.  
  347. void UpdateIMAPMailboxInfo(mailbox_spec *adoptedBoxSpec, MWContext *currentContext);
  348.  
  349. #define kUidUnknown -1
  350. int32 GetUIDValidityForSpecifiedImapFolder(const char *hostName, const char *canonicalimapName, MWContext *currentContext);
  351.  
  352. enum EMailboxDiscoverStatus {
  353.         eContinue,
  354.         eContinueNew,
  355.         eListMyChildren,
  356.         eNewServerDirectory,
  357.         eCancelled };
  358.  
  359. enum EMailboxDiscoverStatus DiscoverIMAPMailbox(mailbox_spec *adoptedBoxSpec, MSG_Master *master, MWContext *currentContext);
  360.  
  361. void ReportSuccessOfOnlineCopy(MWContext *currentContext, enum ImapOnlineCopyState copyState);
  362. void ReportSuccessOfOnlineDelete(MWContext *currentContext, const char *mailboxName);
  363. void ReportFailureOfOnlineCreate(MWContext *currentContext, const char *mailboxName);
  364. void ReportSuccessOfOnlineRename(MWContext *currentContext, folder_rename_struct *names);
  365. void ReportMailboxDiscoveryDone(MWContext *currentContext, URL_Struct *URL_s);
  366. void ReportSuccessOfChildMailboxDiscovery(MWContext *currentContext);
  367. void NotifyHeaderFetchCompleted(MWContext *currentContext, TNavigatorImapConnection *imapConnection);
  368.  
  369. void ReportLiteSelectUIDVALIDITY(MSG_Pane *receivingPane, uint32 UIDVALIDITY);
  370.  
  371. typedef void (UploadCompleteFunctionPointer)(void*);
  372. void BeginMessageUpload(MWContext *currentContext, 
  373.                         PRFileDesc *ioSocket,
  374.                         UploadCompleteFunctionPointer *completeFunction, 
  375.                         void *completionFunctionArgument);
  376.  
  377. void IMAP_DoNotDownLoadAnyMessageHeadersForMailboxSelect(TNavigatorImapConnection *connection);
  378. void IMAP_DownLoadMessagesForMailboxSelect(TNavigatorImapConnection *connection,
  379.                                            uint32 *messageKeys,    /* uint32* is adopted */
  380.                                            uint32 numberOfKeys);
  381.                                            
  382. void IMAP_DownLoadMessageBodieForMailboxSelect(TNavigatorImapConnection *connection,
  383.                                                uint32 *messageKeys,    /* uint32* is adopted */
  384.                                                uint32 numberOfKeys);
  385.  
  386. void IMAP_BodyIdMonitor(TNavigatorImapConnection *connection, XP_Bool enter);
  387.  
  388. const char *IMAP_GetCurrentConnectionUrl(TNavigatorImapConnection *connection);
  389.  
  390. void IMAP_UploadAppendMessageSize(TNavigatorImapConnection *connection, uint32 msgSize, imapMessageFlagsType flags);
  391. void IMAP_ResetAnyCachedConnectionInfo();
  392.  
  393. XP_Bool IMAP_CheckNewMail(TNavigatorImapConnection *connection);
  394. XP_Bool IMAP_NewMailDetected(TNavigatorImapConnection *connection);
  395.  
  396. TImapFlagAndUidState *IMAP_CreateFlagState(int numberOfMessages);
  397. void                  IMAP_DeleteFlagState(TImapFlagAndUidState *state);
  398. int                   IMAP_GetFlagStateNumberOfMessages(TImapFlagAndUidState *state);
  399.     
  400. imap_uid              IMAP_GetUidOfMessage(int zeroBasedIndex, TImapFlagAndUidState *state);
  401. imapMessageFlagsType IMAP_GetMessageFlags(int zeroBasedIndex, TImapFlagAndUidState *state);
  402. imapMessageFlagsType IMAP_GetMessageFlagsFromUID(imap_uid uid, XP_Bool *foundIt, TImapFlagAndUidState *state);
  403.  
  404. void                 IMAP_TerminateConnection (TNavigatorImapConnection *connection);
  405.  
  406. char                *IMAP_CreateOnlineSourceFolderNameFromUrl(const char *url);
  407.  
  408. void                 IMAP_FreeBoxSpec(mailbox_spec *victim);
  409.  
  410. const char            *IMAP_GetPassword();
  411. void                 IMAP_SetPassword(const char *password);
  412.  
  413. /* called once only by MSG_InitMsgLib */
  414. void                 IMAP_StartupImap();
  415.  
  416. /* called once only by MSG_ShutdownMsgLib */
  417. void                 IMAP_ShutdownImap();
  418.  
  419. /* used to prevent recursive listing of mailboxes during discovery */
  420. int64 IMAP_GetTimeStampOfNonPipelinedList();
  421.  
  422. /* returns TRUE if either we have a password or we were preAuth'd by SSL certs */
  423. XP_Bool IMAP_HaveWeBeenAuthenticated();
  424.  
  425. /* used by libmsg when creating an imap message display stream */
  426. int IMAP_InitializeImapFeData (ImapActiveEntry * ce);
  427. MSG_Pane *IMAP_GetActiveEntryPane(ImapActiveEntry * ce);
  428. NET_StreamClass *IMAP_CreateDisplayStream(ImapActiveEntry * ce, XP_Bool clearCacheBit, uint32 msgSize);
  429.  
  430. /* used by libmsg when a new message is loaded to interrupt the load of the previous message */
  431. void                IMAP_PseudoInterruptFetch(MWContext *context);
  432.  
  433. void IMAP_URLFinished(URL_Struct *URL_s);
  434.  
  435. XP_Bool IMAP_HostHasACLCapability(const char *hostName);
  436.  
  437. /**** IMAP Host stuff - used for communication between MSG_IMAPHost (in libmsg) and TImapHostInfo (in libnet) ****/
  438.  
  439. /* obsolete? */
  440. /*void    IMAP_SetNamespacesFromPrefs(const char *hostName, char *personalDir, char *publicDir, char *otherUsersDir);*/
  441.  
  442. /* Sets the preference of whether or not we should always explicitly LIST the INBOX for given host */
  443. void    IMAP_SetShouldAlwaysListInboxForHost(const char *hostName, XP_Bool shouldList);
  444.  
  445. /* Gets the number of namespaces in use for a given host */
  446. int        IMAP_GetNumberOfNamespacesForHost(const char *hostName);
  447.  
  448. /* Sets the currently-used default personal namespace for a given host.  Used for updating from libnet when
  449.    we get a NAMESPACE response. */
  450. void MSG_SetNamespacePrefixes(MSG_Master *master, const char *hostName, EIMAPNamespaceType type, const char *prefix);
  451.  
  452.  
  453. /* Check to see if we need upgrade to IMAP subscription */
  454. extern XP_Bool    MSG_ShouldUpgradeToIMAPSubscription(MSG_Master *mast);
  455. extern void        MSG_ReportSuccessOfUpgradeToIMAPSubscription(MWContext *context, enum EIMAPSubscriptionUpgradeState *state);
  456.  
  457. /* Adds a set of ACL rights for the given folder on the given host for the given user.  If userName is NULL, it means
  458.    the currently authenticated user (i.e. my rights). */
  459. extern void MSG_AddFolderRightsForUser(MSG_Master *master, const char *hostName, const char*mailboxName, const char *userName, const char *rights);
  460.  
  461. /* Clears all ACL rights for the given folder on the given host for all users. */
  462. extern void MSG_ClearFolderRightsForFolder(MSG_Master *master, const char *hostName, const char *mailboxName);
  463.  
  464. /* Refreshes the icon / flags for a given folder, based on new ACL rights */
  465. extern void MSG_RefreshFolderRightsViewForFolder(MSG_Master *master, const char *hostName, const char *mailboxName);
  466.  
  467. extern XP_Bool MSG_GetFolderNeedsSubscribing(MSG_FolderInfo *folder);
  468.  
  469. /* Returns TRUE if this folder needs an auto-refresh of the ACL (on a folder open, for example) */
  470. extern XP_Bool MSG_GetFolderNeedsACLListed(MSG_FolderInfo *folder);
  471.  
  472. /* Returns TRUE if this folder has NEVER (ever) had an ACL retrieved for it */
  473. extern XP_Bool MSG_IsFolderACLInitialized(MSG_Master *master, const char *folderName, const char *hostName);
  474.  
  475. extern char *IMAP_SerializeNamespaces(char **prefixes, int len);
  476. extern int IMAP_UnserializeNamespaces(const char *str, char **prefixes, int len);
  477.  
  478. XP_END_PROTOS
  479.  
  480. #endif
  481.