home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / comm / Mail+News / UMS11 / Developer / C / examples / SelectMail.c < prev    next >
C/C++ Source or Header  |  1994-01-23  |  7KB  |  229 lines

  1. /*
  2.  * SelectMail.c (adapted from SelectMail.mod)
  3.  *
  4.  */
  5.  
  6. #include <proto/ums.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. extern struct Library *UMSBase;
  11. UMSUserAccount account;
  12.  
  13. /* get UMS error number and print error text */
  14. void CheckErr(void)
  15. {
  16.  UMSError err;
  17.  
  18.  err=UMSErrNum(account);
  19.  
  20.  /* got an error? */
  21.  if (err != UMSERR_OK)
  22.   {
  23.    fprintf(stderr,"UMS-Error: %3d, '%s'\n",err,UMSErrTxt(account));
  24.    UMSLogout(account);
  25.    exit(20);
  26.   }
  27. }
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31.  char *login,*passwd,*select;
  32.  UMSMsgNum result;
  33.  
  34.  if (argc<3)
  35.   {
  36.    fprintf(stderr,"Usage: %s <login> <passwd> [<select name>]\n",argv[0]);
  37.    exit(0);
  38.   }
  39.  
  40.  /* Read parameters */
  41.  login=argv[1];
  42.  passwd=argv[2];
  43.  if (argc>3)
  44.   select=argv[3]; /* select name is the same as login name */
  45.  else
  46.   select=login;
  47.  
  48.  /* log into UMS system */
  49.  if ((account=UMSLogin(login,passwd))==NULL)
  50.   {
  51.    fprintf(stderr,"Login failed.\n");
  52.    exit(20);
  53.   }
  54.  
  55.  /****************************************************************************
  56.    1. For all messages with
  57.  
  58.        (GlobalFlags & (ViewAccess|PostPoned|Old)) == ViewAccess
  59.  
  60.       set the local flag bit 0.
  61.  
  62.       These are all NEW messages, which can be seen by the user.
  63.  *****************************************************************************/
  64.  
  65.  printf("Looking for new messages: ");
  66.  fflush(stdout);
  67.  result=UMSSelectTags(account,UMSTAG_SelMask,       UMSUSTATF_ViewAccess |
  68.                                                     UMSUSTATF_PostPoned  |
  69.                                                     UMSUSTATF_Old,
  70.                               UMSTAG_SelMatch,      UMSUSTATF_ViewAccess,
  71.  
  72.                               UMSTAG_SelWriteLocal, TRUE,
  73.                               UMSTAG_SelSet,        (1L<<0),
  74.                               UMSTAG_SelUnset,      0,
  75.                               TAG_DONE);
  76.  printf("%d found.\n",result);
  77.  CheckErr();
  78.  
  79.  /****************************************************************************
  80.    2. For all messages with
  81.  
  82.        ToName field == select name
  83.  
  84.       set the local flag bit 1.
  85.  
  86.       These are all messages addressed to the user.
  87.  *****************************************************************************/
  88.  
  89.  printf("selecting by name: ");
  90.  fflush(stdout);
  91.  result=UMSSelectTags(account,UMSTAG_WToName,       select,
  92.  
  93.                               UMSTAG_SelWriteLocal, TRUE,
  94.                               UMSTAG_SelSet,        (1L<<1),
  95.                               UMSTAG_SelUnset,      0,
  96.                               UMSTAG_SelQuick,      TRUE,
  97.                               TAG_DONE);
  98.  printf("%d selected.\n",result);
  99.  CheckErr();
  100.  
  101.  /****************************************************************************
  102.    3. For all messages with
  103.  
  104.        (LocalFlags & (Bit 0 and Bit 1)) == (Bit 0 and Bit 1)
  105.  
  106.       set the local flag bit 4.
  107.  
  108.       This operation builds the intersection set of the operation 1 and 2,
  109.       thus setting the local flag bit 4 in all new messages, which are
  110.       addressed to the user.
  111.  *****************************************************************************/
  112.  
  113.  printf("  new messages amongst these: ");
  114.  fflush(stdout);
  115.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  116.                               UMSTAG_SelMask,       (1L<<0) | (1L<<1),
  117.                               UMSTAG_SelMatch,      (1L<<0) | (1L<<1),
  118.  
  119.                               UMSTAG_SelWriteLocal, TRUE,
  120.                               UMSTAG_SelSet,        (1L<<4),
  121.                               UMSTAG_SelUnset,      0,
  122.                               UMSTAG_SelQuick,      TRUE,
  123.                               TAG_DONE);
  124.  printf("%d selected.\n",result);
  125.  CheckErr();
  126.  
  127.  /****************************************************************************
  128.    4. For all messages with
  129.  
  130.        FromName field == select name
  131.  
  132.       set local flag bit 2.
  133.  
  134.       These are all messages written by the user.
  135.  *****************************************************************************/
  136.  
  137.  printf("looking for messages written by you: ");
  138.  fflush(stdout);
  139.  result=UMSSelectTags(account,UMSTAG_WFromName,     select,
  140.  
  141.                               UMSTAG_SelWriteLocal, TRUE,
  142.                               UMSTAG_SelSet,        (1L<<2),
  143.                               UMSTAG_SelUnset,      0,
  144.                               UMSTAG_SelQuick,      TRUE,
  145.                               TAG_DONE);
  146.  printf("%d found.\n",result);
  147.  CheckErr();
  148.  
  149.  /****************************************************************************
  150.    5. For all messages with a parent message and
  151.  
  152.        (parent's LocalFlags & Bit 2) == Bit 2
  153.  
  154.       set local flag bit 3.
  155.  
  156.       These are all replies to messages written by the user.
  157.  *****************************************************************************/
  158.  
  159.  printf("selecting replies to your msgs: ");
  160.  fflush(stdout);
  161.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  162.                               UMSTAG_SelParent,     TRUE,
  163.                               UMSTAG_SelMask,       (1L<<2),
  164.                               UMSTAG_SelMatch,      (1L<<2),
  165.  
  166.                               UMSTAG_SelWriteLocal, TRUE,
  167.                               UMSTAG_SelSet,        (1L<<3),
  168.                               UMSTAG_SelUnset,      0,
  169.                               UMSTAG_SelQuick,      TRUE,
  170.                               TAG_DONE);
  171.  printf("%d selected.\n",result);
  172.  CheckErr();
  173.  
  174.  /****************************************************************************
  175.    6. For all messages with
  176.  
  177.        (LocalFlags & (Bit 0 and Bit 3)) == (Bit 0 and Bit 3)
  178.  
  179.       set the local flag bit 4.
  180.  
  181.       This operation builds the intersection set of the operation 4 and 5,
  182.       thus setting the local flag bit 4 in all new messages, which are
  183.       replies to messages written by the user.
  184.  *****************************************************************************/
  185.  
  186.  printf("  new messages amongst these: ");
  187.  fflush(stdout);
  188.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  189.                               UMSTAG_SelMask,       (1L<<0) | (1L<<3),
  190.                               UMSTAG_SelMatch,      (1L<<0) | (1L<<3),
  191.  
  192.                               UMSTAG_SelWriteLocal, TRUE,
  193.                               UMSTAG_SelSet,        (1L<<4),
  194.                               UMSTAG_SelUnset,      0,
  195.                               UMSTAG_SelQuick,      TRUE,
  196.                               TAG_DONE);
  197.  printf("%d selected.\n",result);
  198.  CheckErr();
  199.  
  200.  /****************************************************************************
  201.    7. For all messages with
  202.  
  203.        (LocalFlags & Bit 4) == Bit 4
  204.  
  205.       set the selected user flag.
  206.  
  207.       This operation builds the union set of the operation 3 and 6, thus
  208.       setting the selected user flag in all new messages, which are either
  209.       messages addressed to the user or replies to messages written by the
  210.       user.
  211.       The news reader will now show these messages first.
  212.  *****************************************************************************/
  213.  
  214.  printf("totally selected: ");
  215.  fflush(stdout);
  216.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  217.                               UMSTAG_SelMask,       (1L<<4),
  218.                               UMSTAG_SelMatch,      (1L<<4),
  219.  
  220.                               UMSTAG_SelSet,        UMSUSTATF_Selected,
  221.                               UMSTAG_SelUnset,      0,
  222.                               TAG_DONE);
  223.  printf("%d.\n",result);
  224.  CheckErr();
  225.  
  226.  UMSLogout(account);
  227.  return(0);
  228. }
  229.