1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dacastro4\LaravelGmail\Traits; |
4
|
|
|
|
5
|
|
|
use Dacastro4\LaravelGmail\Services\Message\Mail; |
6
|
|
|
use Google_Service_Gmail; |
7
|
|
|
use Google_Service_Gmail_ModifyMessageRequest; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @property Google_Service_Gmail $service |
11
|
|
|
*/ |
12
|
|
|
trait Modifiable |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
use ModifiesLabels { |
16
|
|
|
ModifiesLabels::__construct as private __mlConstruct; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
private $messageRequest; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->__mlConstruct(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Marks emails as "READ". Returns string of message if fail |
28
|
|
|
* |
29
|
|
|
* @return Mail|string |
30
|
|
|
*/ |
31
|
|
|
public function markAsRead() |
32
|
|
|
{ |
33
|
|
|
try { |
34
|
|
|
return $this->removeSingleLabel( 'UNREAD' ); |
35
|
|
|
} catch ( \Exception $e ) { |
36
|
|
|
return "Couldn't mark email as read: {$e->getMessage()}"; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Marks emails as unread |
42
|
|
|
* |
43
|
|
|
* @return Mail|string |
44
|
|
|
* @throws \Exception |
45
|
|
|
*/ |
46
|
|
|
public function markAsUnread() |
47
|
|
|
{ |
48
|
|
|
try { |
49
|
|
|
return $this->addSingleLabel( 'UNREAD' ); |
50
|
|
|
} catch ( \Exception $e ) { |
51
|
|
|
throw new \Exception( "Couldn't mark email as unread: {$e->getMessage()}" ); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return Mail|string |
57
|
|
|
* @throws \Exception |
58
|
|
|
*/ |
59
|
|
|
public function markAsImportant() |
60
|
|
|
{ |
61
|
|
|
try { |
62
|
|
|
return $this->addSingleLabel( 'IMPORTANT' ); |
63
|
|
|
} catch ( \Exception $e ) { |
64
|
|
|
throw new \Exception( "Couldn't remove mark email as important.: {$e->getMessage()}" ); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return Mail|string |
70
|
|
|
* @throws \Exception |
71
|
|
|
*/ |
72
|
|
|
public function markAsNotImportant() |
73
|
|
|
{ |
74
|
|
|
try { |
75
|
|
|
return $this->removeSingleLabel( 'IMPORTANT' ); |
76
|
|
|
} catch ( \Exception $e ) { |
77
|
|
|
throw new \Exception( "Couldn't mark email as unread: {$e->getMessage()}" ); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Mail|string |
83
|
|
|
* @throws \Exception |
84
|
|
|
*/ |
85
|
|
|
public function addStar() |
86
|
|
|
{ |
87
|
|
|
try { |
88
|
|
|
return $this->addSingleLabel( 'STARRED' ); |
89
|
|
|
} catch ( \Exception $e ) { |
90
|
|
|
throw new \Exception( "Couldn't remove mark email as important.: {$e->getMessage()}" ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Mail|string |
96
|
|
|
* @throws \Exception |
97
|
|
|
*/ |
98
|
|
|
public function removeStar() |
99
|
|
|
{ |
100
|
|
|
try { |
101
|
|
|
return $this->removeSingleLabel( 'STARRED' ); |
102
|
|
|
} catch ( \Exception $e ) { |
103
|
|
|
throw new \Exception( "Couldn't mark email as unread: {$e->getMessage()}" ); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Send the email to the trash |
109
|
|
|
* |
110
|
|
|
* @return \Dacastro4\LaravelGmail\Services\Message\Mail|\Exception |
111
|
|
|
*/ |
112
|
|
|
public function sendToTrash() |
113
|
|
|
{ |
114
|
|
|
try { |
115
|
|
|
return $this->addSingleLabel( 'TRASH' ); |
116
|
|
|
} catch ( \Exception $e ) { |
117
|
|
|
return new \Exception( "Couldn't mark email as trash: {$e->getMessage()}" ); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function removeFromTrash() |
122
|
|
|
{ |
123
|
|
|
try { |
124
|
|
|
return $this->removeSingleLabel( 'TRASH' ); |
125
|
|
|
} catch ( \Exception $e ) { |
126
|
|
|
return new \Exception( "Couldn't untrash the email: {$e->getMessage()}" ); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.