Loading ...
Sorry, an error occurred while loading the content.

[jasspa] Netscape Mailbox to MS Excahnge Server News Files Converter

Expand Messages
  • Jon Green
    The following might be useful. This macro converts a Netscape mail box into Microsoft exchange server news files. This allows an exisiting mail box to be
    Message 1 of 1 , Mar 22, 2000
    • 0 Attachment
      The following might be useful. This macro converts a Netscape
      mail box into Microsoft exchange server news files. This
      allows an exisiting mail box to be converted into News
      for everybody to read.

      Netscape mailbox generated on windows.

      Regards
      Jon.


      ;
      ; Author : $Author$
      ; Created By : Jon Green
      ; Created : Tue Mar 21 13:24:30 2000
      ; Last Modified : <000322.1031>
      ;
      ; Description : Convert a Netscape mail box to a Microsoft Internet
      ; Information Server News files.
      ;
      ; Notes :
      ;
      ; History
      ;
      ; Copyright (c) JASSPA 2000.
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

      define-macro netscape-mail-to-miis-news-files
      ; #l0 The base name (excluding the extension) of the generated file.
      ; #l1 The name of the buffer and generated file.
      ; #l2 The loop counter runs 1..n
      ; #l3 The news group name i.e. comp.emacs
      ; #l4 The name of the news server host (i.e. inet.jasspa.com)
      ; #l5 The base name of the directory into which we generate the file.
      ; #l8 The line number count
      ; #l9 The flag to force an exit 1 = run, 0 = exit

      ; Confirm that this is a mail file
      beginning-of-buffer
      !force regex-forward "From - [A-Za-z][A-Za-z][A-Za-z] [A-Za-z][A-Za-z][A-Za-z] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]"
      !if ¬ $status
      ml-write "This is not a Netscape mail file"
      !abort
      !endif
      ;
      ; Promot the user for the names of the server. (#l3)
      ;
      set-variable #l3 @ml "News group name (i.e. comp.emacs) ? "
      !if &seq #l3 ""
      2000 ml-write "No news group name, aborting"
      !abort
      !endif
      ;
      ; Promt the user for then name of the mail server. (#l4)
      ;
      set-variable #l4 @ml "News server name (i.e. inet.jasspa.com) ? "
      !if &seq #l4 ""
      2000 ml-write "No News server name, aborting"
      !abort
      !endif
      ;
      ; Get the base directory name (#l5)
      ;
      set-variable #l5 &rsin "/" $buffer-fname
      !if &equ #l5 0
      ml-write "Cannot find base directory location"
      !abort
      !endif
      set-variable #l5 &lef $buffer-fname #l5
      ml-write &spr "Base name %s => %s" $buffer-fname #l5

      ;
      ; Initialise variables
      ; #l2 - loop counter
      ; #l9 - Exit flag
      set-variable #l2 1
      set-variable #l9 1

      ;
      ; Knock off undo mode from the buffer
      ;
      -1 buffer-mode "undo"

      ; Leave the 'from' line as the top line in the buffer
      ; Remove all leading lines up until the first header.
      beginning-of-line
      set-mark
      beginning-of-buffer
      kill-region
      -1 yank
      ;
      ; Iterate through the buffer looking for the messages
      ; to process. Extract each message in turn.
      ;
      !repeat
      beginning-of-buffer
      kill-line
      ml-write &spr "Processing Message %d" #l2
      !force regex-forward "From - [A-Za-z][A-Za-z][A-Za-z] [A-Za-z][A-Za-z][A-Za-z] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]"
      !if ¬ $status
      set-variable #l9 0
      end-of-buffer
      set-mark
      !else
      beginning-of-line
      set-mark
      !endif
      beginning-of-buffer
      kill-region
      ; Construct the name for the new file. The naming for the MS server
      ; is a little strange. Basically the filename is the ASCII
      ; name of the message number, starting from 1. But the LSB
      ; is the MSB of the file name. The name is in ASCII hexadecimal.
      ; We will generate up to 2^24 files.
      set-variable #l0 &mul &band 0x000000ff #l2 0x10000
      set-variable #l0 &add #l0 &band 0x0000ff00 #l2
      set-variable #l0 &add #l0 &div &band 0x00ff0000 #l2 0x10000
      set-variable #l0 &spr "%x00" #l0
      ;
      ; Construct the resultant file name and buffer name
      ; Create the buffer and yank in the message.
      set-variable #l1 &cat #l0 ".nws"
      find-buffer #l1
      -1 buffer-mode "undo"
      yank
      -1 yank
      beginning-of-buffer
      ; Add the news trailers, this is the first blank line
      ; following the headers. We need to count the lines
      ; as well.
      !force regex-forward "^ *\n"
      backward-line
      insert-string &spr "Path: %s" #l4
      newline
      insert-string &spr "Xref: %s %s:%d" #l4 #l3 #l2
      newline
      insert-string "NNTP-Posting-Host: MicroEmacs 127.0.0.1"
      newline
      set-variable #l8 $window-line
      set-mark
      end-of-buffer
      set-variable #l8 &sub $window-line #l8
      insert-string "."
      exchange-point-and-mark
      insert-string &spr "Lines: %d" #l8
      newline
      ;
      ; We have found that we get some Message-Id fields with the
      ; same identity. This causes the MS Server to fail the file
      ; and mark it as bad. Fix up the Message-Id with some bogud
      ; value to fool the stupid server.
      beginning-of-buffer
      !force regex-forward "^Message-Id:[ \t]*<"
      !if $status
      insert-string &spr "me/%s/" #l0
      !endif
      ;
      ; Save the file in the current directory
      ;
      !force write-buffer &cat #l5 #l1
      !if ¬ $status
      ml-write &spr "Cannot write file \"%s%s\" - probably exists" #l5 #l1
      delete-buffer #l1
      !abort
      !endif
      delete-buffer #l1
      set-variable #l2 &add #l2 1
      !until &equ #l9 0
      !emacro
    Your message has been successfully submitted and would be delivered to recipients shortly.