@@ -109,6 +109,21 @@ public LoginResult Login(string token)
109
109
return result ;
110
110
}
111
111
112
+ public GetTokenResult GenerateTokenOnBehalfOf ( string emailAddress )
113
+ {
114
+ Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
115
+ parameters . Add ( "ClientTime" , DateTime . Now . ToUniversalTime ( ) . ToString ( DATETIME_FORMATTER ) ) ;
116
+
117
+ string payload = ( new { Main = this . main , GetToken = parameters } ) . ToJson ( ) ;
118
+ payload = payload . Replace ( "{\" Main\" :{" , $ "{{\" Main\" :{{\" OnBehalfOf\" :\" { emailAddress } \" ,") ;
119
+ string response = Utilities . Post ( this . apiEndpoint , payload ) ;
120
+
121
+ GetTokenResult result = response . ParseJson < GetTokenResult > ( ) ;
122
+ this . main . UpdateToken ( result . Token ) ;
123
+
124
+ return result ;
125
+ }
126
+
112
127
/// <summary>
113
128
/// Tell the API that we're logging out. Not critical, more as good behavior and for logging
114
129
/// </summary>
@@ -535,15 +550,18 @@ public MailContactsReadResult MailContactsRead(string userId, string unId, List<
535
550
MailContactsReadResult result = response . ParseJson < MailContactsReadResult > ( ) ;
536
551
this . main . UpdateToken ( result . Token ) ;
537
552
538
- if ( additionalFields != null )
553
+ if ( additionalFields != null && additionalFields . Count != 0 )
539
554
{
540
555
Dictionary < string , object > temp = response . ParseJson < Dictionary < string , object > > ( ) ;
541
556
temp = ( Dictionary < string , object > ) temp [ "MailContactsRead" ] ;
542
557
temp = ( Dictionary < string , object > ) temp [ "Contact" ] ;
543
558
result . MailContactsRead . Contact . Fields = new Dictionary < string , object > ( ) ;
544
559
foreach ( string item in additionalFields )
545
560
{
546
- result . MailContactsRead . Contact . Fields . Add ( item , temp [ item ] ) ;
561
+ if ( temp . ContainsKey ( item ) )
562
+ {
563
+ result . MailContactsRead . Contact . Fields . Add ( item , temp [ item ] ) ;
564
+ }
547
565
}
548
566
}
549
567
@@ -622,6 +640,110 @@ public CalendarsModifiedResult CalendarsModified(string changeKey = null)
622
640
return result ;
623
641
}
624
642
643
+ public MailListResult MailList ( string userId , DateTime from , DateTime to )
644
+ {
645
+ if ( this . servletPath == null ) { throw new NullReferenceException ( "servletPath is null" ) ; }
646
+ if ( userId == null ) { throw new ArgumentNullException ( "userId" ) ; }
647
+ if ( from == null ) { throw new ArgumentNullException ( "from" ) ; }
648
+ if ( to == null ) { throw new ArgumentNullException ( "to" ) ; }
649
+
650
+ Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
651
+ parameters . Add ( "UserID" , userId ) ;
652
+ parameters . Add ( "FromDT" , from . ToUniversalTime ( ) . ToString ( DATETIME_FORMATTER ) ) ;
653
+ parameters . Add ( "ToDT" , to . ToUniversalTime ( ) . ToString ( DATETIME_FORMATTER ) ) ;
654
+
655
+ string payload = ( new { Main = this . main , MailList = parameters } ) . ToJson ( ) ;
656
+ string response = Utilities . Post ( this . servletEndpoint , payload ) ;
657
+
658
+ MailListResult result = response . ParseJson < MailListResult > ( ) ;
659
+ this . main . UpdateToken ( result . Token ) ;
660
+
661
+ return result ;
662
+ }
663
+
664
+ public MailReadResult MailRead ( string userId , string unId , string [ ] fields , string [ ] extraItems = null , string [ ] attachments = null , bool bodyHtml = true , bool bodyMime = false )
665
+ {
666
+ if ( this . servletPath == null ) { throw new NullReferenceException ( "servletPath is null" ) ; }
667
+ if ( userId == null ) { throw new ArgumentNullException ( "userId" ) ; }
668
+ if ( unId == null ) { throw new ArgumentNullException ( "unId" ) ; }
669
+ if ( fields == null ) { throw new ArgumentNullException ( "fields" ) ; }
670
+
671
+ Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
672
+ parameters . Add ( "UserID" , userId ) ;
673
+ parameters . Add ( "UnID" , unId ) ;
674
+ parameters . Add ( "Fields" , fields ) ;
675
+ parameters . Add ( "BodyHtml" , bodyHtml ) ;
676
+ parameters . Add ( "BodyMime" , bodyMime ) ;
677
+
678
+ if ( extraItems != null && extraItems . Length != 0 ) { parameters . Add ( "ExtraItems" , extraItems ) ; }
679
+ if ( attachments != null && attachments . Length != 0 ) { parameters . Add ( "Attachments" , attachments ) ; }
680
+
681
+ string payload = ( new { Main = this . main , MailRead = parameters } ) . ToJson ( ) ;
682
+ string response = Utilities . Post ( this . servletEndpoint , payload ) ;
683
+
684
+ MailReadResult result = response . ParseJson < MailReadResult > ( ) ;
685
+ this . main . UpdateToken ( result . Token ) ;
686
+
687
+ if ( fields != null && fields . Length != 0 )
688
+ {
689
+ Dictionary < string , object > temp = response . ParseJson < Dictionary < string , object > > ( ) ;
690
+ temp = ( Dictionary < string , object > ) temp [ "MailRead" ] ;
691
+ temp = ( Dictionary < string , object > ) temp [ "Mail" ] ;
692
+ result . MailRead . Mail . Fields = new Dictionary < string , string > ( ) ;
693
+ foreach ( string item in fields )
694
+ {
695
+ if ( temp . ContainsKey ( item ) )
696
+ {
697
+ result . MailRead . Mail . Fields . Add ( item , ( string ) temp [ item ] ) ;
698
+ }
699
+ }
700
+ }
701
+
702
+ if ( extraItems != null && extraItems . Length != 0 )
703
+ {
704
+ Dictionary < string , object > temp = response . ParseJson < Dictionary < string , object > > ( ) ;
705
+ temp = ( Dictionary < string , object > ) temp [ "MailRead" ] ;
706
+ temp = ( Dictionary < string , object > ) temp [ "Mail" ] ;
707
+ temp = ( Dictionary < string , object > ) temp [ "ExtraItems" ] ;
708
+
709
+ result . MailRead . Mail . Extraitems = new Dictionary < string , MailReadExtraItem > ( ) ;
710
+ foreach ( string item in fields )
711
+ {
712
+ if ( temp . ContainsKey ( item ) )
713
+ {
714
+ result . MailRead . Mail . Extraitems . Add ( item , temp [ "Subject" ] . ToJson ( ) . ParseJson < MailReadExtraItem > ( ) ) ;
715
+ }
716
+ }
717
+ }
718
+
719
+ return result ;
720
+ }
721
+
722
+ public MailSendResult MailSend ( string [ ] sendTo , string subject , string body , string [ ] copyTo = null , string [ ] blindCopyTo = null , MailSendAttachment [ ] attachments = null )
723
+ {
724
+ if ( this . servletPath == null ) { throw new NullReferenceException ( "servletPath is null" ) ; }
725
+ if ( sendTo == null || sendTo . Length == 0 ) { throw new ArgumentNullException ( "sendTo" ) ; }
726
+ if ( subject == null ) { throw new ArgumentNullException ( "subject" ) ; }
727
+ if ( body == null ) { throw new ArgumentNullException ( "body" ) ; }
728
+
729
+ Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
730
+ parameters . Add ( "SendTo" , sendTo ) ;
731
+ parameters . Add ( "Subject" , subject ) ;
732
+ parameters . Add ( "Body" , body ) ;
733
+
734
+ if ( copyTo != null && copyTo . Length != 0 ) { parameters . Add ( "CopyTo" , copyTo ) ; }
735
+ if ( blindCopyTo != null && blindCopyTo . Length != 0 ) { parameters . Add ( "BlindCopyTo" , blindCopyTo ) ; }
736
+ if ( attachments != null && attachments . Length != 0 ) { parameters . Add ( "Attachments" , attachments ) ; }
737
+
738
+ string payload = ( new { Main = this . main , MailSend = parameters } ) . ToJson ( ) ;
739
+ string response = Utilities . Post ( this . servletEndpoint , payload ) ;
740
+
741
+ MailSendResult result = response . ParseJson < MailSendResult > ( ) ;
742
+ this . main . UpdateToken ( result . Token ) ;
743
+
744
+ return result ;
745
+ }
746
+
625
747
private class OtBase
626
748
{
627
749
public string ApplID { get ; set ; }
0 commit comments