phpsieve-language

Read sieve conf file in php


I am migrating our mail platform,

I have for each user a file (I don't have access to Sieve host)

that looks like this

require "vacation";
if not header :contains "Precedence" ["bulk","list"] {
vacation
:days 15
:addresses ["some@email.tld", "some@email.tld"]
:subject "Out of office Subject"
"Some out of office tekst

With multiple lines 

another line"
;}

I want to get the subject and message in PHP as a variable for each. How can accomplish this?


Solution

  • A solution without regex looks like this:

    <?php
    
    $input = file_get_contents("input");
    
    $needle = ":subject";
    
    $theString = substr($input, strpos($input, $needle) + strlen($needle));
    
    $newLinePosition = strpos($theString, "\n");
    
    $subject = substr($theString, 0, $newLinePosition);
    
    $content = substr($theString, $newLinePosition + 1);
    
    echo "SUBJECT IS \n" . $subject . "\n";
    
    echo "CONTENT IS \n" . $content . "\n";
    

    Explanation: