Sample code for 30+ languages & platforms
PowerBuilder

Enumerate MIME Header Field Values

See more MIME Examples

Demonstrates the Chilkat Mime.GetHeaderFieldValue method, which returns the unfolded value of the header-field occurrence at a zero-based index. The only argument is the index. Continuation (folded) lines are combined into a single value.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: Paired with GetHeaderFieldName, this lets you list every header as name/value pairs, including duplicates. A useful detail is unfolding: long headers are wrapped across multiple physical lines in the raw message, and this recombines them into the single logical value the header actually represents, so you never have to reassemble continuation lines yourself.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Mime
long n
long i
string ls_FieldName
string ls_FieldValue

li_Success = 0

loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
    destroy loo_Mime
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Mime.LoadMimeFile("qa_data/message.eml")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

//  Iterate the header fields by index and print each name and unfolded value.  Continuation lines
//  (folded headers) are combined into a single value.
n = loo_Mime.NumHeaderFields

for i = 0 to n - 1
    ls_FieldName = loo_Mime.GetHeaderFieldName(i)
    if loo_Mime.LastMethodSuccess = 0 then
        Write-Debug loo_Mime.LastErrorText
        destroy loo_Mime
        return
    end if

    ls_FieldValue = loo_Mime.GetHeaderFieldValue(i)
    if loo_Mime.LastMethodSuccess = 0 then
        Write-Debug loo_Mime.LastErrorText
        destroy loo_Mime
        return
    end if

    Write-Debug ls_FieldName + ": " + ls_FieldValue
next


destroy loo_Mime