#!/bin/sh # the next line restarts using tclsh 8.0 (should work with other tcl versions) \ exec tclsh8.0 "$0" "$@" # c2n.tcl -- # # This tcl application converts mail messages from the old VIS000 # mail format (Compuserve) to Netscape Communicator mail messages. # It reads all the files into the source directory and converts # all the .plx and .msg into a new file called as the source directory. # # # Copyright (c) 1998 José María González, http://www.cs.berkeley.edu/~chema # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # A. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # B. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # C. Neither the names of the copyright holders nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # @(#) $Header: c2n.tcl,v 1.1 1998/10/28 17:04:25 chema Exp $ # TODO list: # - debug it thoroughly # - packetize all the code (pretty nasty currently) # - get rid of all the code that uses a default mail address (at least # put it inside global variables # # write here your name set default_receiver_name "John Doe" set default_receiver_address john@doe.com set default_sender_name "John Doe" set other_name "John X. Doe" set other_address "doe@john.com" proc LookForNpac {the_string} { for {set i 0} {$i < [string length $the_string]} {incr i} { set character [string range $the_string $i $i] if {$character < " "} {break} } return $i } proc LookForPac {the_string} { for {set i 0} {$i < [string length $the_string]} {incr i} { set character [string range $the_string $i $i] if {$character >= " "} {break} } return $i } proc LookForNpacExtended {the_string} { for {set i 0} {$i < [string length $the_string]} {incr i} { set character [string range $the_string $i $i] # Extended Look for non-printable character: looks for # characters under the space (0x20) which are neither # newline (0x0a), carriage feed (0x0d), nor a tab (0x09) if {($character < " ") && ($character != "\x0a") && \ ($character != "\x0d") && ($character != "\x09")} {break} } return $i } proc LookForNpacReduced {the_string} { for {set i 0} {$i < [string length $the_string]} {incr i} { set character [string range $the_string $i $i] # Reduced Look for non-printable character: looks for # characters under the space (0x20), and for the appereance # of the string "INTERNET:" if {($character < " ") || ($character == "%")} { break } if {($i != 0) && ([string range $the_string $i [expr $i + 8]] == \ "INTERNET:")} { set i [expr $i - 1] break } } return $i } proc LookForText {the_string} { set MIN_TEXT 10 set counter 0 for {set i 0} {$i < [string length $the_string]} {incr i} { set character [string range $the_string $i $i] if {($character >= " ") || ($character == "\n")} { incr counter } else { set counter 0 } if {$counter >= $MIN_TEXT} {break} } return [expr $i - $MIN_TEXT + 1] } proc ProcessAddress {old_address_} { upvar $old_address_ old_address if {[string range $old_address 0 8] == "INTERNET:"} { set old_address [string range $old_address 9 end] return 0 } elseif {[string range $old_address 0 3] == "CIS:"} { return 0 } else { regexp {([0-9]+),([0-9]+)} $old_address u first second if {[catch {set new_address "$first.$second@compuserve.com"}] != 0} { puts "Error in the address \"$old_address\"" set old_address "ERROR" return 1 } else { set old_address $new_address return 0 } } } ####################################################################### # # ProcessCompuserveMail # ####################################################################### proc ProcessCompuserveMail {contents errMsg_ new_message_ extension} { upvar $errMsg_ errMsg upvar $new_message_ new_message global default_receiver_name global default_sender_name global default_receiver_address global other_name global other_address #----------------------------------------------------------------------- # The structure of Compuserve's VIS000 mail files is the following: # # Note: 'npac' stands for 'non-printable ASCII char' # (i.e., 00x to 19x inclusive) # # # 1. 'VIS000..........' # <---- 0-26 ----> header (useless?) # # 2. 'text' + npac subject # 3. 'text' + npac Sender's name # 4. 'text' + npac Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) # 4bis 'text' + npac Receiver's forum name # # 5. '................' # <----- 16 -----> date and time of the message # byte 4 -> minute in hexadecimal # byte 5 -> hour in hexadecimal # byte 6 -> day in hexadecimal # byte 7 -> month in hexadecimal # byte 8 -> year in hexadecimal (add 1970) # # 6. 'text' + npac subject # 7. 'text' + npac Sender's name # 8. 'text' + npac+ Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) # 9. 'text' + npac Receiver's name # 10. 'text' + npac Receiver's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) # 11. '................' # <---- 0-? -----> unknown (useless?) # 12. 'text' Body # #----------------------------------------------------------------------- #----------------------------------------------------------------------- # 1. 'VIS000..........' # <---- 0-26 ----> header (useless?) #----------------------------------------------------------------------- set index 27 if {[catch {set header [string range $contents 0 5]}] != 0} { set errMsg "Error while reading the message (error1.1)" return 1 } if {$header != "VIS000"} { puts "Error: The header is not VIS000 ($header) (error1.2)" return 1 } if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error1.3)" return 1 } #----------------------------------------------------------------------- # 2. 'text' + npac subject #----------------------------------------------------------------------- # set index [LookForNpac $contents] set index [LookForNpacReduced $contents] if {[catch {set subject [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the subject (error2.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error2.2)" return 1 } #----------------------------------------------------------------------- # 3. 'text' + npac Sender's name #----------------------------------------------------------------------- # set index [LookForNpac $contents] set index [LookForNpacReduced $contents] if {[catch {set sender_name [string range $contents 0 [expr $index - 1]]}] \ != 0} { set errMsg "Error while reading the sender name 1 (error3.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error3.2)" return 1 } #----------------------------------------------------------------------- # 4. 'text' + npac Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) #----------------------------------------------------------------------- set index [LookForNpac $contents] if {[catch {set sender_address [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the sender's address (error4.1)" return 1 } set result [ProcessAddress sender_address] #----------------------------------------------------------------------- # 4bis 'text' + npac Receiver's forum name #----------------------------------------------------------------------- if {($extension == ".msg") || ($extension == ".MSG")} { incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error4bis.1)" return 1 } set index [LookForNpac $contents] if {[catch {set forum_address [string range $contents 0 [expr $index - 1]]}] != 0} { set errMsg "Error while reading the recv's forum address (error4bis.2)" return 1 } set result [ProcessAddress forum_address] puts " --> The sender's forum address is $forum_address" } # incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error4.2)" return 1 } puts "subject is $subject, sender_name is $sender_name, sender_address is $sender_address" #----------------------------------------------------------------------- # 5. '................' # <----- 16 -----> date and time of the message #----------------------------------------------------------------------- # 5.1. byte 4 -> minute in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 2 } else { set index 4 } set minute_ [string range $contents $index $index] if {$minute_ == "\x00"} { set minute 0 } else { scan $minute_ %c minute } # 5.2. byte 5 -> hour in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 3 } else { set index 5 } set hour_ [string range $contents $index $index] if {$hour_ == "\x00"} { set hour 0 } else { scan $hour_ %c hour } # 5.3. byte 6 -> day in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 4 } else { set index 6 } set day_ [string range $contents $index $index] scan $day_ %c day # 5.4. byte 7 -> month in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 5 } else { set index 7 } set month_ [string range $contents $index $index] scan $month_ %c month # 5.5. byte 8 -> year in hexadecimal (add 1970) if {($extension == ".msg") || ($extension == ".MSG")} { set index 6 } else { set index 8 } set year_ [string range $contents $index $index] scan $year_ %c year set year [expr $year + 1970] set date "$month\/$day\/$year $hour:$minute" set int_clock [clock scan $date] set date [clock format $int_clock -format "%a, %d %b %Y %H:%M:%S +0100"] set index 16 if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error5.1)" return 1 } #----------------------------------------------------------------------- # 6. 'text' + npac subject #----------------------------------------------------------------------- # set index [LookForNpac $contents] set index [LookForNpacReduced $contents] if {[catch {set subject2 [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the subject2 (error6.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error6.2)" return 1 } # if {$subject != $subject2} { # set errMsg "Error: I have two subjects (\"$subject\" and \"$subject2\" \ # (error6.3)" # return 1 # } #----------------------------------------------------------------------- # 7. 'text' + npac Sender's name #----------------------------------------------------------------------- # set index [LookForNpac $contents] set index [LookForNpacReduced $contents] if {[catch {set sender_name2 [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the sender's name 2 (error7.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error7.2)" return 1 } if {$sender_name != $sender_name2} { set errMsg "Error: I have two sender's name (\"$sender_name\" and \ \"$sender_name2\" \ (error7.3)" return 1 } #----------------------------------------------------------------------- # 8. 'text' + npac+ Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) #----------------------------------------------------------------------- set index [LookForNpac $contents] if {[catch {set sender_address2 [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the sender's address (error8.1)" return 1 } set result [ProcessAddress sender_address2] # incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error8.2)" return 1 } set index [LookForPac $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error8.3)" return 1 } if {$sender_address != $sender_address2} { set errMsg "Error: I have two sender's addresses (\"$sender_address\" \ and \"$sender_address2\" \ (error8.4)" return 1 } #----------------------------------------------------------------------- # 9. 'text' + npac Receiver's name #----------------------------------------------------------------------- set index [LookForNpacReduced $contents] if {[catch {set receiver_name [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the receiver's name (error9.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error9.2)" return 1 } #----------------------------------------------------------------------- # 9bis. 'text' + npac Receiver's name #----------------------------------------------------------------------- if {($extension == ".msg") || ($extension == ".MSG")} { set forum_name $receiver_name } if {($extension == ".msg") || ($extension == ".MSG")} { set exit 0 while {$exit == 0} { set index [LookForText $contents] catch {set contents [string range $contents $index end]} if {[string range $contents 0 7] == "Spanish+"} { set exit 1 } set index 1 catch {set contents [string range $contents $index end]} set index [LookForNpac $contents] catch {set contents [string range $contents $index end]} } } else { #--------------------------------------------------------------------- # 10. 'text' + npac Receiver's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) #--------------------------------------------------------------------- set index [LookForNpac $contents] if {[catch {set receiver_address [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the receiver's name (error10.1)" return 1 } set result [ProcessAddress receiver_address] # incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error10.2)" return 1 } #--------------------------------------------------------------------- # 11. '................' # <---- 0-? -----> unknown (useless?) #--------------------------------------------------------------------- set index [LookForText $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error11.2)" return 1 } #--------------------------------------------------------------------- # 12. 'text' Body #--------------------------------------------------------------------- if {[string match "Internet Message Header" $contents] == 1} { set index [LookForNpac $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error12.1)" return 1 } set index [LookForPac $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error12.2)" return 1 } } } set body [string range $contents 0 end] while {!([LookForNpacExtended $body] == [string length $body])} { set index [LookForNpacExtended $body] if {[catch {set body [string range $body $index end]}] != 0} { set errMsg "Error while reading the message (error12.3)" return 1 } set index [LookForPac $body] if {[catch {set body [string range $body $index end]}] != 0} { set errMsg "Error while reading the message (error12.4)" return 1 } } regsub -all "@b\n" $body "\n" body regsub -all "@b\n" $body "\n" body regsub -all "@b\n" $body "\n" body # set body [string range $contents 0 end] # regsub -all "@b\n" $contents "\n" body # set body_error 0 # set body_end 0 # while {$body_end == 0} { #puts "\\\\ -> inside the body_end == 0 loop" # set index [LookForNpacExtended $body] # if {($index == 0) && ([string length $body] == 0)} { #puts " ----> index is $index and the length is [string length $body]" # if {$body_end == 0} { # set body_end 1 # set errMsg "This shouldn't happen (error12.2bis)" # return 1 # } # break # } # if {$index != [expr [string length $body] - 1]} { #puts " --> A body piece starts with \"[string range $body 0 10]\"" #puts " ----> index is $index and the length is [string length $body]" # incr body_error # # # incr index # set index [LookForPac $contents] # if {[catch {set body [string range $body $index end]}] != 0} { # set errMsg "Error while reading the message (error12.3)" # return 1 # } # } else { # set body_end 1 # } # } # if {$body_error == 1} { # set errMsg "Multiple body error (error12.4)" # return 1 # } #--------------------------------------------------------------------- # 13. Convert the old address and name to the new ones #--------------------------------------------------------------------- catch { if {$receiver_address == $other_address} { set receiver_address $default_receiver_address set receiver_name $default_receiver_name } } catch { if {($receiver_name == $other_name) || ($receiver_name == "\"$other_name\"")} { set receiver_address $default_receiver_address set receiver_name $default_receiver_name } } catch { if {$receiver_address == "ERROR"} { set receiver_address $default_receiver_address set receiver_name $default_receiver_name } } if {$sender_address == $other_address} { set sender_address $default_receiver_address set sender_name $default_sender_name } if {($sender_name == $other_name) || ($sender_name == "\"$other_name\"")} { set sender_address $default_receiver_address set sender_name $default_sender_name } #puts " --> The subject is $subject" #puts " --> The sender's name is $sender_name" #puts " --> The sender's address is $sender_address" #puts " --> The date is $date" #puts " --> The receiver's name is $receiver_name" #puts " --> The receiver's address is $receiver_address" puts "($sender_name, $sender_address) -> ($receiver_name, $receiver_address), \ \"$subject\", $date" puts " --> The body ([string length $body] characters) starts with \"[string range $body 0 10]\"\n" #----------------------------- # 14. Create the new mail file #----------------------------- set new_message "From $sender_address $date\n" append new_message "Return-Path: $sender_address\n" append new_message "Sender: $sender_address\n" append new_message "Message-ID: <3637B2B0.3D0D8045@unknown.es>\n" append new_message "Date: $date\n" append new_message "From: $sender_name <$sender_address>\n" append new_message "Organization: None\n" append new_message "X-Mailer: c2n.tcl on my old Compuserve email\n" append new_message "X-Accept-Language: es,gl,en\n" append new_message "MIME-Version: 1.0\n" if {($extension == ".msg") || ($extension == ".MSG")} { append new_message "To: $forum_name <$forum_address>\n" } else { append new_message "To: $receiver_name <$receiver_address>\n" } append new_message "Subject: $subject\n" append new_message "Content-Type: text/plain; charset=us-ascii\n" append new_message "Content-Transfer-Encoding: 7bit\n" append new_message "X-Mozilla-Status: 8001\n" append new_message "X-Mozilla-Status2: 00000000\n" append new_message "\n" append new_message "$body\n" append new_message "\n" #----------------------------- # 15. Return #----------------------------- return 0 } ####################################################################### # # ProcessCompuserveMessage # ####################################################################### proc ProcessCompuserveMessage {contents errMsg_ new_message_ extension} { upvar $errMsg_ errMsg upvar $new_message_ new_message global default_receiver_name global default_sender_name global default_receiver_address global other_name global other_address #----------------------------------------------------------------------- # The structure of Compuserve's VIS000 message files is the following: # # Note: 'npac' stands for 'non-printable ASCII char' # (i.e., 00x to 19x inclusive) # # # 1. 'VIS000..........' # <---- 0-26 ----> header (useless?) # # 2. 'text' + npac subject # 3. 'text' + npac Sender's name # 4. 'text' + npac Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) # 5. 'text' + npac Receiver's forum name # # 6. '................' # <----- 16 -----> date and time of the message # byte 4 -> minute in hexadecimal # byte 5 -> hour in hexadecimal # byte 6 -> day in hexadecimal # byte 7 -> month in hexadecimal # byte 8 -> year in hexadecimal (add 1970) # # 7. '................' # <---- 0-? -----> unknown (useless?) # 8. 'text' Body # #----------------------------------------------------------------------- #----------------------------------------------------------------------- # 1. 'VIS000..........' # <---- 0-26 ----> header (useless?) #----------------------------------------------------------------------- set index 27 if {[catch {set header [string range $contents 0 5]}] != 0} { set errMsg "Error while reading the message (error1.1)" return 1 } if {$header != "VIS000"} { puts "Error: The header is not VIS000 ($header) (error1.2)" return 1 } if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error1.3)" return 1 } #----------------------------------------------------------------------- # 2. 'text' + npac subject #----------------------------------------------------------------------- set index [LookForNpac $contents] if {[catch {set subject [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the subject (error2.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error2.2)" return 1 } #----------------------------------------------------------------------- # 3. 'text' + npac Sender's name #----------------------------------------------------------------------- # set index [LookForNpac $contents] set index [LookForNpacReduced $contents] if {[catch {set sender_name [string range $contents 0 [expr $index - 1]]}] \ != 0} { set errMsg "Error while reading the sender name (error3.1)" return 1 } incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error3.2)" return 1 } #----------------------------------------------------------------------- # 4. 'text' + npac Sender's email-address. This can be: # INTERNET:internet_address@asd.asd.sd # 123456,1234 (a compuserve.com address) #----------------------------------------------------------------------- set index [LookForNpac $contents] if {[catch {set sender_address [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the sender's address (error4.1)" return 1 } set result [ProcessAddress sender_address] #----------------------------------------------------------------------- # 5. 'text' + npac Receiver's forum name #----------------------------------------------------------------------- puts "contents is [string range $contents 0 10]" if {($extension == ".msg") || ($extension == ".MSG")} { incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error4bis.1)" return 1 } puts "contents is [string range $contents 0 10]" puts "subject is $subject, sender_name is $sender_name, and sender_address is $sender_address" set index [LookForNpac $contents] puts "index is $index" if {[catch {set forum_address [string range $contents 0 \ [expr $index - 1]]}] != 0} { set errMsg "Error while reading the recv's forum address (error4bis.2)" return 1 } puts " --> The sender's forum address is $forum_address" set result [ProcessAddress forum_address] puts " --> The sender's forum address is $forum_address" } # incr index if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error4.2)" return 1 } #----------------------------------------------------------------------- # 6. '................' # <----- 16 -----> date and time of the message #----------------------------------------------------------------------- # 6.1. byte 4 -> minute in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 2 } else { set index 4 } set minute_ [string range $contents $index $index] if {$minute_ == "\x00"} { set minute 0 } else { scan $minute_ %c minute } # 6.2. byte 5 -> hour in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 3 } else { set index 5 } set hour_ [string range $contents $index $index] if {$hour_ == "\x00"} { set hour 0 } else { scan $hour_ %c hour } # 6.3. byte 6 -> day in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 4 } else { set index 6 } set day_ [string range $contents $index $index] scan $day_ %c day # 6.4. byte 7 -> month in hexadecimal if {($extension == ".msg") || ($extension == ".MSG")} { set index 5 } else { set index 7 } set month_ [string range $contents $index $index] scan $month_ %c month # 6.5. byte 8 -> year in hexadecimal (add 1970) if {($extension == ".msg") || ($extension == ".MSG")} { set index 6 } else { set index 8 } set year_ [string range $contents $index $index] scan $year_ %c year set year [expr $year + 1970] set date "$month\/$day\/$year $hour:$minute" set int_clock [clock scan $date] set date [clock format $int_clock -format "%a, %d %b %Y %H:%M:%S +0100"] set index 16 if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error5.1)" return 1 } #--------------------------------------------------------------------- # 7. '................' # <---- 0-? -----> unknown (useless?) #--------------------------------------------------------------------- set index [LookForText $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error11.2)" return 1 } #--------------------------------------------------------------------- # 8. 'text' Body #--------------------------------------------------------------------- if {[string match "Internet Message Header" $contents] == 1} { set index [LookForNpac $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error12.1)" return 1 } set index [LookForPac $contents] if {[catch {set contents [string range $contents $index end]}] != 0} { set errMsg "Error while reading the message (error12.2)" return 1 } } set body [string range $contents 0 end] while {!([LookForNpacExtended $body] == [string length $body])} { set index [LookForNpacExtended $body] if {[catch {set body [string range $body $index end]}] != 0} { set errMsg "Error while reading the message (error12.3)" return 1 } set index [LookForPac $body] if {[catch {set body [string range $body $index end]}] != 0} { set errMsg "Error while reading the message (error12.4)" return 1 } } regsub -all "@b\n" $body "\n" body regsub -all "@b\n" $body "\n" body regsub -all "@b\n" $body "\n" body if {[string range $body 0 7] == "Spanish+"} { set body [string range $body 8 end] } if {[string range $body 0 6] == "Spanish"} { set body [string range $body 7 end] } #--------------------------------------------------------------------- # 9. Convert the old address and name to the new ones #--------------------------------------------------------------------- set receiver_address "spforum@compuserve.com" set receiver_name "Compuserve Spanish Forum" if {$sender_address == $other_address} { set sender_address $default_receiver_address set sender_name $default_sender_name } if {($sender_name == $other_name) || ($sender_name == "\"$other_name\"")} { set sender_address $default_receiver_address set sender_name $default_sender_name } #puts " --> The subject is $subject" #puts " --> The sender's name is $sender_name" #puts " --> The sender's address is $sender_address" #puts " --> The date is $date" #puts " --> The receiver's name is $receiver_name" #puts " --> The receiver's address is $receiver_address" puts "($sender_name, $sender_address) -> ($receiver_name, $receiver_address), \ \"$subject\", $date" puts " --> The body ([string length $body] characters) starts with \"[string range $body 0 10]\"\n" #----------------------------- # 14. Create the new mail file #----------------------------- set new_message "From $sender_address $date\n" append new_message "Return-Path: $sender_address\n" append new_message "Sender: $sender_address\n" append new_message "Message-ID: <3637B2B0.3D0D8045@unknown.es>\n" append new_message "Date: $date\n" append new_message "From: $sender_name <$sender_address>\n" append new_message "Organization: None\n" append new_message "X-Mailer: c2n.tcl on my old Compuserve email\n" append new_message "X-Accept-Language: es,gl,en\n" append new_message "MIME-Version: 1.0\n" append new_message "To: $receiver_name <$receiver_address>\n" append new_message "Subject: $subject\n" append new_message "Content-Type: text/plain; charset=us-ascii\n" append new_message "Content-Transfer-Encoding: 7bit\n" append new_message "X-Mozilla-Status: 8001\n" append new_message "X-Mozilla-Status2: 00000000\n" append new_message "\n" append new_message "$body\n" append new_message "\n" #----------------------------- # 15. Return #----------------------------- return 0 } #---------------------------------- # 1. Interpret the input parameters #---------------------------------- if {$argc == 1} { if {[lindex $argv 0] == "--write"} { set do_write 1 } else { set do_write 0 } } else { set do_write 0 } #----------------------------------------------------------- # 2. Make the list of files of the directory to be converted #----------------------------------------------------------- set dir_name [lindex [split [pwd] /] end] set list [glob *.{plx,PLX,msg,MSG}] foreach source_name $list { #---------------------------- # 3. For each one of them ... #---------------------------- puts "processing file $source_name" set extension [file extension $source_name] #--------------------------------------- # 4. Read the contents of the input file #--------------------------------------- # 4.1. Check that the file exists if {![file exists $source_name]} { puts "Error: user has not rights to access to file $source_name" exit 1 } # 4.2. Open the file and configure it in DOS mode if {[catch {set file [open $source_name r]} errMsg]} { puts "error opening $source_name ($errMsg)" exit 1 } #fconfigure $file -eofchar {} -translation crlf fconfigure $file -eofchar {} -translation binary # 4.3. Read the contents catch {set contents [read $file]} # 4.4. Close the file close $file #------------------------- # 5. Process the mail file #------------------------- set errMsg "" if {($extension == ".msg") || ($extension == ".MSG")} { set result [ProcessCompuserveMessage $contents errMsg new_message $extension] } else { set result [ProcessCompuserveMail $contents errMsg new_message $extension] } if {$result != 0} { puts "STOP in $source_name ($errMsg)" exit 1 } #------------------------------------------- # 6. Write the contents into the output file #------------------------------------------- if {$do_write == 1} { # 6.1. Open the file and configure it in Unix mode if {[catch {set file [open $dir_name a]} errMsg]} { puts "error opening $dir_name ($errMsg)" exit 1 } fconfigure $file -eofchar {} -translation lf # 6.2. Write the contents puts -nonewline $file $new_message puts -nonewline $file "\n\n" # 6.3. Close the file close $file } } if {$do_write == 1} { #---------------------------- # 7. Clean the ^M in the file #---------------------------- # 7.1. Reopen the file and configure it in Unix mode if {[catch {set file [open $dir_name r]} errMsg]} { puts "error opening $dir_name ($errMsg)" exit 1 } fconfigure $file -eofchar {} -translation crlf # 7.2. Reload it catch {set contents [read $file]} # 7.3. Close the file close $file # 7.4. Delete the file file delete $dir_name # 7.5. Reopen the file and configure it in Unix mode if {[catch {set file [open $dir_name a]} errMsg]} { puts "error opening $dir_name ($errMsg)" exit 1 } fconfigure $file -eofchar {} -translation lf # 7.6. Write the contents puts -nonewline $file $contents # 7.7. Close the file close $file } puts "Done!"