Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Unicode C) Parse MIME Header Fields

Demonstrates how to parse MIME header fields, including Content-Type, Content-Disposition, and Content-Transfer-Encoding.

This example uses a MIME test file located at http://www.chilkatsoft.com/testData/sampleMime2.txt. It contains the following MIME:

Content-Type: multipart/mixed;
 boundary="------------080707010302060306060800";

This is a multi-part message in MIME format.

--------------080707010302060306060800
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is the plain-text body.
--------------080707010302060306060800
Content-Disposition: attachment; filename="starfish.gif";
Content-Transfer-Encoding: base64
Content-Type: image/gif; name="starfish.gif";

R0lGODlhIAAgAPcAAP///+/v7/f39+/n5/fv7//39/fn597OzufW1tbGxs69vffe3u/W1salpZQQ
EIQYEJwQCJQYCJwYCM6clL2Ee5wpGIwhEK0YANatpdalnHMYCKUhCJQYAKUYAM6Ec5QhCJwhCPfW
zu/Oxta1rb17a6UhAK0hAPe9rb2Ec7V7a71rUpwpCL0xCJwhAOfOxta9tcatpdallM6cjMaUhK1C
IZwxELU5EK0xCLUxCN61pcacjK1rUrVaOaVKKZxCIZwxCKUxCL05CLUxAM6llO+1nMZzUr1rSrVS
KaVCGK1CGLVCEJQxCK05CLU5CIwpAKUxAK0xAM69tffWxrVrSrVaMbVKGMZKEL1CCLU5AP/v597O
xufGtcallNaljLWEa96ce9aUc717Wq1aMcZjMbVaKbVSIa1KGL1SGJw5CK1CCLVCCMZKCM5KCMZC
APfn3tbGvc57Ss5aGMZSENZaEL1KCM5SCLVCAMZKAPfezvfOte/GrdatlN6cc9aEUr1rOc5jIdZj
GL1SEM5aELVKCMZSCNZaCL1KAOfOvc57Qs5jGNZjEM5aCMZSAN5aAO/OtefGrcZjGM5jEN5rELVS
CMZaCN5jCOdrCM5aAO/Gpc5rGMZjENZrEN5jAOdrAOfe1t6MQtZ7Kd57IdZzGM5rEMZjCNZrCM5j
ANbOxu/Wve+9jPe9hO+1e+etc85zGO+EGMZrENZzEM5rCN5zCO97COdzAO/n3u+1c+ecSt6UQs57
Ie+MIdZ7GOeEGM5zEO+EELVjCOd7CO+ECOd7AO/Ope+tWuelUu+UKeeMGOeEEO+MEOeECO+EAO/G
jO+cKfeUEO+MCO+tSuecMeeUGN6MEOeMCO+UCO+tQuelOe+lMe+lKe+cGOeUEO+cEOeUCN6MAO+U
AOe9c/e1Oe+lId6UEO+cCPe9Qve1Me+lEOecCO+lCOe1Su+1OeelGO+tGPetCPetAO+9Qve1GO+1
EPe9CPe9APf37+fv5/f//+/v9/fv9+fe5+/e5869xufW3t7GzgAAACwAAAAAIAAgAAAI/wABCBxI
sKDBgwgTFgCwMKHDhwyHYWoIsWIBZsdyHaoIcaGbaNQ0ZeBYEROvV0pmCCDp8B4rZaOUcGHpcIEx
aqPMYLjHMcsCAwgxkRv3q8wLnhAdfWpmDRwqAgQFEEvHLlCZNxwfpVmkDJ04dczc3LsXQtq4XWh8
aGH48F49FDUC9UInT941W6luCUOWyQmSLST3eUnChNS4c9SooQuGDNkrIIrA1MqXr0A+AyFC4Kln
kMAQKljotJJGDZklS9PkyEHGLZu1ctbCmWvXThurfAbvHSii5kegxpYqtRpEKFnid/TSneu2LRYh
P/0Q1tJRgYOZV71UL5LEK1KiV68yVf+xgaOKmAZICd5bmA8FEyZQlMjRRAhQGQv4QQSJL8ZLFHwP
6aFIJXNIEkggcgQhwYIlKEFFGDKcEgBCBVCkByC0IAMJGnSAYsUNEmzAgw4HBJBeQisZcAswjqGh
wQeBKGIFFD0ocCJE9diyjTKRLPHBAx/cEAcdgxgx4Vg3HnSPKs4E00sNEYDwgQksQDLJIohMSJIj
ugSTCRA/ILFDCjTckUkrpYiCAEluYCMLJCsoMQUM9gjQRSSL7CLJJjmQxMw3kQChxA78IFULHIK0
MgonXyR5UAHWVBKIEmEcUJAIYxgSSSF94AZRPrgsQgUF0RmUgWpy/LFmRYdMkACAANwrWA8cbAhi
RZ8cjRWro0QEEsQVGTiKkLAM5QNGFWrAQFNLBIzABQPLRktQQAA7

--------------080707010302060306060800--

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkMimeW.h>

void ChilkatSample(void)
    {
    HCkMimeW mime;
    BOOL success;
    HCkMimeW part2;
    const wchar_t *filename;
    const wchar_t *name;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    mime = CkMimeW_Create();

    // Load the sampleMime2.txt file into the MIME object.
    // (This file is available at http://www.chilkatsoft.com/testData/sampleMime2.txt )

    success = CkMimeW_LoadMimeFile(mime,L"sampleMime2.txt");
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        return;
    }

    // The GIF image is the 2nd sub-part located directly under the
    // top-level MIME node.  Indexing begins at 0, therefore the 2nd
    // sub-part is at index 1.

    part2 = CkMimeW_GetPart(mime,1);

    // -------------------------------
    // Content-Disposition
    // -------------------------------
    // In this example, the Content-Disposition header field
    // contains this value:
    // attachment; filename="starfish.gif"

    // To get the "filename", call GetHeaderFieldAttribute
    // Header field names and attribute names are case insensitive.
    filename = CkMimeW_getHeaderFieldAttribute(part2,L"Content-Disposition",L"filename");
    wprintf(L"Filename: %s\n",filename);

    // Because the "filename" is so often accessed, it is also available
    // by accessing the "Filename" property:
    wprintf(L"Filename: %s\n",CkMimeW_filename(part2));

    // The disposition (without attributes) which in this case 
    // is the string "attachment" is accessed via the Disposition property:
    wprintf(L"Disposition: %s\n",CkMimeW_disposition(part2));

    // To get the full value of the Content-Disposition header field,
    // call GetHeaderField.
    wprintf(L"Content-Disposition: %s\n",CkMimeW_getHeaderField(part2,L"Content-Disposition"));

    // -------------------------------
    // Content-Type
    // -------------------------------
    // In this example, the Content-Type header field
    // contains this value:
    // image/gif; name="starfish.gif"

    // To get the "name", call GetHeaderFieldAttribute
    name = CkMimeW_getHeaderFieldAttribute(part2,L"Content-Type",L"name");
    wprintf(L"Content-Type name: %s\n",name);

    // Because the "name" is so often accessed, it is also available
    // by accessing the "Name" property:
    wprintf(L"Content-Type name: %s\n",CkMimeW_name(part2));

    // The content-type without attributes is available in the
    // ContentType property:
    wprintf(L"Content-Type: %s\n",CkMimeW_contentType(part2));

    // To get the full value of the Content-Type header field,
    // call GetHeaderField.
    wprintf(L"Content-Type: %s\n",CkMimeW_getHeaderField(part2,L"Content-Type"));

    // -------------------------------
    // Content-Transfer-Encoding
    // -------------------------------

    // The Encoding property contains the value of the
    // Content-Transfer-Encoding property. 
    // Calling GetHeaderField("Content-Transfer-Encoding") is
    // equivalent to accessing the Encoding property:
    wprintf(L"Content-Transfer-Encoding: %s\n",CkMimeW_encoding(part2));
    wprintf(L"Content-Transfer-Encoding: %s\n",CkMimeW_getHeaderField(part2,L"Content-Transfer-Encoding"));

    CkMimeW_Dispose(part2);

    wprintf(L"Finished.\n");


    CkMimeW_Dispose(mime);

    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.