Skip to content

Commit 72aa064

Browse files
committed
Examples added
1 parent 32a8c6e commit 72aa064

File tree

6 files changed

+212
-44
lines changed

6 files changed

+212
-44
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,32 +344,32 @@ $paginator = $oFolder->search()
344344
``` html
345345
<table>
346346
<thead>
347-
<tr>
348-
<th>UID</th>
349-
<th>Subject</th>
350-
<th>From</th>
351-
<th>Attachments</th>
352-
</tr>
347+
<tr>
348+
<th>UID</th>
349+
<th>Subject</th>
350+
<th>From</th>
351+
<th>Attachments</th>
352+
</tr>
353353
</thead>
354354
<tbody>
355355
<?php if($paginator->count() > 0): ?>
356356
<?php foreach($paginator as $oMessage): ?>
357-
<tr>
358-
<td><?php echo $oMessage->getUid(); ?></td>
359-
<td><?php echo $oMessage->getSubject(); ?></td>
360-
<td><?php echo $oMessage->getFrom()[0]->mail; ?></td>
361-
<td><?php echo $oMessage->getAttachments()->count() > 0 ? 'yes' : 'no'; ?></td>
362-
</tr>
363-
<?php endforeach: ?>
357+
<tr>
358+
<td><?php echo $oMessage->getUid(); ?></td>
359+
<td><?php echo $oMessage->getSubject(); ?></td>
360+
<td><?php echo $oMessage->getFrom()[0]->mail; ?></td>
361+
<td><?php echo $oMessage->getAttachments()->count() > 0 ? 'yes' : 'no'; ?></td>
362+
</tr>
363+
<?php endforeach; ?>
364364
<?php else: ?>
365365
<tr>
366366
<td colspan="4">No messages found</td>
367367
</tr>
368-
<?php endif: ?>
368+
<?php endif; ?>
369369
</tbody>
370370
</table>
371371

372-
{{$paginator->links()}}
372+
<?php echo $paginator->links(); ?>
373373
```
374374
> You can also paginate a Folder-, Attachment- or FlagCollection instance.
375375

examples/custom_attachment_mask.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*
3+
* File: custom_message_mask.php
4+
* Category: Example
5+
* Author: M.Goldenbaum
6+
* Created: 14.03.19 18:47
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
class CustomAttachmentMask extends \Webklex\PHPIMAP\Support\Masks\AttachmentMask {
14+
15+
/**
16+
* New custom method which can be called through a mask
17+
* @return string
18+
*/
19+
public function token(){
20+
return implode('-', [$this->id, $this->getMessage()->getUid(), $this->name]);
21+
}
22+
23+
/**
24+
* Custom attachment saving method
25+
* @return bool
26+
*/
27+
public function custom_save() {
28+
$path = storage_path('foo');
29+
$filename = $this->token();
30+
31+
$path = substr($path, -1) == DIRECTORY_SEPARATOR ? $path : $path.DIRECTORY_SEPARATOR;
32+
33+
return \Illuminate\Support\Facades\File::put($path.$filename, $this->getContent()) !== false;
34+
}
35+
36+
}
37+
38+
/** @var \Webklex\PHPIMAP\Client $oClient */
39+
$cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php');
40+
$oClient = $cm->account('default');
41+
$oClient->connect();
42+
$oClient->setDefaultAttachmentMask(CustomAttachmentMask::class);
43+
44+
/** @var \Webklex\PHPIMAP\Folder $folder */
45+
$folder = $oClient->getFolder('INBOX');
46+
47+
/** @var \Webklex\PHPIMAP\Message $message */
48+
$message = $folder->query()->limit(1)->get()->first();
49+
50+
/** @var \Webklex\PHPIMAP\Attachment $attachment */
51+
$attachment = $message->getAttachments()->first();
52+
53+
/** @var CustomAttachmentMask $masked_attachment */
54+
$masked_attachment = $attachment->mask();
55+
56+
echo 'Token for uid ['.$masked_attachment->getMessage()->getUid().']: '.$masked_attachment->token();
57+
58+
$masked_attachment->custom_save();

examples/custom_message_mask.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/*
3+
* File: custom_message_mask.php
4+
* Category: Example
5+
* Author: M.Goldenbaum
6+
* Created: 14.03.19 18:47
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
class CustomMessageMask extends \Webklex\PHPIMAP\Support\Masks\MessageMask {
14+
15+
/**
16+
* New custom method which can be called through a mask
17+
* @return string
18+
*/
19+
public function token(){
20+
return implode('-', [$this->message_id, $this->uid, $this->message_no]);
21+
}
22+
23+
/**
24+
* Get number of message attachments
25+
* @return integer
26+
*/
27+
public function getAttachmentCount() {
28+
return $this->getAttachments()->count();
29+
}
30+
31+
}
32+
33+
/** @var \Webklex\PHPIMAP\Client $oClient */
34+
$cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php');
35+
$oClient = $cm->account('default');
36+
$oClient->connect();
37+
38+
/** @var \Webklex\PHPIMAP\Folder $folder */
39+
$folder = $oClient->getFolder('INBOX');
40+
41+
/** @var \Webklex\PHPIMAP\Message $message */
42+
$message = $folder->query()->limit(1)->get()->first();
43+
44+
/** @var CustomMessageMask $masked_message */
45+
$masked_message = $message->mask(CustomMessageMask::class);
46+
47+
echo 'Token for uid ['.$masked_message->uid.']: '.$masked_message->token().' @atms:'.$masked_message->getAttachmentCount();
48+
49+
$masked_message->setFlag('seen');
50+

examples/folder_structure.blade.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/*
3+
* File: folder_structure.blade.php
4+
* Category: View
5+
* Author: M.Goldenbaum
6+
* Created: 15.09.18 19:53
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
/**
14+
* @var \Webklex\PHPIMAP\Support\FolderCollection $paginator
15+
* @var \Webklex\PHPIMAP\Folder $oFolder
16+
*/
17+
18+
?>
19+
<table>
20+
<thead>
21+
<tr>
22+
<th>Folder</th>
23+
<th>Unread messages</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<?php if($paginator->count() > 0): ?>
28+
<?php foreach($paginator as $oFolder): ?>
29+
<tr>
30+
<td><?php echo $oFolder->name; ?></td>
31+
<td><?php echo $oFolder->search()->unseen()->leaveUnread()->setFetchBody(false)->setFetchAttachment(false)->get()->count(); ?></td>
32+
</tr>
33+
<?php endforeach; ?>
34+
<?php else: ?>
35+
<tr>
36+
<td colspan="4">No folders found</td>
37+
</tr>
38+
<?php endif: ?>
39+
</tbody>
40+
</table>
41+
42+
<?php echo $paginator->links(); ?>

examples/message_table.blade.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/*
3+
* File: message_table.blade.php
4+
* Category: View
5+
* Author: M.Goldenbaum
6+
* Created: 15.09.18 19:53
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
/**
14+
* @var \Webklex\PHPIMAP\Support\FolderCollection $paginator
15+
* @var \Webklex\PHPIMAP\Folder $oFolder
16+
* @var \Webklex\PHPIMAP\Message $oMessage
17+
*/
18+
19+
?>
20+
<table>
21+
<thead>
22+
<tr>
23+
<th>UID</th>
24+
<th>Subject</th>
25+
<th>From</th>
26+
<th>Attachments</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<?php if($paginator->count() > 0): ?>
31+
<?php foreach($paginator as $oMessage): ?>
32+
<tr>
33+
<td><?php echo $oMessage->getUid(); ?></td>
34+
<td><?php echo $oMessage->getSubject(); ?></td>
35+
<td><?php echo $oMessage->getFrom()[0]->mail; ?></td>
36+
<td><?php echo $oMessage->getAttachments()->count() > 0 ? 'yes' : 'no'; ?></td>
37+
</tr>
38+
<?php endforeach; ?>
39+
<?php else: ?>
40+
<tr>
41+
<td colspan="4">No messages found</td>
42+
</tr>
43+
<?php endif; ?>
44+
</tbody>
45+
</table>
46+
47+
<?php echo $paginator->links(); ?>

src/Support/Masks/MessageMask.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,4 @@ public function getHTMLBodyWithEmbeddedBase64Images() {
7979
return $body;
8080
});
8181
}
82-
83-
/**
84-
* Get the Message html body with embedded image urls
85-
* the resulting $body.
86-
*
87-
* @param string $route_name
88-
* @param array $params
89-
*
90-
* @return null|string
91-
*/
92-
public function getHTMLBodyWithEmbeddedUrlImages($route_name, $params = []) {
93-
return $this->getCustomHTMLBody(function($body, $oAttachment) use($route_name, $params){
94-
/** @var \Webklex\PHPIMAP\Attachment $oAttachment */
95-
if ($oAttachment->id && $oAttachment->getImgSrc() != null) {
96-
$oMessage = $oAttachment->getMessage();
97-
98-
$image_url = route($route_name, array_merge([
99-
'muid' => urlencode($oMessage->uid),
100-
'mid' => urlencode($oMessage->message_id),
101-
'mti' => urlencode($oMessage->date->timestamp),
102-
'aid' => urlencode($oAttachment->id)
103-
], $params));
104-
105-
$body = str_replace('cid:'.$oAttachment->id, $image_url, $body);
106-
}
107-
108-
return $body;
109-
});
110-
}
11182
}

0 commit comments

Comments
 (0)