c971d3e7ca
* NEW: Put the publishing configuration and registration in the option dialog. [GB.FORM] * BUG: SwitchButton: Use a "disable" look for ON and OFF state when the Enabled property is FALSE. * NEW: ListEditor is a new control that allows to edit the contents of a ListBox control. [GB.GTK] * BUG: Remove a debugging message. * BUG: TextBox: Postpone the Change event so that replacing the selection raises a unique Change event. [GB.NET.SMTP] * NEW: Add a Content-Disposition header to attachments. [GB.WEB] * NEW: The default response content type is now HTML with UTF-8 charset. git-svn-id: svn://localhost/gambas/trunk@6574 867c0c6c-44f3-4631-809d-bfa615b0a4ec
124 lines
2.6 KiB
Text
124 lines
2.6 KiB
Text
' Gambas class file
|
|
|
|
Public Name As String
|
|
Public Mime As String
|
|
Public Data As String
|
|
Public NameSet As Boolean
|
|
Public Encoding As Integer
|
|
Public Parent As Integer
|
|
Public Boundary As String
|
|
Public Charset As String
|
|
|
|
Public Sub _new(Optional sMime As String, Optional sName As String)
|
|
|
|
Mime = sMime
|
|
Name = sName
|
|
|
|
CheckMime
|
|
|
|
End
|
|
|
|
|
|
Private Sub CheckMime()
|
|
|
|
Dim iPos As Integer
|
|
Dim sCharset As String
|
|
|
|
If Not Mime Then
|
|
Mime = "text/plain;charset=" & System.Charset
|
|
Encoding = Encode.ENC_QUOTED
|
|
Return
|
|
Endif
|
|
|
|
iPos = RInStr(Mime, ";")
|
|
If iPos Then
|
|
If Left(Mime, iPos - 1) Not Like "*/*" Then Goto SYNTAX_ERROR
|
|
sCharset = Trim(Mid$(Mime, iPos + 1))
|
|
If sCharset Not Begins "charset=" Then Goto SYNTAX_ERROR
|
|
Charset = Trim(Mid$(sCharset, 9))
|
|
Else
|
|
If Mime Not Like "*/*" Then Goto SYNTAX_ERROR
|
|
Endif
|
|
|
|
If Mime Begins "text/" Or If Mime Begins "message/" Then
|
|
Encoding = Encode.ENC_QUOTED
|
|
Else If Mime Begins "multipart/" Then
|
|
Encoding = Encode.ENC_7BITS
|
|
Else
|
|
Encoding = Encode.ENC_BASE64
|
|
Endif
|
|
|
|
Return
|
|
|
|
SYNTAX_ERROR:
|
|
|
|
Error.Raise("Incorrect mime type")
|
|
|
|
End
|
|
|
|
Public Sub SetBoundary(hSession As SmtpSession)
|
|
|
|
Dim sBoundary As String
|
|
Dim I As Integer
|
|
Dim sDigit As String = "0123456789ABCDEF"
|
|
|
|
For I = 1 To 16
|
|
sBoundary &= Mid$(sDigit, Int(Rnd(16)) + 1, 1)
|
|
Next
|
|
|
|
Inc hSession._Count
|
|
Boundary = "|" & sBoundary & Hex$(hSession._Count, 2) & "|"
|
|
|
|
End
|
|
|
|
Public Sub SendHeaders(hSession As SmtpSession)
|
|
|
|
Dim sHeader As String
|
|
Dim sErr As String
|
|
|
|
sHeader = "Content-Type: " & Mime
|
|
|
|
If Name Then sHeader &= "; name=\"" & Name & "\""
|
|
|
|
If Mime Begins "text/" Or If Mime Begins "message/" Then
|
|
If Charset Then
|
|
sHeader &= "; charset=\"" & Charset & "\""
|
|
Endif
|
|
Endif
|
|
|
|
If Mime Begins "multipart/" Then
|
|
SetBoundary(hSession)
|
|
sHeader &= "; boundary=\"" & Boundary & "\""
|
|
Endif
|
|
|
|
hSession.Print(sHeader)
|
|
|
|
hSession.Print("Content-Disposition: " & If(Not Name, "inline", "attachment"))
|
|
|
|
If Mime Not Begins "multipart/" Then hSession.Print("Content-Transfer-Encoding: " & Encode.Format(Encoding))
|
|
|
|
hSession.Print("Content-Length: " & Len(Data))
|
|
|
|
hSession.Print
|
|
|
|
Catch
|
|
|
|
sErr = Error.Text
|
|
Error.Raise("Unable to send headers of part #" & hSession.GetPartIndex(Me) & ": " & sErr)
|
|
|
|
End
|
|
|
|
|
|
Public Sub Send(hSession As SmtpSession)
|
|
|
|
Select Case Encoding
|
|
Case Encode.ENC_QUOTED
|
|
Encode.PrintQuoted(hSession.Stream, Data, hSession._Debug)
|
|
Case Encode.ENC_BASE64
|
|
Encode.PrintBase64(hSession.Stream, Data, hSession._Debug)
|
|
Case Else
|
|
hSession.Print(Data)
|
|
End Select
|
|
hSession.Print
|
|
|
|
End
|