/build.properties/src/wsl/fw/msgserver/MsExMailMessage.java

http://mobiledatanow.googlecode.com/ · Java · 95 lines · 68 code · 9 blank · 18 comment · 8 complexity · b78552579d7320c06682dfde80881b4f MD5 · raw file

  1. /** $Id: MsExMailMessage.java,v 1.2 2002/11/12 23:18:41 jonc Exp $
  2. *
  3. * Intermediate MailMessage from the Microsoft Exchange
  4. * Expands attachments if possible
  5. *
  6. */
  7. package wsl.fw.msgserver;
  8. import java.io.FileInputStream;
  9. import wsl.fw.msgserver.converters.WordReader;
  10. import java.io.IOException;
  11. public class MsExMailMessage
  12. extends MailMessage
  13. {
  14. /*
  15. * MS Word markers
  16. */
  17. private static String
  18. MSWORD_EXTENSION = ".doc";
  19. /**
  20. * Constructor
  21. */
  22. public
  23. MsExMailMessage (
  24. String id,
  25. String subject,
  26. String text,
  27. String type,
  28. String sender,
  29. String timeReceived,
  30. String unread,
  31. String senderEmail,
  32. MsExAttachment attachments [])
  33. {
  34. super (
  35. id, subject, expand (text, attachments), type,
  36. sender, "", timeReceived, unread,
  37. senderEmail);
  38. }
  39. /*
  40. * Attempt to Expand attachements
  41. */
  42. private static String
  43. expand (
  44. String text,
  45. MsExAttachment attachments [])
  46. {
  47. String result = text;
  48. if (attachments != null)
  49. {
  50. for (int i = 0; i < attachments.length; i++)
  51. {
  52. if (attachments [i] == null)
  53. {
  54. result += "\n" + "Internal error converting attachment";
  55. } else
  56. {
  57. result += "\n"
  58. + "["
  59. + attachments [i]._name
  60. + " (" + (i + 1) + "/" + attachments.length + ")"
  61. + "]\n";
  62. if (attachments [i]._pathname != null)
  63. {
  64. /*
  65. * Attempt conversions
  66. */
  67. if (attachments [i]._name.endsWith (MSWORD_EXTENSION))
  68. {
  69. try
  70. {
  71. FileInputStream fIn = new FileInputStream (attachments [i]._pathname);
  72. WordReader doc = new WordReader (fIn);
  73. result += doc.getAllText ();
  74. } catch (IOException e)
  75. {
  76. result += "*Internal conversion error: "
  77. + e.getMessage () + "*";
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. return result;
  85. }
  86. }