iMail aliases.txt to csv converter.

This will convert iMails aliases.txt file to a csv to import into outlook or similar.

'Convert imail alias.txt to something that is not useless.

Const ForReading = 1, ForWriting = 2, ForAppending = 8 

Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("aliases.txt", ForReading) 

Set filetxtOUT = filesys.OpenTextFile("aliasesOUT.csv", ForWriting, TRUE) 
Set filetxtBAD = filesys.OpenTextFile("aliasesBAD.txt", ForWriting, TRUE) 

'get name
Set nameRegex = New RegExp
nameRegex.IgnoreCase = True
nameRegex.Pattern = """(.*?)"""

'get email
Set emailRegex = New RegExp
emailRegex.IgnoreCase = True
emailRegex.Pattern = "<(.*?)>"

filetxtOUT.WriteLine "Name, Email Address"
Do until filetxt.AtEndofStream
 txtline = filetxt.Readline
 
 'get name if 0 name is bad
 Set namevar = nameRegex.Execute(txtline)
 if namevar.Count = 0 then
  name = ""
 else
  name = namevar(0).Value
 end if

 'get email address if 0 email is bad
 Set emailvar = emailRegex.Execute(txtline)
 if emailvar.Count = 0 then
  email = ""
 else
  email = emailvar(0).Value
 end if

 'record bad lines to bad file
 if namevar.count = 0 AND emailvar.count = 0 then
  filetxtBAD.writeline txtline
 else
  if len(name) > 2 then
   filetxtOUT.writeline name & "," & email
  else
   filetxtOUT.writeline """" & name & """," & email
  end if
 end if
 
  
  
loop

filetxt.Close
msgbox "DONE"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.