Mht C Library Reference
Mht
Chilkat MHT can generate email objects from HTML files and URLs, and convert HTML to MHT or EML files.
Create/Dispose
HCkMht CkMht_Create(void);
Creates an instance of the CkMht object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.
void CkMht_Dispose(HCkMht handle);
Objects created by calling CkMht_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.
C "Properties"
void CkMht_getBaseUrl(HCkMht cHandle, HCkString retval); void CkMht_putBaseUrl(HCkMht cHandle, const char *newVal);
When processing an HTML file or string (not a website URL), this defines the base URL to be used when converting relative HREFs to absolute HREFs.
long CkMht_getConnectTimeout(HCkMht cHandle); void CkMht_putConnectTimeout(HCkMht cHandle, long newVal);
The amount of time in seconds to wait before timing out when connecting to an HTTP server. The default value is 10 seconds.
void CkMht_getDebugHtmlAfter(HCkMht cHandle, HCkString retval); void CkMht_putDebugHtmlAfter(HCkMht cHandle, const char *newVal);
A filename to save the result HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.
void CkMht_getDebugHtmlBefore(HCkMht cHandle, HCkString retval); void CkMht_putDebugHtmlBefore(HCkMht cHandle, const char *newVal);
A filename to save the input HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.
BOOL CkMht_getDebugTagCleaning(HCkMht cHandle); void CkMht_putDebugTagCleaning(HCkMht cHandle, BOOL newVal);
When true causes the Mht class to be much more verbose in its logging. The default is false.
BOOL CkMht_getEmbedImages(HCkMht cHandle); void CkMht_putEmbedImages(HCkMht cHandle, BOOL newVal);
Controls whether images are embedded in the MHT/EML, or whether the IMG SRC attributes are left as external URL references. If false, the IMG SRC tags are converted to absolute URLs (if necessary) and the images are not embedded within the MHT/EML.
BOOL CkMht_getEmbedLocalOnly(HCkMht cHandle); void CkMht_putEmbedLocalOnly(HCkMht cHandle, BOOL newVal);
If true, only images found on the local filesystem (i.e. links to files) will be embedded within the MHT.
BOOL CkMht_getFetchFromCache(HCkMht cHandle); void CkMht_putFetchFromCache(HCkMht cHandle, BOOL newVal);
If true, page parts such as images, style sheets, etc. will be fetched from the disk cache if possible. The disk cache root may be defined by calling AddCacheRoot. The default value is false.
long CkMht_getHeartbeatMs(HCkMht cHandle); void CkMht_putHeartbeatMs(HCkMht cHandle, long newVal);
The time interval, in milliseconds, between AbortCheck event callbacks. The heartbeat/AbortCheck provides a means for an application to abort any MHT method before completion.
The default value is 0, which means that no AbortCheck events will be fired.
BOOL CkMht_getIgnoreMustRevalidate(HCkMht cHandle); void CkMht_putIgnoreMustRevalidate(HCkMht cHandle, BOOL newVal);
Some HTTP responses contain a "Cache-Control: must-revalidate" header. If this is present, the server is requesting that the client always issue a revalidate HTTP request instead of serving the page directly from cache. If IgnoreMustRevalidate is set to true, then Chilkat MHT will serve the page directly from cache without revalidating until the page is no longer fresh. (assuming that FetchFromCache is set to true)
The default value of this property is false.
BOOL CkMht_getIgnoreNoCache(HCkMht cHandle); void CkMht_putIgnoreNoCache(HCkMht cHandle, BOOL newVal);
Some HTTP responses contain headers of various types that indicate that the page should not be cached. Chilkat MHT will adhere to this unless this property is set to true.
The default value of this property is false.
void CkMht_getLastErrorHtml(HCkMht cHandle, HCkString retval);
To be documented soon.Error information in HTML format for the last method called.
void CkMht_getLastErrorText(HCkMht cHandle, HCkString retval);
Error information in plain-text format for the last method called.
void CkMht_getLastErrorXml(HCkMht cHandle, HCkString retval);
Error information in XML format for the last method called.
BOOL CkMht_getNoScripts(HCkMht cHandle); void CkMht_putNoScripts(HCkMht cHandle, BOOL newVal);
Only applies when creating MHT files. Scripts are always removed when creating EML or emails from HTML. If set to true, then all scripts are removed, if set to false (the default) then scripts are not removed.
BOOL CkMht_getNtlmAuth(HCkMht cHandle); void CkMht_putNtlmAuth(HCkMht cHandle, BOOL newVal);
Setting this property to true causes the MHT component to use NTLM authentication (also known as IWA -- or Integrated Windows Authentication) when authentication with an HTTP server.
The default value of this property is false.
long CkMht_getNumCacheLevels(HCkMht cHandle); void CkMht_putNumCacheLevels(HCkMht cHandle, long newVal);
The number of directory levels to be used under each cache root. The default is 0, meaning that each cached item is stored in a cache root directory. A value of 1 causes each cached page to be stored in one of 255 subdirectories named "0","1", "2", ..."255" under a cache root. A value of 2 causes two levels of subdirectories ("0..255/0..255") under each cache root. The MHT control automatically creates subdirectories as needed. The reason for mutliple levels is to alleviate problems that may arise when huge numbers of files are stored in a single directory. For example, Windows Explorer does not behave well when trying to display the contents of directories with thousands of files.
long CkMht_getNumCacheRoots(HCkMht cHandle);
The number of cache roots to be used for the disk cache. This allows the disk cache spread out over multiple disk drives. Each cache root is a string indicating the drive letter and directory path. For example, "E:\Cache". To create a cache with four roots, call AddCacheRoot once for each directory root.
BOOL CkMht_getPreferMHTScripts(HCkMht cHandle); void CkMht_putPreferMHTScripts(HCkMht cHandle, BOOL newVal);
This property provides a means for the noscript option to be selected when possible. If PreferMHTScripts = false, then scripts with noscript alternatives are removed and the noscript content is kept. If true (the default), then scripts are preserved and the noscript options are discarded.
void CkMht_getProxy(HCkMht cHandle, HCkString retval); void CkMht_putProxy(HCkMht cHandle, const char *newVal);
(Optional) A proxy host:port if a proxy is necessary to access the Internet. The proxy string should be formatted as "hostname:port", such as "www.chilkatsoft.com:100".
void CkMht_getProxyLogin(HCkMht cHandle, HCkString retval); void CkMht_putProxyLogin(HCkMht cHandle, const char *newVal);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.
void CkMht_getProxyPassword(HCkMht cHandle, HCkString retval); void CkMht_putProxyPassword(HCkMht cHandle, const char *newVal);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.
long CkMht_getReadTimeout(HCkMht cHandle); void CkMht_putReadTimeout(HCkMht cHandle, long newVal);
The amount of time in seconds to wait before timing out when reading from an HTTP server. The ReadTimeout is the amount of time that needs to elapse while no additional data is forthcoming. During a long data transfer, if the data stream halts for more than this amount, it will timeout. Otherwise, there is no limit on the length of time for the entire data transfer.
The default value is 20 seconds.
void CkMht_getSocksHostname(HCkMht cHandle, HCkString retval); void CkMht_putSocksHostname(HCkMht cHandle, const char *newVal);
The SOCKS4/SOCKS5 hostname or IPv4 address (in dotted decimal notation). This property is only used if the SocksVersion property is set to 4 or 5).
void CkMht_getSocksPassword(HCkMht cHandle, HCkString retval); void CkMht_putSocksPassword(HCkMht cHandle, const char *newVal);
The SOCKS5 password (if required). The SOCKS4 protocol does not include the use of a password, so this does not apply to SOCKS4.
int CkMht_getSocksPort(HCkMht cHandle); void CkMht_putSocksPort(HCkMht cHandle, int newVal);
The SOCKS4/SOCKS5 proxy port. The default value is 1080.
This property only applies if a SOCKS proxy is used (if the SocksVersion property is set to 4 or 5).
void CkMht_getSocksUsername(HCkMht cHandle, HCkString retval); void CkMht_putSocksUsername(HCkMht cHandle, const char *newVal);
The SOCKS4/SOCKS5 proxy username. This property is only used if the SocksVersion property is set to 4 or 5).
int CkMht_getSocksVersion(HCkMht cHandle); void CkMht_putSocksVersion(HCkMht cHandle, int newVal);
SocksVersion
May be set to one of the following integer values:
0 - No SOCKS proxy is used. This is the default.
4 - Connect via a SOCKS4 proxy.
5 - Connect via a SOCKS5 proxy.
BOOL CkMht_getUpdateCache(HCkMht cHandle); void CkMht_putUpdateCache(HCkMht cHandle, BOOL newVal);
Controls whether the cache is automatically updated with the responses from HTTP GET requests. If true, the disk cache is updated, if false (the default), the cache is not updated.
BOOL CkMht_getUseCids(HCkMht cHandle); void CkMht_putUseCids(HCkMht cHandle, BOOL newVal);
Controls whether CID URLs are used for embedded references when generating MHT or EML documents. If UseCids is false (the default), then URLs are left unchanged and the embedded items will contain "content-location" headers that match the URLs in the HTML. If true, CIDs are generated and the URLs within the HTML are replaced with "CID:" links.
BOOL CkMht_getUseFilename(HCkMht cHandle); void CkMht_putUseFilename(HCkMht cHandle, BOOL newVal);
If true, a "filename" attribute is added to each Content-Disposition MIME header field for each embedded item (image, style sheet, etc.). If false, then no filename attribute is added.
The default value of this property is true.
BOOL CkMht_getUseIEProxy(HCkMht cHandle); void CkMht_putUseIEProxy(HCkMht cHandle, BOOL newVal);
If true, the proxy host/port used by Internet Explorer will also be used by Chilkat MHT.
BOOL CkMht_getUseInline(HCkMht cHandle); void CkMht_putUseInline(HCkMht cHandle, BOOL newVal);
If true, an "inline" attribute is added to each Content-Disposition MIME header field for each embedded item (image, style sheet, etc.). If false, then no inline attribute is added.
The default value of this property is true.
BOOL CkMht_getUtf8(HCkMht cHandle); void CkMht_putUtf8(HCkMht cHandle, BOOL newVal);
When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.
void CkMht_getVersion(HCkMht cHandle, HCkString retval);
The version of the component, such as "1.0.0"
void CkMht_getWebSiteLogin(HCkMht cHandle, HCkString retval); void CkMht_putWebSiteLogin(HCkMht cHandle, const char *newVal);
(Optional) Specifies the login if a a Web page is accessed that requires a login
void CkMht_getWebSitePassword(HCkMht cHandle, HCkString retval); void CkMht_putWebSitePassword(HCkMht cHandle, const char *newVal);
Optional) Specifies the password if a a Web page is accessed that requires a login and password
C "Methods"
void CkMht_AddCacheRoot(HCkMht cHandle, const char *dir);
If disk caching is used, this must be called once for each cache root. For example, if the cache is spread across D:\cacheRoot, E:\cacheRoot, and F:\cacheRoot, an application would setup the cache object by calling AddRoot three times -- once with "D:\cacheRoot", once with "E:\cacheRoot", and once with "F:\cacheRoot".
void CkMht_AddCustomHeader(HCkMht cHandle, const char *name, const char *value);
Adds a custom HTTP header to all HTTP requests sent by the MHT component. To add multiple header fields, call this method once for each custom header.
void CkMht_AddExternalStyleSheet(HCkMht cHandle, const char *url);
(This method rarely needs to be called.) Includes an additional style sheet that would not normally be included with the HTML. This method is provided for cases when style sheet names are constructed and dynamically included in Javascript such that MHT .NET cannot know beforehand what stylesheet to embed. MHT .NET by default downloads and embeds all stylesheets externally referenced by the HTML
void CkMht_ClearCustomHeaders(HCkMht cHandle);
Removes all custom headers that may have accumulated from previous calls to AddCustomHeader.
void CkMht_ExcludeImagesMatching(HCkMht cHandle, const char *pattern);
(This method rarely needs to be called.) Tells Chilkat MHT .NET to not embed any images whose URL matches a pattern. Sometimes images can be referenced within style sheets and not actually used when rendering the page. In cases like those, the image will appear as an attachment in the HTML email. This feature allows you to explicitly remove those images from the email so no attachments appear.
BOOL CkMht_GetAndSaveEML(HCkMht cHandle, const char *url, const char *emlFilename);
Creates an EML file from a web page or HTML file. All external images and style sheets are downloaded and embedded in the EML file. Returns TRUE for success, FALSE for failure.
BOOL CkMht_GetAndSaveMHT(HCkMht cHandle, const char *url, const char *mhtFilename);
Creates an MHT file from a web page or local HTML file. All external images, scripts, and style sheets are downloaded and embedded in the MHT file. Returns TRUE for success, FALSE for failure.
BOOL CkMht_GetAndZipEML(HCkMht cHandle, const char *url, const char *zipEntryFilename, const char *zipFilename);
Creates an EML file from a web page or HTML file, compresses, and appends to a new or existing Zip file. All external images and style sheets are downloaded and embedded in the EML. Returns TRUE for success, FALSE for failure.
BOOL CkMht_GetAndZipMHT(HCkMht cHandle, const char *url, const char *zipEntryFilename, const char *zipFilename);
Creates an MHT file from a web page or HTML file, compresses, and appends to a new or existing Zip file. All external images and style sheets are downloaded and embedded in the MHT. Returns TRUE for success, FALSE for failure.
BOOL CkMht_GetCacheRoot(HCkMht cHandle, int index, HCkString str);
Returns the Nth cache root (indexing begins at 0). Cache roots are set by calling AddCacheRoot one or more times.
BOOL CkMht_GetEML(HCkMht cHandle, const char *url, HCkString eml);
Creates EML from a web page or HTML file, and returns the EML (MIME) message data as a string.
HCkEmail CkMht_GetEmail(HCkMht cHandle, const char *url);
Downloads a web page and creates an HTML Email object that can be sent using Chilkat Email component. Embedded within the email are all the images and style sheets referenced from the web page.
Returns a null reference on failure. Returns a null reference on failure
BOOL CkMht_GetMHT(HCkMht cHandle, const char *url, HCkString mht);
Creates MHT from a web page or local HTML file, and returns the MHT (MIME) message data as a string
HCkMime CkMht_GetMime(HCkMht cHandle, const char *url);
Converts a web Page (URL) or HTML file to a Chilkat Mime object. Returns a null reference on failure.
BOOL CkMht_HtmlToEML(HCkMht cHandle, const char *htmlText, HCkString eml);
Creates an in-memory EML string from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML string that is returned. Returns TRUE for success, FALSE for failure.
BOOL CkMht_HtmlToEMLFile(HCkMht cHandle, const char *html, const char *emlFilename);
Creates an EML file from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML file. Returns TRUE for success, FALSE for failure.
HCkEmail CkMht_HtmlToEmail(HCkMht cHandle, const char *htmlText);
Creates an email object from an in-memory HTML string. Returns a null reference on failure. Returns a null reference on failure
BOOL CkMht_HtmlToMHT(HCkMht cHandle, const char *htmlText, HCkString mht);
Creates an in-memory MHT web archive from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT string.
BOOL CkMht_HtmlToMHTFile(HCkMht cHandle, const char *html, const char *mhtFilename);
Creates an MHT file from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT file. Returns TRUE for success, FALSE for failure.
BOOL CkMht_IsUnlocked(HCkMht cHandle);
Returns true if the MHT component is unlocked.
void CkMht_RemoveCustomHeader(HCkMht cHandle, const char *name);
Removes a custom header by header field name.
void CkMht_RestoreDefaults(HCkMht cHandle);
Restores the default property settings.
BOOL CkMht_SaveLastError(HCkMht cHandle, const char *filename);
Saves the last error information to an XML formatted file.
BOOL CkMht_UnlockComponent(HCkMht cHandle, const char *unlockCode);
Unlocks the component allowing for the full functionality to be used. Returns true if the unlock code is valid.
BOOL CkMht_UnpackMHT(HCkMht cHandle, const char *mhtFilename, const char *unpackDir, const char *htmlFilename, const char *partsSubDir);
Unpacks the contents of a MHT file. The destination directory is specified by unpackDir. The name of the HTML file created is specified by outputHtmlFilename, and supporting files (images, javascripts, etc.) are created in partsSubDir, which is automatically created if it does not already exist. Returns TRUE for success, FALSE for failure.
BOOL CkMht_UnpackMHTString(HCkMht cHandle, const char *mhtContents, const char *unpackDir, const char *htmlFilename, const char *partsSubDir);
Same as UnpackMHT, except the MHT is passed in as an in-memory string. Returns TRUE for success, FALSE for failure.
const char *CkMht_baseUrl(HCkMht cHandle);
When processing an HTML file or string (not a website URL), this defines the base URL to be used when converting relative HREFs to absolute HREFs.
const char *CkMht_debugHtmlAfter(HCkMht cHandle);
A filename to save the result HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.
const char *CkMht_debugHtmlBefore(HCkMht cHandle);
A filename to save the input HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.
const char *CkMht_getCacheRoot(HCkMht cHandle, int index);
Returns the Nth cache root (indexing begins at 0). Cache roots are set by calling AddCacheRoot one or more times.
const char *CkMht_getEML(HCkMht cHandle, const char *url);
Creates EML from a web page or HTML file, and returns the EML (MIME) message data as a string.
const char *CkMht_getMHT(HCkMht cHandle, const char *url);
Creates MHT from a web page or local HTML file, and returns the MHT (MIME) message data as a string
const char *CkMht_htmlToEML(HCkMht cHandle, const char *htmlText);
Creates an in-memory EML string from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML string that is returned. Returns TRUE for success, FALSE for failure.
const char *CkMht_htmlToMHT(HCkMht cHandle, const char *htmlText);
Creates an in-memory MHT web archive from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT string.
const char *CkMht_lastErrorHtml(HCkMht cHandle);
Error information in HTML format for the last method called.
const char *CkMht_lastErrorText(HCkMht cHandle);
Error information in plain-text format for the last method called.
const char *CkMht_lastErrorXml(HCkMht cHandle);
Error information in XML format for the last method called.
const char *CkMht_proxy(HCkMht cHandle);
(Optional) A proxy host:port if a proxy is necessary to access the Internet. The proxy string should be formatted as "hostname:port", such as "www.chilkatsoft.com:100".
const char *CkMht_proxyLogin(HCkMht cHandle);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.
const char *CkMht_proxyPassword(HCkMht cHandle);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.
const char *CkMht_socksHostname(HCkMht cHandle);
The SOCKS4/SOCKS5 hostname or IPv4 address (in dotted decimal notation). This property is only used if the SocksVersion property is set to 4 or 5).
const char *CkMht_socksPassword(HCkMht cHandle);
The SOCKS5 password (if required). The SOCKS4 protocol does not include the use of a password, so this does not apply to SOCKS4.
const char *CkMht_socksUsername(HCkMht cHandle);
The SOCKS4/SOCKS5 proxy username. This property is only used if the SocksVersion property is set to 4 or 5).
const char *CkMht_version(HCkMht cHandle);
The version of the component, such as "1.0.0"
const char *CkMht_webSiteLogin(HCkMht cHandle);
(Optional) Specifies the login if a a Web page is accessed that requires a login
const char *CkMht_webSitePassword(HCkMht cHandle);
Optional) Specifies the password if a a Web page is accessed that requires a login and password
|