the-djmaze / snappymail

Simple, modern & fast web-based email client
https://snappymail.eu
GNU Affero General Public License v3.0
1.01k stars 121 forks source link

API for dummies #1055

Closed robmies1968 closed 6 months ago

robmies1968 commented 1 year ago

Is your feature request related to a problem? Please describe. I am looking for some API examples

Describe the solution you'd like A simple, or a few examples.

Describe alternatives you've considered Not using the API, but programming 'around' Snappymail.

Additional context Here I have an example of me trying to get the number of all read and unread emails from a logged in user:

$oActions = new RainLoop\Actions();
$inlog = $oActions->LoginProcess($email, $emailWachtwoord, true);
$berichten = $oActions->ImapClient()->FolderStatus('INBOX');
$alleBerichten = $berichten->MESSAGES;
$ongelezen = $berichten->UNSEEN;

I don't know if this is the best way of doing it, but it works. Problem is, I was really struggling to come up with this piece of code. Is there some kind of documentation (without me first reverse engineering the codebase) of the API? If somebody has an example of how to create a contact, for instance, that would help a lot, because I think that is quite a difficult procedure. I have tried: $oActions->DoContacts()->AddContact($email, $email, $email);, but that fails. :(

the-djmaze commented 1 year ago

Indeed there is no documentation. Eventually there will be, but RainLoop never did and i need to find time somewhere.

To add a contact look at https://github.com/the-djmaze/snappymail/blob/master/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php#L92 There you see that it:

  1. opens the addressbook
  2. create a vCard from jCard
  3. find existing contact by UID, else create
  4. set the vCard inside the Contact
  5. then save the Contact

So you need:

$oActions->AddressBookProvider($oAccount);
$vCard = new \Sabre\VObject\Component\VCard;
$oContact = new \RainLoop\Providers\AddressBook\Classes\Contact();
$oContact->setVCard($vCard);
$oAddressBookProvider->ContactSave($oContact);
cm-schl commented 1 year ago

There is at least some first try to write a developer documentation https://github.com/the-djmaze/snappymail/wiki/Developer-Documentation I know, this is not directly that what you're looking for, but maybe it helps you a bit. If you have made some progress on your project maybe you find some time to add your knowledge to this first document 🙂

robmies1968 commented 1 year ago

Thanks! I will add examples of found knowledge to this document. And I will look further into teh developer documentation.

cm-schl commented 1 year ago

That would be great! Had exactly the same problems when I've written my plugin, so I know it is a bit hard to begin 👍