This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-postmark-api.php
1438 lines (1276 loc) · 43 KB
/
wp-postmark-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WP Postmark API (http://developer.postmarkapp.com/)
*
* @package WP-API-Libraries\WP-Postmark-Base\WP-Postmark-API
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/* Check if class exists. */
if ( ! class_exists( 'PostMarkAPI' ) ) {
if ( ! class_exists( 'PostMarkBase' ) ) {
include_once( 'wp-postmark-base.php' );
}
/**
* PostMarkAPI class.
*/
class PostMarkAPI extends PostMarkBase {
/**
* Format Email Fields.
*
* @access public
* @static
* @param mixed $emails Emails.
*/
public static function format_email_fields( $emails ) {
if ( is_array( $emails ) ) {
return implode( ',', $emails );
}
return $emails;
}
/**
* FEF???.
*
* @access public
* @static
* @param mixed $emails Emails.
*/
public static function fef( $emails ) {
return self::format_email_fields( $emails );
}
/* EMAIL. */
/**
* Send a Single Email.
*
* @access public
* @param string $from [REQUIRED] The sender email address. Must have a registered and confirmed Sender Signature.
* @param string $to [REQUIRED] Recipient email address. Multiple addresses are comma seperated. Max 50.
* @param string $cc Cc recipient email address. Multiple addresses are comma seperated. Max 50.
* @param string $bcc Bcc recipient email address. Multiple addresses are comma seperated. Max 50.
* @param string $subject Email subject.
* @param string $tag Email tag that allows you to categorize outgoing emails and get detailed statistics.
* @param string $html_body [REQUIRED] HTML email message (If no TextBody specified).
* @param string $text_body [REQUIRED] Plain text email message (If no HtmlBody specified).
* @param string $reply_to Reply To override email address. Defaults to the Reply To set in the sender signature.
* @param object $headers List of custom headers to include.
* @param bool $track_opens Activate open tracking for this email.
* @param string $track_links Activate link tracking for links in the HTML or Text bodies of this email.
* @param object $attachments List of attachments.
* @return Object Server response.
*/
public function send_email( $from, $to, $cc, $bcc, $subject, $tag, $html_body, $text_body, $reply_to = '', $headers = array(), $track_opens = true, $track_links = 'HtmlAndText', $attachments = array() ) {
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => array(
'From' => $from,
'To' => $to,
'Cc' => $cc,
'Bcc' => $bcc,
'Subject' => $subject,
'Tag' => $tag,
'HtmlBody' => $html_body,
'TextBody' => $text_body,
'ReplyTo' => $reply_to,
'Headers' => $headers,
'TrackOpens' => $track_opens,
'TrackLinks' => $track_links,
'Attachments' => $attachments,
),
);
$response = $this->build_request( $args )->fetch( '/email' );
return $response;
}
/**
* Send Batch Emails.
*
* Format it as an array of the emails to send. This is not a route for being efficient with sending emails, it's for doing a bunch of emails in one request.
* It's also possible for you to instead of making an array of email objects to send, to comma separate recipients.
*
* @access public
* @param mixed $from [REQUIRED] The sender email address. Must have a registered and confirmed Sender Signature.
* @param mixed $to [REQUIRED] Recipient email address. Multiple addresses are comma seperated. Max 50.
* @param mixed $cc Cc recipient email address. Multiple addresses are comma seperated. Max 50.
* @param mixed $bcc Bcc recipient email address. Multiple addresses are comma seperated. Max 50.
* @param mixed $subject Email subject.
* @param mixed $tag Email tag that allows you to categorize outgoing emails and get detailed statistics.
* @param mixed $html_body [REQUIRED] HTML email message (If no TextBody specified).
* @param mixed $text_body [REQUIRED] Plain text email message (If no HtmlBody specified).
* @param mixed $replyto Reply To override email address. Defaults to the Reply To set in the sender signature.
* @param mixed $headers List of custom headers to include.
* @param mixed $track_opens Activate open tracking for this email.
* @param mixed $track_links Activate link tracking for links in the HTML or Text bodies of this email.
* @param mixed $attachments List of attachments.
* @return Object Server response.
*/
public function send_batch_emails( $emails ) {
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $emails,
);
return $this->build_request( $args )->fetch( '/email/batch' );
}
/* BOUNCE. */
/**
* Get Delivery Stats.
* It is recommended you use server token as opposed to account token for this command (and other bounce data).
*
* @access public
* @return Object Server response.
*/
public function get_delivery_stats() {
return $this->build_request()->fetch( '/deliverystats' );
}
/**
* Get Bounces. Used as a paginator for viewing bounce data.
*
* @access public
* @param mixed $count (Default: 50) Count.
* @param mixed $offset Offset (default: 0) Offset.
* @param string $type (default: '') Type.
* @param string $inactive (default: '') Inactive.
* @param string $email_filter (default: '') Email Filter.
* @param string $tag (default: '') Tag.
* @param string $message_id (default: '') Message ID.
* @param string $from_date (default: '') From Date.
* @param string $to_date (default: '') To Date.
* @return Object Server response.
*/
public function get_bounces( $count = 50, $offset = 0, $type = '', $inactive = '', $email_filter = '', $tag = '', $message_id = '', $from_date = '', $to_date = '' ) {
$args = array(
'count' => $count,
'offset' => $offset,
'type' => $type,
'inactive' => $inactive,
'email_filter' => $email_filter,
'tag' => $tag,
'message_id' => $message_id,
'from_date' => $from_date,
'to_date' => $to_date,
);
$request = '/bounces?' . http_build_query( array_filter( $args ) );
return $this->build_request()->fetch( $request );
}
/**
* Get a specific bounce by ID.
*
* @access public
* @param mixed $bounce_id Bounce ID.
* @return Object Server response.
*/
public function get_bounce( $bounce_id ) {
return $this->build_request()->fetch( '/bounces/' . $bounce_id );
}
/**
* Get a Bounce Dump by ID.
*
* @access public
* @param mixed $bounce_id Bounce ID.
* @return Object Server response.
*/
public function get_bounce_dump( $bounce_id ) {
return $this->build_request()->fetch( '/bounces/' . $bounce_id . '/dump' );
}
/**
* Activate a Bounce by ID.
*
* @access public
* @param mixed $bounce_id Bounce ID.
* @return Object Server response.
*/
public function activate_bounce( $bounce_id ) {
$args = array();
$args['method'] = 'PUT';
return $this->build_request( $args )->fetch( '/bounces/' . $bounce_id . '/activate' );
}
/**
* Get Bounced Tags.
*
* @access public
* @return Object Server response.
*/
public function get_bounced_tags() {
return $this->build_request()->fetch( '/bounces/tags' );
}
/**
* Get a list of all possible bounce types.
*
* @access public
* @return list of bounce types.
*/
public function get_bounce_types() {
return array(
array(
'Type' => 'HardBounce',
'Code' => 1,
'Name' => 'Hard bounce',
'Description' => __( 'The server was unable to deliver your message (ex: unknown user, mailbox not found).', 'wp-postmark-api' ),
),
array(
'Type' => 'Transient',
'Code' => 2,
'Name' => 'Message delayed',
'Description' => __( 'The server could not temporarily deliver your message (ex: Message is delayed due to network troubles).', 'wp-postmark-api' ),
),
array(
'Type' => 'Unsubscribe',
'Code' => 16,
'Name' => 'Unsubscribe request',
'Description' => __( 'Unsubscribe or Remove request.', 'wp-postmark-api' ),
),
array(
'Type' => 'Subscribe',
'Code' => 32,
'Name' => 'Subscribe request',
'Description' => __( 'Subscribe request from someone wanting to get added to the mailing list.', 'wp-postmark-api' ),
),
array(
'Type' => 'AutoResponder',
'Code' => 64,
'Name' => 'Auto responder',
'Description' => __( 'Automatic email responder (ex: "Out of Office" or "On Vacation").', 'wp-postmark-api' ),
),
array(
'Type' => 'AddressChange',
'Code' => 128,
'Name' => 'Address change',
'Description' => __( 'The recipient has requested an address change.', 'wp-postmark-api' ),
),
array(
'Type' => 'DnsError',
'Code' => 256,
'Name' => 'DNS error',
'Description' => __( 'A temporary DNS error.', 'wp-postmark-api' ),
),
array(
'Type' => 'SpamNotification',
'Code' => 512,
'Name' => 'Spam notification',
'Description' => __( 'The message was delivered, but was either blocked by the user, or classified as spam, bulk mail, or had rejected content.', 'wp-postmark-api' ),
),
array(
'Type' => 'OpenRelayTest',
'Code' => 1024,
'Name' => 'Open relay test',
'Description' => __( 'The NDR is actually a test email message to see if the mail server is an open relay.', 'wp-postmark-api' ),
),
array(
'Type' => 'Unknown',
'Code' => 2048,
'Name' => 'Unknown',
'Description' => __( 'Unable to classify the NDR.', 'wp-postmark-api' ),
),
array(
'Type' => 'SoftBounce',
'Code' => 4096,
'Name' => 'Soft bounce',
'Description' => __( 'Unable to temporarily deliver message (i.e. mailbox full, account disabled, exceeds quota, out of disk space).', 'wp-postmark-api' ),
),
array(
'Type' => 'VirusNotification',
'Code' => 8192,
'Name' => 'Virus notification',
'Description' => __( 'The bounce is actually a virus notification warning about a virus/code infected message.', 'wp-postmark-api' ),
),
array(
'Type' => 'ChallengeVerification',
'Code' => 16384,
'Name' => 'Spam challenge verification',
'Description' => __( 'The bounce is a challenge asking for verification you actually sent the email. Typcial challenges are made by Spam Arrest, or MailFrontier Matador.', 'wp-postmark-api' ),
),
array(
'Type' => 'BadEmailAddress',
'Code' => 100000,
'Name' => 'Invalid email address',
'Description' => __( 'The address is not a valid email address.', 'wp-postmark-api' ),
),
array(
'Type' => 'SpamComplaint',
'Code' => 100001,
'Name' => 'Spam complaint',
'Description' => __( 'The subscriber explicitly marked this message as spam.', 'wp-postmark-api' ),
),
array(
'Type' => 'ManuallyDeactivated',
'Code' => 100002,
'Name' => 'Manually deactivated',
'Description' => __( 'The email was manually deactivated.', 'wp-postmark-api' ),
),
array(
'Type' => 'Unconfirmed',
'Code' => 100003,
'Name' => 'Registration not confirmed',
'Description' => __( 'The subscriber has not clicked on the confirmation link upon registration or import.', 'wp-postmark-api' ),
),
array(
'Type' => 'Blocked',
'Code' => 100006,
'Name' => 'ISP block',
'Description' => __( 'Blocked from this ISP due to content or blacklisting.', 'wp-postmark-api' ),
),
array(
'Type' => 'SMTPApiError',
'Code' => 100007,
'Name' => 'SMTP API error',
'Description' => __( 'An error occurred while accepting an email through the SMTP API.', 'wp-postmark-api' ),
),
array(
'Type' => 'InboundError',
'Code' => 100008,
'Name' => 'Processing failed',
'Description' => __( 'Unable to deliver inbound message to destination inbound hook.', 'wp-postmark-api' ),
),
array(
'Type' => 'DMARCPolicy',
'Code' => 100009,
'Name' => 'DMARC Policy',
'Description' => __( 'Email rejected due DMARC Policy.', 'wp-postmark-api' ),
),
array(
'Type' => 'TemplateRenderingFailed',
'Code' => 100010,
'Name' => 'Template rendering failed',
'Description' => __( 'An error occurred while attempting to render your template.', 'wp-postmark-api' ),
),
);
}
/* TEMPLATES. */
/**
* Get Templates. AKA List Templates.
*
* @access public
* @param mixed $count Number of results from offset to display.
* @param mixed $offset (Default: 0) Offset from first entry in order.
* @return Object Server response.
*/
public function get_templates( $count = 50, $offset = 0 ) {
return $this->build_request()->fetch( '/templates?count=' . $count . '&offset=' . $offset );
}
/**
* List templates. Redirects to get_templates().
*
* @param mixed $count Number of results from offset to display.
* @param mixed $offset (Default: 0) Offset from first entry in order.
* @return [type] [description]
*/
public function list_templates( $count = 50, $offset = 0 ) {
return $this->get_templates( $count, $offset );
}
/**
* Get a Template by ID.
*
* @access public
* @param mixed $template_id Template ID.
* @return Object Server response.
*/
public function get_template( $template_id ) {
return $this->build_request()->fetch( '/templates/' . $template_id );
}
/**
* Create a template.
* https://api.postmarkapp.com/templates
*
* @param string $name Name.
* @param string $subject Subject.
* @param string $htmlbody Htmlbody.
* @param string $textbody Textbody.
* @return Object Server response.
*/
public function create_template( $name, $subject, $htmlbody, $textbody ) {
$args = array(
'method' => 'POST',
'body' => array(
'Name' => $name,
'Subject' => $subject,
'HtmlBody' => $htmlbody,
'TextBody' => $textbody,
),
);
return $this->build_request( $args )->fetch( '/templates/' );
}
/**
* Edit template.
* Subject, html body and text body are required, name is optional.
*
* @param mixed $template_id Template ID.
* @param string $subject Subject.
* @param string $html_body Html_body.
* @param string $text_body Text_body.
* @param string $name (Default: '') name.
*/
public function edit_template( $template_id, $subject, $html_body, $text_body, $name = '' ) {
$args = array(
'method' => 'PUT',
'body' => array(
'Subject' => $subject,
'HtmlBody' => $htmlbody,
'TextBody' => $textbody,
),
);
return $this->build_request( $args )->fetch( '/templates/' . $template_id );
}
/**
* Validate a template.
*
* @param string $subject (Default: '') Subject of email.
* @param string $htmlbody (Default: '') HTML body.
* @param string $textbody (Default: '') Plaintext body.
* @param array $testrendermodel (Default: array) Test render model obj.
* @param boolean $inlinecss (Default: false) Whether to allow inlinecss through the email.
* @return Object Server Response.
*/
public function validate_template( $subject = '', $htmlbody = '', $textbody = '', $testrendermodel = array(), $inlinecss = false ) {
if ( '' === $subject && '' === $htmlbody && '' === $textbody ) {
return new WP_Error( 'missing-args', __( 'You must specify at least one of the first three arguments', 'wp-postmark-api' ) );
}
$args = array(
'method' => 'POST',
'body' => array(
'Subject' => $subject,
'HtmlBody' => $htmlbody,
'TextBody' => $textbody,
'TestRenderModel' => $testrendermodel,
'InlineCssForHtmlTestRender' => $inlinecss,
),
);
return $this->build_request( $args )->fetch( '/templates/validate' );
}
/**
* Delete a template.
*
* @param mixed $template_id ID of template to delete.
* @return Object Server response.
*/
public function delete_template( $template_id ) {
$args = array(
'method' => 'DELETE',
);
return $this->build_request( $args )->fetch( '/templates/' . $template_id );
}
/**
* Send an email using a template.
*
* @param mixed $template_id ID of template to reference.
* @param object $template_model Object containing values to fill template with.
* @param bool $inlinecss Whether to use inlinecss or not.
* @param string $from Email address to send email from.
* @param string $to (Default: '') Email address(es) to sent email to.
* @param string $cc (Default: '') Email address(es) to cc email to.
* @param string $bcc (Default: '') Email address(es) to bcc email to.
* @param string $tag (Default: '') Tags for internal tracking/data stuff.
* @param string $replyto (Default: '') Email that clicking 'reply' will be prepared to send to.
* @param array $headers (Default: array) Optional headers to include in the email.
* @param bool $trackopens (Default: true) Whether to track opens or not.
* @param string $tracklinks (Default: "HtmlAndText") What sorta things to track.
* @param object $attachments (Default: array) Attachments.
* @return object Server response.
*/
public function send_email_with_template( $template_id, $template_model, $inlinecss, $from, $to, $cc = '', $bcc = '', $tag = '', $replyto = '', $headers = array(), $trackopens = true, $tracklinks = 'HtmlAndText', $attachments = array() ) {
$args = array(
'method' => 'POST',
'body' => array(
'TemplateId' => $template_id,
'TemplateModel' => $template_model,
'InlineCss' => $inlinecss,
'From' => $from,
'To' => self::fef( $to ),
'Cc' => self::fef( $cc ),
'Bcc' => self::fef( $bcc ),
'Tag' => $tag,
'Headers' => $headers,
'TrackOpens' => $trackopens,
'TrackLinks' => $tracklinks,
'Attachments' => $attachments,
),
);
if ( '' !== $replyto ) {
$args['body']['ReplyTo'] = $replyto;
}
return $this->build_request( $args )->fetch( '/email/withTemplate/' );
}
/**
* Send batch with templates.
*
* @link https://postmarkapp.com/developer/api/templates-api#send-batch-with-templates
*
* @param array $messages An array of messages to send, each being an email.
* following the structure from previous emails.
* @return object The response, an array of responses per message.
*/
public function send_batch_email_with_templates( $messages ) {
$args = array(
'method' => 'POST',
'body' => array(
'messages' => $messages,
),
);
return $this->build_request( $args )->fetch( '/email/batchWithTemplates' );
}
/* SERVERS. */
/**
* Get Server.
*
* @access public
* @return Object Server response.
*/
public function get_the_server() {
return $this->build_request()->fetch( '/server' );
}
/**
* Edit Server.
* If you want to reset/clear a value, pass in a space character (ie: " ").
*
* @access public
* @param mixed $name (Default: '') Name.
* @param mixed $color (Default: '') Color.
* @param mixed $raw_email_enabled (Default: '') Raw email embedded.
* @param mixed $smtp_api_activated (Default: '') SMTP API Activated.
* @param mixed $inbound_hook_url (Default: '') Inbound hook url.
* @param mixed $bounce_hook_url (Default: '') Bounce hook url.
* @param mixed $open_hook_url (Default: '') Open hook url.
* @param mixed $post_first_open_only (Default: '') Post first open only.
* @param mixed $track_opens (Default: '') Track opens.
* @param mixed $track_links (Default: '') Track links.
* @param mixed $inbound_domain (Default: '') Inbound domain.
* @param mixed $inbound_spam_threshold (Default: '') Inbound spam threshhold.
* @return Object Server response.
*/
public function edit_the_server( $name = '', $color = '', $raw_email_enabled = '', $smtp_api_activated = '', $inbound_hook_url = '', $bounce_hook_url = '', $open_hook_url = '', $post_first_open_only = '', $track_opens = '', $track_links = '', $inbound_domain = '', $inbound_spam_threshold = '' ) {
$keys = array( 'Name', 'Color', 'RawEmailEnabled', 'SmtpApiActivated', 'DeliveryHookUrl', 'InboundHookUrl', 'BounceHookUrl', 'IncludeBounceContentInHook', 'OpenHookUrl', 'PostFirstOpenOnly', 'TrackOpens', 'TrackLinks', 'InboundDomain', 'InboundSpamThreshold' );
$values = array( $name, $color, $raw_email_enabled, $smtp_api_activated, $inbound_hook_url, $bounce_hook_url, $open_hook_url, $post_first_open_only, $track_opens, $track_links, $inbound_domain, $inbound_spam_threshold );
$args = array(
'method' => 'PUT',
'body' => array(),
);
for ( $i = 0;$i < count( $values );$i++ ) {
if ( '' !== $values[ $i ] && $key[ $i ] ) {
$args[ $keys[ $i ] ] = $values[ $i ];
}
}
if ( 0 === count( $args['body'] ) ) {
return new WP_Error( 'missing-arguments', __( 'You cannot edit a post with no data.', 'wp-postmark-api' ) );
}
return $this->build_request( $args )->fetch( '/server/' );
}
/**
* Get Server.
*
* @access public
* @param mixed $server_id Server ID.
* @return Object Server response.
*/
public function get_server( $server_id ) {
return $this->build_request()->fetch( '/servers/' . $server_id );
}
/**
* Add a server. Possible values to pass into other_args are below (along with their default values).
* You do not need to have every key and value there, only name is mandatory.
* You can alternatively pass in a single string as the name of the server to be created.
*
* @param object $other_args Object as described above.
*/
public function add_server( $other_args = array() ) {
if ( gettype( $other_args ) !== 'string' && ! isset( $other_args['Name'] ) && ! isset( $other_args['name'] ) ) {
return new WP_Error( 'missing-args', __( 'You must at least include a Name key/value within the arguments array.' ) );
}
$args = array(
'method' => 'POST',
'body' => $other_args,
);
if ( gettype( $other_args ) === 'string' ) {
$args['body'] = array( 'Name' => $other_args );
}
return $this->build_request( $args )->fetch( '/servers/' );
}
/**
* Edit a server.
* Pass in an object with the values you'd like to change.
*
* @param mixed $server_id server id.
* @param object $other_args arguments to modify.
* @return object Server response.
*/
public function edit_server( $server_id, $other_args = array() ) {
$args = array(
'method' => 'PUT',
'body' => $other_args,
);
return $this->build_request( $args )->fetch( '/servers/' . $server_id );
}
/**
* List Servers.
*
* @access public
* @param mixed $count Number of results from offset to display.
* @param mixed $offset (Default: 0) Offset from first entry in order.
* @param mixed $name (Default: null) name of server (search filter).
* @return Object Server response.
*/
public function list_servers( $count = 50, $offset = 0, $name = null ) {
return $this->build_request()->fetch( '/servers?count=' . $count . '&offset=' . $offset . '&name=' . $name );
}
/**
* Delete a server by ID.
*
* @param mixed $server_id ID of server to delete.
* @return object Server response.
*/
public function delete_server( $server_id ) {
$args = array(
'method' => 'DELETE',
);
return $this->build_request( $args )->fetch( '/servers/' . $server_id );
}
/* MESSAGES. */
/**
* Search Outbound Messages.
*
* @access public
* @param int $count (default: 50) Count.
* @param int $offset (default: 0) Offset.
* @param mixed $recipient (default: null) Recipient.
* @param mixed $from_email (default: null) From Email.
* @param mixed $tag (default: null) Tag.
* @param mixed $status (default: null) Status.
* @param mixed $to_date (default: null) To Date.
* @param mixed $from_date (default: null) From Date.
*/
public function search_outbound_messages( $count = 50, $offset = 0, $recipient = null, $from_email = null, $tag = null, $status = null, $to_date = null, $from_date = null ) {
$request = '/messages/outbound?count=' . $count . '&offset=' . $offset;
$request .= http_build_query(array(
'offset' => $offset,
'recipient' => $recipient,
'fromemail' => $from_email,
'tag' => $tag,
'status' => $status,
'todate' => $to_date,
'fromdate' => $from_date,
));
return $this->build_request()->fetch( $request );
}
/**
* Get Outbound Message Details.
*
* @access public
* @param mixed $message_id Message ID.
* @return Object Server response.
*/
public function get_outbound_message_details( $message_id ) {
return $this->build_request()->fetch( '/messages/outbound/' . $message_id . '/details' );
}
/**
* Get Outbound Message Dump.
*
* @access public
* @param mixed $message_id Message ID.
*/
public function get_outbound_message_dump( $message_id ) {
return $this->build_request()->fetch( '/messages/outbound/' . $message_id . '/dump' );
}
/**
* Search inbound messages.
*
* @param m ixed $count Number of results from offset to display.
* @param mixed $offset (Default: 0) Offset from first entry in order.
* @param string $recipient Recipient.
* @param string $fromemail Fromemail.
* @param string $tag Tag.
* @param string $subject Subject.
* @param string $mailboxhash Mailboxhash.
* @param string $status Status.
* @param string $todate Todate.
* @param string $fromdate Fromdate.
*/
public function search_inbound_messages( $count = 50, $offset = 0, $recipient = null, $fromemail = null, $tag = null, $subject = null, $mailboxhash = null, $status = null, $todate = null, $fromdate = null ) {
$request = '/messages/inbound?count=' . $count . '&';
$request .= http_build_query(array(
'offset' => $offset,
'recipient' => $recipient,
'fromemail' => $fromemail,
'tag' => $tag,
'subject' => $subject,
'mailboxhash' => $mailboxhash,
'status' => $status,
'todate' => $todate,
'fromdate' => $fromdate,
));
return $this->build_request()->fetch( $request );
}
/**
* Get_inbound_message_details function.
*
* @access public
* @param mixed $message_id Message ID.
*/
public function get_inbound_message_details( $message_id ) {
return $this->build_request()->fetch( '/messages/inbound/' . $message_id . '/details' );
}
/**
* Bypass_blocked_inbound_message function.
*
* @access public
* @param mixed $message_id Message ID.
*/
public function bypass_blocked_inbound_message( $message_id ) {
$args = array( 'method' => 'PUT' );
return $this->build_request( $args )->fetch( '/messages/inbound/' . $message_id . '/bypass' );
}
/**
* Retry_failed_inbound function.
*
* @access public
* @param mixed $message_id Message ID.
*/
public function retry_failed_inbound( $message_id ) {
$args = array( 'method' => 'PUT' );
return $this->build_request( $args )->fetch( '/messages/inbound/' . $message_id . '/retry' );
}
/**
* Get_message_opens function.
*
* @access public
* @param mixed $count (Default: 50) Number of results from offset to display.
* @param mixed $offset (Default: 0) Offset from first entry in order.
* @return Object Server response.
*/
public function get_message_opens( $count = 50, $offset = 0 ) {
$request = '/messages/outbound/opens/?' . http_build_query(array(
'count' => $count,
'offset' => $offset,
));
return $this->build_request()->fetch( $request );
}
/**
* Get_single_message_opens function.
*
* @access public
* @param mixed $message_id Message ID.
*/
public function get_single_message_opens( $message_id ) {
return $this->build_request()->fetch( '/messages/outbound/opens/' . $message_id );
}
/* DOMAINS. */
/**
* List Domains.
*
* @access public
* @param int $count (default: 500) Count. Max 500.
* @param int $offset (default: 0) Offset.
* @return Object Server response.
*/
public function list_domains( $count = 500, $offset = 0 ) {
return $this->build_request()->fetch( '/domains?count=' . $count . '&offset=' . $offset );
}
/**
* Get Domain Details.
*
* @access public
* @param mixed $domain_id Domain ID.
* @return Object Server response.
*/
public function get_domain_details( $domain_id ) {
return $this->build_request()->fetch( '/domains/' . $domain_id );
}
/**
* Add Domain.
*
* @access public
* @param mixed $name Name.
* @param string $return_path_domain (default: '') Return Path Domain.
*/
public function add_domain( $name, $return_path_domain = '' ) {
$args = array(
'method' => 'POST',
'body' => array(
'Name' => $name,
),
);
if ( '' !== $return_path_domain ) {
$args['body']['ReturnPathDomain'] = $return_path_domain;
}
return $this->build_request( $args )->fetch( '/domains' );
}
/**
* Interestingly enough, the only option you can edit for a domain is the
* return path. Kinda makes sense? Otherwise delete it and make a new one if
* you want to change the name.
*
* @param [type] $domain_id Domain ID.
* @param [type] $return_path_domain Return Path Domain.
*/
public function edit_domain( $domain_id, $return_path_domain ) {
$args = array(
'method' => 'PUT',
'body' => array(
'ReturnPathDomain' => $return_path_domain,
),
);
return $this->build_request( $args )->fetch( '/domains/' . $domain_id );
}
/**
* Delete Domain.
*
* @access public
* @param mixed $domain_id Domain ID.
*/
public function delete_domain( $domain_id ) {
$args = array(
'method' => 'DELETE',
);
return $this->build_request( $args )->fetch( '/domains/' . $domain_id );
}
/**
* Verify_domain_spf_record function.
*
* @access public
* @param mixed $domain_id Domain ID.
*/
public function verify_domain_spf_record( $domain_id ) {
$args = array(
'method' => 'POST',
);
return $this->build_request( $args )->fetch( '/domains/' . $domain_id . '/verifyspf' );
}
/**
* Rotate_dkim_keys function.
*
* @access public
* @param mixed $domain_id Domain ID.
*/
public function rotate_dkim_keys( $domain_id ) {
$args = array(
'method' => 'POST',
);
return $this->build_request( $args )->fetch( '/domains/' . $domain_id . '/rotatedkim' );
}
/* SENDER SIGNATURES */
/**
* List Sender Signatures.
*
* @access public
* @param int $count (default: 500) Count.
* @param int $offset (default: 0) Offset.
*/
public function list_sender_signatures( $count = 500, $offset = 0 ) {
return $this->build_request()->fetch( "/senders?count=$count&offset=$offset" );
}
/**
* Get Sender Signature Details.
*
* @access public
* @param mixed $signature_id Signature ID.
* @return Object Server response.
*/
public function get_sender_signatures_details( $signature_id ) {
return $this->build_request()->fetch( '/senders/' . $signature_id );
}
/**
* Create_signature function.
*
* @access public
* @param mixed $from_email From Email.
* @param mixed $name Name.
* @param string $reply_to_email (default: '') Reply to Email.
* @param string $return_path_domain (default: '') Return Path Domain.
*/
public function create_signature( $from_email, $name, $reply_to_email = '', $return_path_domain = '' ) {
$args = array(
'method' => 'POST',
'body' => array(
'FromEmail' => $from_email,
'Name' => $name,