Each account is tied to a sqlite database file which is fully managed by the underlying deltachat core library. All public Account methods are meant to be memory-safe and return memory-safe objects.
| 55 | |
| 56 | |
| 57 | class Account: |
| 58 | """Each account is tied to a sqlite database file which is fully managed |
| 59 | by the underlying deltachat core library. All public Account methods are |
| 60 | meant to be memory-safe and return memory-safe objects. |
| 61 | """ |
| 62 | |
| 63 | MissingCredentials = MissingCredentials |
| 64 | |
| 65 | _logid: str |
| 66 | _evtracker: "FFIEventTracker" |
| 67 | |
| 68 | def __init__(self, db_path, os_name=None, logging=True, closed=False) -> None: |
| 69 | from .events import EventThread |
| 70 | |
| 71 | """initialize account object. |
| 72 | |
| 73 | :param db_path: a path to the account database. The database |
| 74 | will be created if it doesn't exist. |
| 75 | :param os_name: [Deprecated] |
| 76 | :param logging: enable logging for this account |
| 77 | :param closed: set to True to avoid automatically opening the account |
| 78 | after creation. |
| 79 | """ |
| 80 | # initialize per-account plugin system |
| 81 | self._pm = hookspec.PerAccount._make_plugin_manager() |
| 82 | self._logging = logging |
| 83 | |
| 84 | self.add_account_plugin(self) |
| 85 | |
| 86 | self.db_path = db_path |
| 87 | if hasattr(db_path, "encode"): |
| 88 | db_path = db_path.encode("utf8") |
| 89 | |
| 90 | ptr = lib.dc_context_new_closed(db_path) if closed else lib.dc_context_new(ffi.NULL, db_path, ffi.NULL) |
| 91 | if ptr == ffi.NULL: |
| 92 | raise ValueError(f"Could not dc_context_new: {os_name} {db_path}") |
| 93 | self._dc_context = ffi.gc( |
| 94 | ptr, |
| 95 | lib.dc_context_unref, |
| 96 | ) |
| 97 | |
| 98 | self._shutdown_event = Event() |
| 99 | self._event_thread = EventThread(self) |
| 100 | self._configkeys = self.get_config("sys.config_keys").split() |
| 101 | hook = hookspec.Global._get_plugin_manager().hook |
| 102 | hook.dc_account_init(account=self) |
| 103 | |
| 104 | def open(self, passphrase: Optional[str] = None) -> bool: |
| 105 | """Open the account's database with the given passphrase. |
| 106 | This can only be used on a closed account. If the account is new, this |
| 107 | operation sets the database passphrase. For existing databases the passphrase |
| 108 | should be the one used to encrypt the database the first time. |
| 109 | |
| 110 | :returns: True if the database is opened with this passphrase, False if the |
| 111 | passphrase is incorrect or an error occurred. |
| 112 | """ |
| 113 | return bool(lib.dc_context_open(self._dc_context, as_dc_charpointer(passphrase))) |
| 114 |
no outgoing calls