home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / prm2nsm.zip / convert.java < prev    next >
Text File  |  1998-11-16  |  3KB  |  95 lines

  1.  
  2. import java.io.*;
  3. import java.text.SimpleDateFormat;
  4. import java.util.*;
  5.  
  6. /**
  7.  * This program converts a Post Road Mailer folder to
  8.  * Netscape Communicator format.
  9.  *
  10.  * Attachments, unless they remain in the original message,
  11.  * are not converted.
  12.  *
  13.  * There is some special processing due to the way Mozilla handles
  14.  * incoming mail.  If a line starts with "From " then it must be
  15.  * changed to ">From ".
  16.  *
  17.  * This code also strips blank lines from the end of any mail messages.
  18.  *
  19.  * @author Aaron Williams
  20.  * @version 1.01
  21.  */
  22.  
  23. public class Convert {
  24.  
  25.   public static void main(String args[]) {
  26.     File file = new File(args[0]);
  27.     File inFile;
  28.     String fileList[] = file.list();
  29.     String line;
  30.     int blankcount=0;
  31.     boolean verbose = false;
  32.     for (int i=1; i<args.length; i++) {
  33.       if (args[i].equals("-v"))
  34.     verbose = true;
  35.     }
  36.     SimpleDateFormat gmtDateFormat = 
  37.       new SimpleDateFormat("d MMM yyyy HH:mm:ss", Locale.US);
  38.  
  39.     gmtDateFormat.setTimeZone(TimeZone.getDefault());
  40.     FileInputStream in;
  41.     BufferedReader reader;
  42.     String name;
  43.  
  44.     try {
  45.       for (int i=0; i<fileList.length; i++) {
  46.     name = fileList[i];
  47.     if (!name.toLowerCase().endsWith(".pop")) {
  48.       if (verbose) 
  49.         System.err.println("Skipping "+name);
  50.     } else {
  51.       System.err.print("Converting "+name+" ("+i+" out of "+fileList.length+" files)\t\r");
  52.       inFile = new File(file, name);
  53.       System.out.println("From - "+gmtDateFormat.format(new Date(inFile.lastModified())));
  54.       System.out.println("X-Mozilla-Status: 0000");
  55.       
  56.       in = new FileInputStream(inFile);
  57.       reader = new BufferedReader(new InputStreamReader(in));
  58.       line = reader.readLine();
  59.       while (line != null && line.length() > 0) {
  60.         System.out.println(line);
  61.         if (verbose) {
  62.           if (line.startsWith("Subject:"))
  63.         System.err.println(line);
  64.           if (line.startsWith("From:"))
  65.         System.err.println(line);
  66.         }
  67.         line = reader.readLine();
  68.       }
  69.  
  70.       while (line != null) {
  71.         if (line.length() > 0) {
  72.           if (blankcount > 0) {
  73.         for (int j=0; j<blankcount; j++)
  74.           System.out.println();
  75.         blankcount = 0;
  76.           }
  77.           if (line.startsWith("From "))
  78.         line = ">"+line;
  79.           System.out.println(line);
  80.         } else {
  81.           blankcount++;
  82.         }
  83.         line = reader.readLine();
  84.       }
  85.       // There must be two blank lines at the end of the message
  86.       System.out.println();
  87.       in.close();
  88.     }
  89.       }
  90.     } catch (Exception ex) {
  91.       ex.printStackTrace();
  92.     }
  93.   }
  94. }
  95.