EmailParser.Header
------------------

Queries a header entry.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [EmailParser](component_EmailParser.md) | [5.3](newinversion53.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "EmailParser.Header"; EmailID; Index; Selector ) 

**MBS**( **"EmailParser.Header";** /\* Queries a header entry. \*/  
**$EmailID**; /\* The ID fo the email parser.e.g. $Email \*/   
**$Index**; /\* The index from 0 to [EmailParser.HeaderCount](EmailParserHeaderCount.md)-1.e.g. 0 \*/   
**$Selector**) /\* Which value to return. Can be "name" or "value".e.g. "name" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| EmailID | The ID fo the email parser. | $Email |
| Index | The index from 0 to [EmailParser.HeaderCount](EmailParserHeaderCount.md)-1. | 0 |
| Selector | Which value to return. Can be "name" or "value". | "name" |

### Result

Returns text or error.

### Description

Queries a header entry.  
Common header values include Date, Subject, From and X-Mailer.  
### Examples

Query first header entry:

 $name = MBS ( "EmailParser.Header"; $EmailID ; 0; "name" )  
$value = MBS ( "EmailParser.Header"; $EmailID ; 0; "value" )  
Find a header value by name:

 Set Variable \[$i ; Value:0\]  
Set Variable \[$c ; Value:MBS ("[EmailParser.HeaderCount](EmailParserHeaderCount.md)"; $email )\]  
If \[$c &gt; 0\]  
 Loop  
 Set Variable \[$HeaderName ; Value:MBS ("EmailParser.Header"; $email ; $i ; "name")\]  
 If \[$HeaderName = "X-Mailer"\]  
 Set Variable \[$HeaderValue ; Value:MBS ("EmailParser.Header"; $email ; $i ; "value")\]  
 Set Field \[Email Parser::Mailer ; $HeaderValue \]  
 End If  
 #next  
 Set Variable \[$i ; Value:$i + 1\]  
 Exit Loop If \[$i = $c \]  
 End Loop  
End If  
Copy all headers into records:

 Set Variable \[ $i ; Value: 0 \]   
Set Variable \[ $c ; Value: MBS ("[EmailParser.HeaderCount](EmailParserHeaderCount.md)"; $email ) \]   
If \[ $c &gt; 0 \]   
 Loop  
 Set Variable \[ $HeaderName ; Value: MBS ("EmailParser.Header"; $email ; $i ; "name") \]   
 Set Variable \[ $HeaderValue ; Value: MBS ("EmailParser.Header"; $email ; $i ; "value") \]   
 New Record/Request  
 Set Field \[ EmailHeaders::EmailID ; $EmailRecordID \]   
 Set Field \[ EmailHeaders::HeaderName ; $HeaderName \]   
 Set Field \[ EmailHeaders::HeaderValue ; $HeaderValue \]   
 Commit Records/Requests \[ With dialog: Off \]   
 # next  
 Set Variable \[ $i ; Value: $i + 1 \]   
 Exit Loop If \[ $i = $c \]   
 End Loop  
End If  
### See also

- [EmailParser.Hash](EmailParserHash.md)
- [EmailParser.HasHeader](EmailParserHasHeader.md)
- [EmailParser.HeaderCount](EmailParserHeaderCount.md)
- [EmailParser.HeaderValue](EmailParserHeaderValue.md)
- [EmailParser.Parse](EmailParserParse.md)
- [EmailParser.Release](EmailParserRelease.md)

### Release notes

- **Version 7.4**
    - Added [EmailParser.HasHeader](http://www.mbsplugins.eu/EmailParserHasHeader.shtml) and [EmailParser.HeaderValue](http://www.mbsplugins.eu/EmailParserHeaderValue.shtml) functions to make header queries easier.

### Example Databases

- [CURL/Email/Email Client](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Email%20Client.shtml#1ScriptAnchor_)
- [CURL/Email/Email Parser and Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Email%20Parser%20and%20Preview.shtml#1ScriptAnchor_)
- [CURL/Email/Email Parser](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Email%20Parser.shtml#1ScriptAnchor_)
- [CURL/Email/IMAP Email](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email.shtml#4ScriptAnchor_)

This function is free to use.

Created 24th September 2015 , last changed 9th June 2017

  
[EmailParser.Hash](EmailParserHash.md) - [EmailParser.HeaderCount](EmailParserHeaderCount.md)

[HTML Version](EmailParserHeader.shtml)