home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lm2pmm.zip / lm_migr.cmd next >
OS/2 REXX Batch file  |  1997-11-05  |  28KB  |  780 lines

  1. /*
  2. program: lm_migr.cmd  
  3. type:    REXXSAA-OS/2, Object Rexx, REXXSAA 6.x
  4. purpose: utilities for dealing with LaMail files
  5. version: 1.0
  6. date:    1997-02-10
  7. changed: 1997-11-05, ---rgf, determining whether PM-Mail is running, aborts if so
  8.  
  9. author:  Rony G. Flatscher
  10.          Rony.Flatscher@wu-wien.ac.at
  11.  
  12. needs:   lmrxtool, pmmrxtoo
  13.  
  14. usage:   "lm_migr"
  15.  
  16. All rights reserved, copyrighted 1997, no guarantee that it works without
  17. errors, etc. etc.
  18.  
  19. donated to the public domain granted that you are not charging anything (money
  20. etc.) for it and derivates based upon it, as you did not write it,
  21. etc. if that holds you may bundle it with commercial programs too
  22.  
  23. you may freely distribute this program, granted that no changes are made
  24. to it
  25.  
  26. Please, if you find an error, post me a message describing it, I will
  27. try to fix and rerelease it to the net.
  28. */
  29.  
  30.  
  31. .local ~ work.NewRootFolder = "LaMail.FLD"      
  32. .local ~ work.DateTime = DATE( "S" ) TIME()
  33.  
  34.  
  35.         /* main menu    */
  36. SAY "LaMail e-mail --> PM-Mail 1.9 migration tool"
  37. SAY
  38. SAY
  39. SAY "HINT: for newly created PM-Mail folders the settings of the present"
  40. SAY "      PM Mail 'Inbox' folder will be used as a template; therefore"
  41. SAY "      set the 'Inbox' folder properties the way you want the migrated"
  42. SAY "      folders to be set to (e.g. sort fields, sorting order, read mail"
  43. SAY "      indicator, ...)."
  44. SAY
  45. SAY "ATTENTION !"
  46. SAY
  47. SAY "PM-Mail MUST NOT be running, otherwise unpredictable *ERRORs* occur !!"
  48. SAY
  49. IF bisPMMailActive() THEN
  50. DO
  51.    SAY
  52.    SAY "[PM-Mail is running, please close it and re-start migration.]"
  53.    EXIT -1
  54. END
  55. "@PAUSE"
  56.  
  57. SAY
  58. SAY "LaMail e-mail --> PM-Mail 1.9 migration tool"
  59. SAY
  60. SAY
  61. SAY "LaMail related information:"
  62. SAY
  63. SAY " - INI-file:        " pp( .lam.IniPath  )
  64. SAY " - NickName file:   " pp( .lam.Nickname )
  65. SAY " - Signature file:  " pp( .lam.Signature )
  66. SAY " - folder directory:" pp( .lam.Folders )
  67. SAY " - inbox directory: " pp( .lam.Inbox ) 
  68. SAY
  69.  
  70. SAY "PM-Mail 1.9 related information:"
  71. SAY
  72. SAY " - toolPath:        " pp( .pmm.ToolPath )
  73. SAY " - MailPath:        " pp( .pmm.MailPath )
  74. SAY
  75. SAY
  76. SAY RIGHT( "(1)" , 10 ) "Migrate LaMail e-mail"
  77. SAY RIGHT( "(2)" , 10 ) "Delete  LaMail e-mail (final step of migration)"
  78. SAY
  79. CALL CHAROUT , "Enter choice: 1-2 or 0, 'q' to quit: "
  80.  
  81. answer = get_answer( "Q", 2, "F" )
  82. SAY; SAY
  83.  
  84.                 /* delete LaMail e-mails in LaMail folders      */
  85. IF answer = 2 THEN  
  86. DO
  87.    CALL Beep 2500, 250; CALL Beep 2500, 250; CALL Beep 2500, 250
  88.    SAY "Hint: deleting affects all subfolders too !"
  89.    SAY "      (should have been migrated in step # 1)"
  90.    
  91.    answer = "N"
  92.    answer  = get_choice( answer, "Do you really want to delete LaMail e-mail in the (old) LaMail folders ? (y/N)" )
  93.    IF answer = "N" THEN CALL abort
  94.    
  95.    answer = "Y"
  96.    answer  = get_choice( answer, "Should empty (old) LaMail-subdirectories be removed ? (Y/n)" )
  97.    bRemoveDirs = ( answer = "Y" )
  98.  
  99.    answer  = "P"
  100.    answer  = get_choice( answer, "Decide which (old) LaMail e-mail folders to delete ? (a/P/s/q)",,
  101.                             "Choose: a(ll folders), P(rompt for), s(kip), q(uit)", "APSQ" )
  102.  
  103.    bTmpSkip = ( answer <> "A" )
  104.    
  105.    IF answer = "A" | answer = "P" THEN
  106.    DO
  107.       SAY 
  108.       SAY "Deleting (old) LaMail e-mail folders ..."
  109.       SAY
  110.       
  111.       DO item OVER .lam.FolderList              /* get a directory      */
  112.    
  113.          IF bTmpSkip THEN
  114.          DO
  115.             answer = "N"                        
  116.             answer  = get_choice( answer, "Delete folder" pp( item ) "? (y/N/g/s/q)",,
  117.                                   "Choose: y(es), g(o ahead, migrate all left), N(o), s(kip all), q(uit)", "YNGSQ" )
  118.    
  119.             IF answer = "N" THEN ITERATE        /* not this one, maybe the next ?       */
  120.             ELSE IF answer = "S" THEN LEAVE     /* skip all             */
  121.    
  122.             bTmpSkip = ( answer = "Y" )         /* continue to ask ?    */
  123.          END
  124.    
  125.          CALL Delete_Dirs item, bRemoveDirs     /* copy, rename LaMail e-mail           */
  126.       END
  127.    END
  128.  
  129.                      /* delete LaMail-Inbox ?        */
  130.    CALL Beep 2500, 250
  131.    SAY
  132.    SAY "ATTENTION: If you defined the LaMail-Inbox directory" pp( .lam.inbox )
  133.    SAY "           as your SMTPPATH in PM-View, then you might not want to delete the"
  134.    SAY "           LaMail-Inbox ! This is because e-mail sent thru sendmail.exe"
  135.    SAY "           is stored in this path, if set up thru OS/2's TCP/IP configuration."
  136.    SAY 
  137.    SAY "           (With other words, you receive your e-mail via SMTP and have OS/2"
  138.    SAY "           place it first into LaMail's InBox-directory from which PM-Mail"
  139.    SAY "           will fetch the e-mail on its next fetch/read-cycle.)"
  140.    SAY 
  141.    SAY "Warning:   If you delete the e-mails in such a case, then you mostlikely"
  142.    SAY "           loose any new mail sent directly via SMTP to you !!"
  143.    SAY 
  144.    "@PAUSE"
  145.  
  146.    answer = "N"
  147.    answer  = get_choice( answer, "Delete LaMail InBox-folder" pp( .lam.inbox, ) "? (y/N)" )
  148.  
  149.    IF answer = "Y" THEN                      /* no, finished            */
  150.       CALL Delete_Dirs .lam.inbox, .false    /* copy, rename LaMail e-mail           */
  151.  
  152.  
  153.    SAY
  154.    CALL LINEOUT STDERR, "Migration LaMail ---> PM-Mail 1.9:" 
  155.    CALL LINEOUT STDERR, "" 
  156.    .logError ~ dump                /* dump any errors that occurred (from LMRXTOOL.CMD)    */
  157.    
  158.    
  159.    SAY
  160.    SAY
  161.    SAY "Deleting (old) LaMail e-mail finished."
  162.    SAY
  163.    SAY "Good luck, that everything worked out ! ;-)"
  164.    SAY "---rgf"
  165.    
  166.    EXIT
  167. END
  168.  
  169.  
  170.                 /* Migrate LaMail e-mail ...    */
  171.  
  172. SAY "Migrate LaMail e-mail ..."
  173. answer = "Y"                        /* default to yes       */
  174. answer  = get_choice( answer, "Allow for skipping migration steps (interactive migration) ? (Y/n/q)",,
  175.                       "Choose: Y(es), n(o, do entire migration automatically), q(uit)", "YNQ" )
  176.  
  177. bSkip = ( answer = "Y" )                /* allow for skipping steps ?           */
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.         /* migrating LaMail e-mails     */
  186.  
  187.         /* pmmrxtoo     */
  188.         /* let user choose account to copy E-Mail-stuff to      */
  189.  
  190. SAY "Choose the PM-Mail account to which to attach the LaMail E-Mails:"
  191. SAY
  192. i = 0
  193. choice. = ""
  194. DO item OVER .accounts ~ ObjectColl
  195.    i = i + 1
  196.    choice.i = item 
  197.    tmpDir = item ~ objectData 
  198.    SAY RIGHT( "(" || i || ")", 10 ) pp( tmpDir ~ acctdiskname ) pp( tmpDir ~ acctname ) 
  199. END 
  200. choice.0 = i                            /* save nr of items in stem             */
  201.  
  202. SAY
  203. CALL CHAROUT , "Enter choice: 1-" || i "or 0, 'q' to quit: "
  204.  
  205. IF .accounts ~ ObjectColl ~ items = 1 THEN      /* only one account, then use it        */
  206. DO
  207.    answer = 1                                   /* choose single account        */
  208.    SAY answer "(using only account by default)" /* display feedback             */
  209. END
  210. ELSE
  211.    answer = get_answer( "Q", i, "Force" )       /* ask user which account to use        */
  212.  
  213. SAY; SAY
  214. IF answer = "Q" THEN CALL abort
  215.  
  216. .local ~ work.AcctObj  = choice.answer    /* save object representing the target account  */
  217.  
  218. .local ~ work.AcctPath = .work.AcctObj ~ objectData ~ full_path       /* save account-path    */
  219. .local ~ work.Acct.DiskName = .work.AcctObj ~ objectData ~ AcctDiskName
  220.  
  221.  
  222.  
  223.  
  224.  
  225.         /* read files, determine respective maximum Numbers     */
  226.  
  227. /* .accounts, .addr, .assoc, .books are read in PMMRXTOO.CMD already    */
  228. .local ~ work.maxNumbers = .directory ~ new
  229. .work.maxNumbers ~ setentry( "BOOKS", .books ~ maxNumber )
  230.  
  231. inFolderObj = .folder.ini ~ newFromFile /* use PM-Mail's Inbox settings as a template   */
  232. .work.maxNumbers ~ setentry( "FOLDERS", .folder.ini ~ maxNumber )
  233.  
  234.  
  235.                 /* create stub for FOLDER.INIs according to PM-Mails Inbox folder (#1)  */
  236.                 /* determine value for icon, assume that unread mail is present now     */
  237. IF inFolderObj ~ ObjectData ~ indicate_Unread_Mail THEN 
  238.    inFolderObj ~ ObjectData ~ folder_icon = 2           /* green folder */
  239. ELSE IF inFolderObj ~ ObjectData ~ indicate_AnyMail THEN
  240.    inFolderObj ~ ObjectData ~ folder_icon = 1           /* red folder   */
  241. ELSE
  242.    inFolderObj ~ ObjectData ~ folder_icon = 0           /* yellow folder*/
  243.  
  244. inFolderObj ~ ObjectData ~ user_defined = 1     /* indicate that not a system FOLDER.INI        */
  245.  
  246.                 /* remove name and number from ini-folder-string*/
  247. PARSE VALUE ( inFolderObj ~ makestring ) WITH . ( .pmm.deli ) . ( .pmm.deli ) rest
  248.  
  249. .local ~ work.folder.template = rest            /* save in .local environment   */
  250.                                                 
  251.  
  252.  
  253.  
  254.  
  255.         /* does LaMail folder to be created exist already ?     */
  256.  
  257. bCreate = .true
  258. tmpTargetFolder = .work.AcctPath || "\" || .work.NewRootFolder
  259. CALL SysFileTree tmpTargetFolder, "files.", "DO"
  260.  
  261. IF files.0 > 0 THEN                     /* oops LaMail exists already, ask user */
  262. DO
  263.    CALL BEEP 2000, 250
  264.    SAY
  265.    SAY "Problem: Default Target folder exists already !"
  266.    SAY "       " pp( tmpTargetFolder )
  267.    SAY
  268.    SAY "Choices: c(reate new one), u(se existing one), q(uit)"
  269.    SAY 
  270.    CALL CHAROUT , "Enter your choice: "
  271.    answer = get_answer( "CUQ", "", "F" )
  272.    SAY; SAY
  273.  
  274.  
  275.    IF answer = "Q" THEN CALL abort
  276.    ELSE IF answer = "U" THEN bCreate = .false   /* don't attempt to create      */
  277.    ELSE IF answer = "C" THEN            /* get name for a new folder    */
  278.    DO
  279.       tmpTargetFolder = SysTempFileName( .work.AcctPath || "\" || "LaMail??.FLD" )
  280.       IF tmpTargetFolder = "" THEN
  281.       DO
  282.          SAY "It is not possible to create a unique LaMail folder."
  283.          CALL abort
  284.       END
  285.    END
  286. END
  287.  
  288.  
  289. IF bCreate THEN                         /* create subdirectory                  */
  290. DO
  291.    IF SysMkDir( tmpTargetFolder ) <> 0 THEN
  292.    DO
  293.       SAY "Could not create target directory:" pp( tmpTargetFolder )
  294.       CALL abort
  295.    END
  296. END
  297.  
  298. .local ~ work.TargetPath = tmpTargetFolder      /* save target dir              */
  299.  
  300.  
  301.  
  302.  
  303. /* copy e-mails                 */
  304.         /* copy signature  - file       */
  305.                 /* build target name    */
  306.  
  307. answer = "Y"                                     /* default to Yes               */
  308. IF bSkip THEN
  309.    answer  = get_choice( answer, "Migrate LaMail signature file ? (Y/n)" )
  310.  
  311. IF answer = "Y" THEN
  312. DO
  313.    SAY
  314.    SAY "Copying LaMail's signature file ..."
  315.    
  316.    bCreate = .true                         /* copy LaMail signature file   */
  317.    
  318.    acctSigPath = .work.acctPath || "\SIGS"
  319.    signFileName = FILESPEC( "N", .lam.Signature )
  320.    tmpTarget = acctSigPath || "\" || signFileName
  321.    IF STREAM( tmpTarget, "C", "QUERY EXISTS" ) <> "" THEN  /* it exists !  */
  322.    DO
  323.       CALL BEEP 2000, 250
  324.       SAY
  325.       SAY "Problem: LaMail signature file exists already !"
  326.       SAY "       " pp( tmpTarget )
  327.       SAY
  328.       SAY "Choices: c(reate new file), s(kip this step), q(uit)"
  329.       SAY 
  330.       CALL CHAROUT , "Enter your choice: "
  331.       answer = get_answer( "CSQ", "", "F" )
  332.       SAY; SAY
  333.    
  334.       IF answer = "Q" THEN CALL abort
  335.       ELSE IF answer = "C" THEN            /* get name for a new folder    */
  336.       DO
  337.          tmpTarget = SysTempFileName( acctSigPath || "\SIG_LM??.TXT" )
  338.          IF tmpTarget = "" THEN
  339.          DO
  340.             SAY "It is not possible to create a unique signature name in" pp( acctSigPath )
  341.             CALL abort
  342.          END
  343.       END
  344.       ELSE IF answer = "S" THEN bCreate = .false   /* don't attempt to create      */
  345.    END
  346.    
  347.    
  348.    IF bCreate THEN
  349.    DO
  350.       ADDRESS CMD "copy" .lam.Signature tmpTarget
  351.       IF RC <> 0 THEN
  352.       DO
  353.          SAY "Copying" pp( .lam.Singature ) "to" pp( tmpTarget ) "failed!"
  354.          CALL abort
  355.       END
  356.  
  357.                       /* add entry to signature list          */
  358.       .sigs ~ newFromFile( .work.acctPath )          /* read all signatures          */
  359.  
  360.       tmpDir = .directory ~ new                       /* set-up a signature object    */
  361.       tmpDir ~~ setentry( "NAME", "LaMail signature") ~~ setentry( "IS_DEFAULT", 0 )
  362.       tmpDir ~~ setentry( "PATH_TO_FILE", .work.Acct.DiskName || "\SIGS\" || FILESPEC( "N", tmpTarget ) )
  363.       .sigs ~~ new( tmpDir ) ~ sortedReplace    /* create new signature-object, sort and replace signature file */
  364.    END
  365. END
  366.  
  367.  
  368.  
  369.  
  370. answer = "Y"                                    /* default to Yes               */
  371. IF bSkip THEN
  372.    answer  = get_choice( answer, "Migrate LaMail e-mail files ? (Y/n)" )
  373.  
  374. IF answer = "Y" THEN
  375. DO
  376.    /* note: copying returns a list of the new folder-names *with* appended backslash !!    */
  377.    
  378.            /* copy all LaMail folders to target    */
  379.  
  380.    answer = "A"                                    /* default to Yes               */
  381.    IF bSkip THEN
  382.       answer  = get_choice( answer, "Which LaMail e-mail folders to migrate ? (A/p/s/q)",,
  383.                             "Choose: A(ll folders), p(rompt for), s(kip), q(uit)", "APSQ" )
  384.  
  385.    IF answer = "A" | answer = "P" THEN
  386.    DO
  387.       SAY 
  388.       SAY "Copying LaMail e-mail folders ..."
  389.       SAY
  390.       IF bSkip THEN
  391.          bTmpSkip = ( answer = "P" )
  392.       ELSE
  393.          bTmpSkip = .false
  394.       
  395.       DO item OVER .lam.FolderList              /* get a directory      */
  396.  
  397.          IF bTmpSkip THEN
  398.          DO
  399.             answer = "Y"                        /* default to yes       */
  400.             answer  = get_choice( answer, "Migrate" pp( item ) "? (Y/n/g/s/q)",,
  401.                                   "Choose: Y(es), g(o ahead, migrate all left), n(o), s(kip all), q(uit)", "YNGSQ" )
  402.  
  403.             IF answer = "N" THEN ITERATE        /* not this one, maybe the next ?       */
  404.             ELSE IF answer = "S" THEN LEAVE     /* skip all             */
  405.  
  406.             btmpSkip = ( answer = "Y" )         /* continue to ask ?    */
  407.          END
  408.    
  409.          targDirName = REVERSE( item )
  410.          targDirName = REVERSE( SUBSTR( targDirName, 1, POS( "\", targDirName ) ) ) || ".FLD"
  411.          targDir     = .work.TargetPath || targDirName 
  412.    
  413.          CALL Replicate_EMAIL item, targDir        /* copy, rename LaMail e-mail           */
  414.          CALL make_folder_ini targDir              /* create PM-Mail FOLDER.INI file       */
  415.       END
  416.    END
  417.  
  418.  
  419.                 /* copying LaMail's inbox file  */
  420.    CALL Beep 2500, 250
  421.    SAY "ATTENTION: If you defined LaMail-Inbox directory" pp( .lam.inbox )
  422.    SAY "           as your SMTPPATH in PM-View, then there is *NO* need to delete"
  423.    SAY "           the LaMail-Inbox ! This is because e-mail sent thru sendmail.exe"
  424.    SAY "           is stored in this path, if set up thru OS/2's TCP/IP configuration."
  425.    SAY 
  426.    SAY "           (With other words, you receive your e-mail via SMTP and have OS/2"
  427.    SAY "           place it first into LaMail's InBox-directory from which PM-Mail"
  428.    SAY "           will fetch the e-mail on its next read-cycle.)."
  429.    SAY 
  430.    SAY "           If you migrate LaMail's InBox e-mails, they will get stored "
  431.    SAY "           underneath e.g." 
  432.    SAY "         " pp( .work.TargetPath || "\INBOX???.FLD" ) 
  433.    SAY "           (hint: the '????' may be filled with blanks or numbers)."
  434.    SAY 
  435.    SAY "           *NEVERTHELESS* if you fetch new e-mail from LaMail's InBox-Folder"
  436.    SAY "           then all the e-mail will get moved over to *PM-Mail*'s Inbox-Folder" 
  437.    SAY "           unless you run immediately step # 2 'Delete LaMail e-mail' right"
  438.    SAY "           after this run."
  439.    SAY
  440.    SAY "           RECOMMENDATION: do *not* migrate LaMail's InBox folder in this case"
  441.    SAY "                     (PM-Mail SMTTPATH pointing to LaMail's InBox), rather"
  442.    SAY "                     fetch all the e-mail with PM-Mail's fetch feature."
  443.    SAY
  444.    "@PAUSE"
  445.  
  446.    answer = "Y"                                    /* default to Yes               */
  447.    answer  = get_choice( answer, "Migrate LaMail's inbox e-mail ? (Y/n)" )
  448.  
  449.    IF answer = "Y" THEN
  450.    DO
  451.       SAY
  452.       SAY "Copying LaMail's inbox-directory ..."
  453.       SAY
  454.       
  455.               /* copy from inbox-dir          */
  456.       
  457.       tmpTargetDir = .work.TargetPath || "\INBOX.FLD"
  458.       CALL SysFileTree tmpTargetDir, "folder.", "DO"
  459.       
  460.       IF folder.0 > 0 THEN            /* exists already !             */
  461.       DO
  462.          tmpTargetDir = SysTempFileName( .work.TargetPath || "\INBOX???.FLD" )
  463.          IF tmpTargetDir = "" THEN
  464.          DO
  465.             SAY "It is not possible to create a unique LAMail INBOX name in" pp( .work.TargetPath )
  466.             CALL abort
  467.          END
  468.       END
  469.  
  470.       CALL Replicate_EMAIL .lam.Inbox, tmpTargetDir     /* copy LaMail IN-folder        */
  471.       CALL make_folder_ini tmpTargetDir                 /* create FOLDER.INIs   */
  472.       
  473.                 /* delete LaMail's INBOX.NDX-index, which got renamed to INBOX.MSG      */
  474.       ADDRESS CMD "DEL" tmpTargetDir || "\INBOX.MSG"
  475.    END
  476. END
  477.  
  478.  
  479. answer = "Y"                                    /* default to Yes               */
  480. IF bSkip THEN
  481.    answer  = get_choice( answer, "Migrate LaMail address-book ? (Y/n/q)" )
  482.  
  483. IF answer = "Y" THEN
  484. DO
  485.    SAY
  486.    SAY "Creating address books and addresses from LaMail definitions ..."
  487.    SAY
  488.            /* create Addresses, in the course create books, if necessary   */
  489.    CALL create_accounts                         /* create accounts              */
  490. END
  491.  
  492.  
  493. SAY "Sorting and replacing address groups ..."
  494. .group ~~ sortedReplace                 /* sort and replace groups      */
  495. SAY "Sorting and replacing address books ..."
  496. .books ~~ sortedReplace                 /* sort and replace books       */
  497. SAY "Sorting and replacing addresses ..."
  498. .addr  ~~ sortedReplace                 /* sort and replace addresses   */
  499.  
  500.  
  501.  
  502.         /* all error information will be written to STDERR              */
  503. SAY
  504. CALL LINEOUT STDERR, "Migration LaMail ---> PM-Mail 1.9:" 
  505. CALL LINEOUT STDERR, "" 
  506. .logError ~ dump                /* dump any errors that occurred (from LMRXTOOL.CMD)    */
  507.  
  508.  
  509. SAY
  510. SAY
  511. SAY "Migration LaMail ---> PM-Mail 1.9 finished."
  512. SAY
  513. SAY "You need to reindex every migrated LaMail folder from"
  514. SAY "within PM-Mail 1.9 (Menu: Folder ---> Re-Index)."
  515. SAY
  516. SAY "Good luck, that everything worked out ! ;-)"
  517. SAY "---rgf"
  518.  
  519. EXIT
  520.  
  521.  
  522.  
  523. get_choice : PROCEDURE          /* general procedure to ask for an action       */
  524.    USE ARG answer, prompt, choice_prompt, choose_string
  525.  
  526.    IF \ VAR( "choice_prompt" ) THEN choice_prompt = "Choices: y(es), n(o), q(uit)"
  527.    IF \ VAR( "choose_string" ) THEN choose_string = "YNQ"
  528.  
  529.    SAY; SAY; SAY
  530.    SAY LEFT( prompt || " ", 79, "=" )
  531.    SAY
  532.    SAY choice_prompt 
  533.    SAY 
  534.    CALL CHAROUT , "Enter your choice: "
  535.    tmpAnswer = get_answer( choose_string )
  536.  
  537.    IF POS( tmpAnswer, choose_string) = 0 THEN           /* use default  */
  538.    DO
  539.       tmpAnswer = answer
  540.       SAY answer "(default)"
  541.    END
  542.  
  543.    IF tmpAnswer = "Q" THEN CALL abort                   /* abort        */
  544.  
  545.    RETURN tmpAnswer
  546.  
  547.  
  548.  
  549.  
  550.         /* creates addresses from LaMail-NickName file,
  551.            creates address-books in the process, if necessary   */
  552. create_accounts : PROCEDURE
  553.  
  554.    /* loop over nicknames               */
  555.    .nickNames ~ NewFromFile             /* read nickname-file, build nickname-objects   */
  556.  
  557.    DefaultBook = "Default Book" 
  558.    tmpLMGroups = .list ~ new            /* for storing LaMail-addresses which are aliases       */
  559.    tmpLMAlias  = .directory ~ new       /* to store LaMailAliases pointing to PM-Mail address objects   */
  560.  
  561.    workCRLF = .pmm.CR || .pmm.LF        /* create a short-cut for CR-LF encoding        */
  562.  
  563.    DO nickObj OVER .nickNames ~ nickNameList
  564.       tmpDir    = nickObj ~ ObjectData 
  565.  
  566.                 /* retrieve standard nick-names */
  567.       tmpNick   = tmpDir ~ nick
  568.  
  569.       tmpName   = tmpDir ~ name
  570.       IF tmpName = .nil THEN tmpName = ""       /* no name given !                      */
  571.  
  572.       tmpUserId = tmpDir ~ userid
  573.       tmpNode   = tmpDir ~ node
  574.       tmpPhone  = tmpDir ~ Phone
  575.       tmpFolder = tmpDir ~ folder
  576.       IF tmpFolder = .nil THEN tmpFolder = ""   /* no folder given !                    */
  577.  
  578.                 /* Build Alias and real name    */
  579.       lastName  = ""
  580.       firstName = ""
  581.       IF POS( ",", tmpName ) > 0 THEN           /* assume "Lastname, title First Names" */
  582.       DO
  583.          PARSE VAR tmpName lastName "," firstName
  584.       END
  585.       ELSE IF tmpName <> "" THEN
  586.       DO                                        /* assume "title FirstNames LASTNAME"   */
  587.          words = WORDS( tmpName )               /* get number of words in string        */
  588.          IF words > 1 THEN
  589.          DO
  590.             lastName  = WORD( tmpName, words )          /* get last token as lastname   */
  591.             firstName = SUBWORD( tmpName, 1, words - 1)
  592.          END
  593.          ELSE 
  594.             lastName = tmpName
  595.       END
  596.  
  597.       IF lastName = "" THEN                     /* no name given, use nick-name         */
  598.          newAlias = tmpNick                     
  599.       ELSE
  600.       DO
  601.          newAlias = lastName "(" || tmpNick || ")"
  602.          IF firstName <> "" THEN
  603.             newAlias = newAlias || "," firstName
  604.       END
  605.  
  606.  
  607.                                 /* determine book this address belongs to       */
  608.       IF tmpFolder = "" THEN workBook = DefaultBook
  609.                         ELSE workBook = tmpFolder       /* use folder name      */
  610.  
  611.  
  612.       nr = get_book_nr( workBook "(from LaMail)" )     /* find book-number     */
  613.  
  614.  
  615.                 /* handle alias-addresses, i.e. turn them into a PM-Mail group  */
  616.       IF WORDS( tmpUserid ) > 1 THEN            /* process later                */
  617.       DO
  618.          newAlias = "Group:" newAlias           /* Hint at group                */
  619.          tmpDir ~ nr = nr                       /* store retrieved book_number  */
  620.          tmpDir ~ alias = newAlias        
  621.          tmpLMGroups ~ insert( tmpDir )         /* store, process later         */
  622.          tmpLMAlias ~ setentry( tmpNick, newAlias )     /* remember this alias  */
  623.          ITERATE
  624.       END
  625.  
  626.  
  627.  
  628.                 /* check whether address exists already, using ALIAS as primary key     */
  629.       tmpAObj = .addr ~ lookupTable ~ at( newAlias )
  630.       IF tmpAObj <> .nil THEN                   /* don't add existing address           */
  631.       DO
  632.          .logError ~ new( "Address with alias" pp( newAlias ) "exists already!" )
  633.          ITERATE
  634.       END
  635.  
  636.  
  637.                 /* create address entry */
  638.       tmpADir = .directory ~ new
  639.       tmpADir ~ in_book_nr = nr
  640.       tmpADir ~ e_mail     = tmpUserid || "@" || tmpNode
  641.       tmpADir ~ alias      = newAlias
  642.       tmpADir ~ truename   = tmpName
  643.       IF tmpPhone <> "" THEN
  644.       DO
  645.          tmpAdir ~ H_phone    = tmpPhone        /* put phone number into both areas     */
  646.          tmpAdir ~ B_phone    = tmpPhone
  647.       END
  648.       tmpAdir ~ SHOW_ON_RMB   = 1               /* show on right mouse button           */
  649.  
  650.                 /* add all nick-name entries into note-field            */
  651.       tmpArr = sortCollection( tmpDir )
  652.  
  653.       tmpString = "LaMail Nickname entry:" || workCRLF || workCRLF
  654.       tmpString = tmpString || ":nick." || tmpNick || workCRLF
  655.       DO i = 1 TO tmpDir ~ items
  656.          IF tmpArr[ i, 1 ] = "NICK" THEN ITERATE
  657.          tmpString = tmpString || workCRLF || "    :" || tmpArr[ i, 1 ] || "." || tmpArr[ i, 2 ]
  658.       END
  659.       DROP tmpArr
  660.  
  661.       tmpAdir ~ notes = tmpString
  662.  
  663.       tmpAddrObj = .addr ~ new( tmpADir )       /* create a new address         */
  664.       tmpLMAlias ~ setentry( tmpNick, newAlias )/* used while building groups   */
  665.  
  666.       DROP tmpADir
  667.       DROP tmpDir
  668.    END
  669.  
  670.  
  671.         /* create groups for LaMail addresses containing aliases        */
  672.    DO tmpDir OVER tmpLMGroups                   /* iterate over list    */
  673.       tmpGroupObj = .group ~ lookUpTable ~ at( tmpDir ~ Alias )
  674.       IF tmpGroupObj <> .nil THEN 
  675.       DO
  676.          .logError ~ new( "Group with alias" pp( newAlias ) "exists already!" )
  677.          ITERATE    /* exists already               */
  678.       END
  679.  
  680.              /* create new, unique file              */
  681.       newGrpFile = SysTempFileName( "GROUPS\LaM_????.GRP" )
  682.       IF newGrpFile = "" THEN
  683.       DO
  684.          .logError ~ new( "Error creating group-file for" pp( tmpNick ) )
  685.          ITERATE
  686.       END
  687.  
  688.       tmpGDir = .directory ~ new
  689.       tmpGDir ~~ setentry( "SHOW_ON_RMB",  1 ) ~~ setentry( "NAME", tmpDir ~ name  )
  690.       tmpGDir ~~ setentry( "ALIAS", tmpDir ~ alias ) ~~ setentry( "IN_BOOK_NR", tmpDir ~ nr )
  691.       tmpGDir ~~ setentry( "PATH", "..\TOOLS\" || newGrpFile )
  692.       tmpGDir ~~ setentry( "DESCRIPTION", "Migrated from LaMail on" pp( .work.DateTime ) )
  693.       tmpGObj = .group ~ new( tmpGDir )         /* create new group-object      */
  694.       DROP tmpGDir
  695.  
  696.       tmpUserId = tmpDir ~ UserId
  697.  
  698.       DO WHILE tmpUserID <> ""                  /* create group file addresses  */
  699.          PARSE VAR tmpUserID tmpEntry tmpUserID
  700.  
  701.          IF POS( "@", tmpEntry ) > 0 THEN tmpValue = tmpEntry   /* a true e-mail address        */
  702.                                      ELSE tmpValue = tmpLMAlias ~ entry( tmpEntry )
  703.  
  704.          IF tmpValue = .nil THEN                /* outdated entries, nick-name does not exist! */
  705.          DO
  706.             .LogError ~ new( "Error while creating group" pp( tmpDir ~ alias ) "for LaMail nickname",
  707.                              pp( tmpDir ~ nick ) || ", definition for" pp( tmpEntry ) ,
  708.                              "not available in LaMail's nickname file !" )
  709.          END
  710.          ELSE
  711.             CALL LINEOUT newGrpFile, tmpValue   /* MAKESTRING will render it accordingly        */
  712.       END
  713.       CALL STREAM newGrpFile, "C", "CLOSE"
  714.    END
  715.  
  716.  
  717.    RETURN
  718.  
  719.  
  720. get_book_nr : PROCEDURE                 /* find the book, create it, if necessary       */
  721.    USE ARG workBook
  722.  
  723.    tmpBookObj = .books ~ LookupTable ~ at( workBook ) 
  724.  
  725.    IF tmpBookObj = .nil THEN
  726.    DO                          /* not available, hence create it       */
  727.       tmpBDir = .directory ~ new
  728.       tmpBDir ~ setentry( "NAME", workBook )
  729.       nr = .work.MaxNumbers ~ books + 1      /* generate a new book number   */
  730.       .work.MaxNumbers ~ books = nr
  731.       tmpBDir ~~ setentry( "NUMBER", nr ) ~~ setentry( "SORT_DESCE", 0 )
  732.       tmpBDir ~  setentry( "SORT_FIELD_NR", 0 )
  733.       tmpBookObj = .books ~ new( tmpBDir )   /* create a new book-object     */
  734.  
  735.       DROP tmpBDir
  736.    END
  737.    ELSE
  738.       nr = tmpBookObj ~ objectData ~ number  /* book nr to put address into  */
  739.       
  740.    RETURN nr
  741.  
  742.  
  743. make_folder_ini : PROCEDURE             /* create FOLDER.INI files in all new PM-Mail folders   */
  744.    USE ARG item     
  745.  
  746.    max = MAX( 1000, .work.maxNumbers ~ folders )        /* determine starting number for folders */
  747.    max = max + 1
  748.  
  749.         /* extract folder name  */
  750.    tmp = REVERSE( item )             
  751.    PARSE VAR tmp . "." folder_name "\" .
  752.    folder = REVERSE( folder_name ) "from LaMail" pp( .work.DateTime )
  753.  
  754.         /* setup FOLDER.INI-string      */
  755.    tmpString =  folder || .pmm.deli || max || .pmm.deli || .work.folder.template
  756.  
  757.    tmpFile = item || "\FOLDER.INI"              /* define name for INI-file     */
  758.    CALL STREAM tmpFile, "C", "OPEN REPLACE"
  759.    CALL LINEOUT tmpFile, tmpString              /* create FOLDER.INI file       */
  760.    CALL STREAM tmpFile, "C", "CLOSE"
  761.  
  762.    .work.maxNumbers ~ folders = max             /* store actual high number     */
  763.    RETURN
  764.  
  765.  
  766.  
  767. abort : PROCEDURE 
  768.    CALL BEEP 2000, 250
  769.    SAY "aborting LaMail ---> PM-Mail 1.9 migration ..."
  770.    EXIT -1
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777. :: REQUIRES     pmmrxtoo                /* PM-Mail Rexx tool    */
  778. :: REQUIRES     lmrxtool                /* LaMail Rexx tool     */
  779.  
  780.