2017-11-03 11:23:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Opdavies\GmailFilterBuilder;
|
|
|
|
|
|
|
|
class Filter
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
private $properties = [];
|
|
|
|
|
2017-11-03 11:23:22 +00:00
|
|
|
public function has($value)
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['hasTheWord'] = $value;
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 09:20:46 +00:00
|
|
|
public function hasNot($value)
|
|
|
|
{
|
|
|
|
$this->properties['doesNotHaveTheWord'] = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-11-03 11:23:22 +00:00
|
|
|
public function from()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['from'] = collect(func_get_args())
|
|
|
|
->map(function ($address) {
|
|
|
|
return trim($address);
|
2017-11-04 09:20:46 +00:00
|
|
|
})->all();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function to()
|
|
|
|
{
|
|
|
|
$this->properties['to'] = collect(func_get_args())
|
|
|
|
->map(function ($address) {
|
|
|
|
return trim($address);
|
|
|
|
})->all();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function subject($subject)
|
|
|
|
{
|
|
|
|
$this->properties['subject'] = $subject;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAttachment()
|
|
|
|
{
|
|
|
|
$this->properties['hasAttachment'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function excludeChats()
|
|
|
|
{
|
|
|
|
$this->properties['excludeChats'] = 'true';
|
2017-11-03 23:22:13 +00:00
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function label($label)
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['label'] = $label;
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function archive()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['shouldArchive'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function labelAndArchive($label)
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->label($label)->archive();
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function spam()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['shouldSpam'] = 'true';
|
|
|
|
$this->properties['shouldNeverSpam'] = 'false';
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function neverSpam()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['shouldSpam'] = 'false';
|
|
|
|
$this->properties['shouldNeverSpam'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function trash()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->properties['shouldTrash'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-11-03 23:45:54 +00:00
|
|
|
public function read()
|
|
|
|
{
|
|
|
|
$this->properties['markAsRead'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function star()
|
|
|
|
{
|
|
|
|
$this->properties['shouldStar'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function forward($to)
|
|
|
|
{
|
|
|
|
$this->properties['forwardTo'] = $to;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function important()
|
|
|
|
{
|
|
|
|
$this->properties['shouldAlwaysMarkAsImportant'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notImportant()
|
|
|
|
{
|
|
|
|
$this->properties['shouldNeverMarkAsImportant'] = 'true';
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function categorise($category)
|
|
|
|
{
|
|
|
|
$this->properties['smartLabelToApply'] = $category;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-11-03 23:22:13 +00:00
|
|
|
public function getProperties()
|
|
|
|
{
|
|
|
|
return $this->properties;
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
}
|