By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,372 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,372 IT Pros & Developers. It's quick & easy.

Reading emails...

P: n/a
I have been developing a program that takes a database of
email bodies and then displays them to the user in a
similar way to Outlook Express would.

The problem I'm having is showing only the message of the
email and not some of the unnecessary jargon of the
message body.

Does anyone know of a really simple and clean way to
display only the message of the email body.

Below is a copy of the code that I'm currently using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub MessageList_SelectedIndexChanged(ByVal
  2. sender As System.Object, ByVal e As System.EventArgs)
  3. Handles MessageList.SelectedIndexChanged
  4. Try
  5. 'Lets make sure that we're not selecting
  6. multiple emails to view, as this would be a bit difficult.
  7. If (MessageList.SelectedItems.Count <> 0) And
  8. (MessageList.SelectedItems.Count = 1) Then
  9. 'Connector/ODBC 3.51 connection string
  10. Dim MyConString As String = "DRIVER=
  11. {MySQL ODBC 3.51 Driver};" & _
  12. "SERVER=localhost;" & _
  13. "DATABASE=temp;" & _
  14. "UID=temp;" & _
  15. "PASSWORD=temp;" & _
  16. "OPTION=3;"
  17.  
  18. 'Connection
  19.  
  20. Dim MyConnection As New
  21. Odbc.OdbcConnection(MyConString)
  22. MyConnection.Open()
  23. Dim MyCommand As New Odbc.OdbcCommand
  24. MyCommand.Connection = MyConnection
  25.  
  26. 'Select the specific email using the data
  27. taken from the selected entry of the Messages List view
  28. box.
  29. If iFolder_Id <> "Deleted" Then
  30. MyCommand.CommandText = "SELECT *
  31. FROM webmail_mails WHERE reciever='" & iUser_Id & "' AND
  32. folder='" & iFolder_Id & "' AND subject='" &
  33. MessageList.SelectedItems(0).Text & "' LIMIT 1"
  34. Else
  35. MyCommand.CommandText = "SELECT *
  36. FROM webmail_mails WHERE reciever='" & iUser_Id & "' AND
  37. trashed='true' AND subject='" & MessageList.SelectedItems
  38. (0).Text & "' LIMIT 1"
  39. End If
  40. Console.WriteLine(MyCommand.CommandText)
  41. Dim MyDataReader As Odbc.OdbcDataReader
  42. MyDataReader = MyCommand.ExecuteReader
  43. (CommandBehavior.Default)
  44.  
  45. 'Some variables being declared.
  46. Dim sSubject As String
  47. Dim sSender As String
  48. Dim sSenderName As String
  49. Dim sMsg As String
  50. Dim dDate As String
  51. Dim bAttachments As Boolean
  52.  
  53. While MyDataReader.Read
  54. 'Assign the data to the variables
  55. sSubject = MyDataReader
  56. ("subject").ToString
  57. sSender = MyDataReader
  58. ("sender").ToString
  59. sSenderName = MyDataReader
  60. ("sendername").ToString
  61. sMsg = MyDataReader("body").ToString
  62. dDate = MyDataReader("date").ToString
  63. dDate = dDate.Substring(5, 20)
  64. bAttachments = True
  65. End While
  66.  
  67. 'Display the message in a formatted way.
  68. 'First we need to find out what content
  69. type the email is
  70. Dim strString As String = sMsg
  71. Dim strString2 As String = sMsg
  72. Dim type As Integer
  73. Dim start As Integer
  74. Dim finish As Integer
  75. type = strString.IndexOf("Content-Type:")
  76.  
  77.  
  78. Dim content As String
  79. Dim content2 As String
  80.  
  81. content = sMsg.Substring(type + 14, 11)
  82. 'Now that we have the content type just
  83. make it all lower for checking.
  84. content = content.ToLower
  85.  
  86. 'Is the content type:
  87. 'Text/Plain?
  88. If content = "text/plain;" Then
  89. start = strString.IndexOf(vbNewLine &
  90. vbNewLine)
  91. content2 = sMsg.Substring(start)
  92. content2 = content2.Trim
  93.  
  94. email.Text = content2
  95. End If
  96. 'Multipart/m?
  97. If content = "multipart/m" Then
  98. start = strString.IndexOf("<html>")
  99. 'MessageBox.Show(start)
  100. If start < 1 Then
  101. 'This means that although it's
  102. Multipart it may be <HTML>
  103. start = strString.IndexOf
  104. ("<HTML>")
  105. 'MessageBox.Show(start)
  106. If start < 1 Then
  107. 'There is no message!
  108. email.Text = ""
  109. Else
  110. finish = strString.IndexOf
  111. ("</HTML>")
  112. content2 = sMsg.Substring
  113. (start, ((finish - start) + 7))
  114. email.Text = content2
  115. End If
  116. Else
  117. finish = strString.IndexOf
  118. ("</html>")
  119. content2 = sMsg.Substring(start,
  120. ((finish - start) + 7))
  121. email.Text = content2
  122. End If
  123. End If
  124. 'Multipart/a?
  125. If content = "multipart/a" Then
  126. start = strString.IndexOf("<html>")
  127. 'MessageBox.Show(start)
  128. If start < 1 Then
  129. 'This means that although it's
  130. Multipart it may be <HTML>
  131. start = strString.IndexOf
  132. ("<HTML>")
  133. 'MessageBox.Show(start)
  134. If start < 1 Then
  135. 'There is no message!
  136. email.Text = "[There is no
  137. message to display.]"
  138. Else
  139. finish = strString.IndexOf
  140. ("</HTML>")
  141. content2 = sMsg.Substring
  142. (start, ((finish - start) + 7))
  143. email.Text = content2
  144. End If
  145. Else
  146. finish = strString.IndexOf
  147. ("</html>")
  148. content2 = sMsg.Substring(start,
  149. ((finish - start) + 7))
  150. email.Text = content2
  151. End If
  152. End If
  153. 'Text/HTML?
  154. If content = "text/html; " Then
  155. start = strString.IndexOf("<html>")
  156. 'MessageBox.Show(start)
  157. If start < 1 Then
  158. 'This means that although it's
  159. Multipart it may be <HTML>
  160. start = strString.IndexOf
  161. ("<HTML>")
  162. 'MessageBox.Show(start)
  163. If start < 1 Then
  164. 'There is no message!
  165. email.Text = "[There is no
  166. message to display.]"
  167. Else
  168. finish = strString.IndexOf
  169. ("</HTML>")
  170. content2 = sMsg.Substring
  171. (start, ((finish - start) + 7))
  172. email.Text = content2
  173. End If
  174. Else
  175. finish = strString.IndexOf
  176. ("</html>")
  177. content2 = sMsg.Substring(start,
  178. ((finish - start) + 7))
  179. email.Text = content2
  180. End If
  181. End If
  182.  
  183. 'Now lets add the data to the infobar
  184. infobar.Text = "Subject: " & sSubject &
  185. vbNewLine & "From:     " & sSenderName & vbNewLine
  186. & "Date:      " & dDate
  187. 'infobar2.Text = "From: " & sSenderName
  188. 'Close the connection and the reader
  189. MyDataReader.Close()
  190. MyCommand.Connection.Close()
  191.  
  192. End If
  193.  
  194. 'The following deals with any errors that
  195. have occured in the process of the above.
  196. 'At present they only output to the console.
  197.  
  198. 'Catch ODBC Exception
  199. Catch MyOdbcException As Odbc.OdbcException
  200. Dim i As Integer
  201. Console.WriteLine(MyOdbcException.ToString)
  202.  
  203. 'Catch program exception
  204. Catch MyException As Exception
  205. Console.WriteLine(MyException.ToString)
  206. End Try
  207. End Sub
  208.  
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
What do you mean "what objects to you refference?"?
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.