caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Edwin Török" <edwin+ml@etorok.net>
To: "Sébastien Hinderer" <Sebastien.Hinderer@inria.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Ask questions on the mailing lists too
Date: Thu, 20 Jan 2022 20:56:09 +0000	[thread overview]
Message-ID: <03d64a08de39bf9d3eedb6515d567fb54d34a092.camel@etorok.net> (raw)
In-Reply-To: <Yeg861TWxfFy5ICj@prajna.paris.inria.fr>

On Wed, 2022-01-19 at 17:31 +0100, Sébastien Hinderer wrote:
> Simon Cruanes (2022/01/18 15:55 +0000):
> 
> [...]
> > I don't know about registration
> > though, it'd be good if there was a way to register purely by email
> > to
> > make it more accessible. For the rest, _once registered_, as far as
> > I'm
> > concerned, it's just a mailing list software.
> 
> Well as was mentionned, the mailing-list mode needs to be enabled and
> that seems to have accessibility issues.

Here is a small python3 script that enables mailing list mode provided
that you've got a live browser logged in to discuss.ocaml.org using
Firefox, and that you have python3 and pip3 installed:

pip3 install --user requests browser-cookie3
wget https://tinyurl.com/domett -O domett.py && python3 domett.py

(If this doesn't work and fails on looking up the username from the
headers it is possible that you've logged out in the browser at some
point, closing and reopening the browser and logging in again might be
a workaround)

Discourse does have APIs for various things, including tweaking
preferences, but unfortunately not for changing mailing list mode:
https://docs.discourse.org/
For any endpoint that is not documented they suggest reverse
engineering it
(https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576)
which I've done.
However we still need to present some form of authentication, I was
thinking about API keys, but they're normally for admins only, and the
user-API keys appear to need a webservice to talk
to https://meta.discourse.org/t/user-api-keys-specification/48536

You've mentioned that you were able to log in with your browser, so the
above Python3 script loads the cookies from the live browser, does a
request to get the CSRF token, and then makes a PUT request to change
mailing list mode settings.
This is similar to what discourse itself would've done if you clicked
through things in the web browser.

(I thought of using Mechaml to write it, but python has a convenient
way of loading the cookies from the cookies.sqlite and mechaml doesn't
yet).

Here is the python3 script in its entirety if it is easier to run from
the email than from the tinyurl.
In theory it should work on other discourse sites, so it might be
possible to adapt this to register on meta.discourse.org (although the
email traffic from that would probably be too large and should instead
subscribe only to a particular topic).

Is is far from ideal, but it might provide you a way to read and
participate in discussions until a better solution is found:

--- CUT HERE ---
#!/usr/bin/env python3
import browser_cookie3
import requests
import logging

logging.basicConfig(level=logging.DEBUG)
logging.debug("About to load Firefox cookiejar")
BASE = "https://discuss.ocaml.org"
cookiejar = browser_cookie3.firefox(domain_name="discuss.ocaml.org")
logging.debug("Got cookies: %r" % ([c.name for c in cookiejar]))

s = requests.Session()
s.cookies = cookiejar
reply = s.get("%s/session/csrf" % BASE, headers={"X-Requested-With":
"XMLHttpRequest"})
csrf = reply.json()['csrf']
logging.debug("Got CSRF token")
username = reply.headers["x-discourse-username"]
logging.info("Got username %s" % username)
data = {
        "mailing_list_mode": "true",
        #        "mailing_list_mode": "true",
        "mailing_list_mode_frequency": "1",
        "email_digests": "true",
        "email_in_reply_to": "true",
        "email_messages_level": "0",
        "email_level": "0",
        "email_previous_replies": "1",
        "digest_after_minutes": "10080",
        "include_tl0_in_digests": "true",
    }
logging.info("About to set mailing list mode to %s" %
data["mailing_list_mode"])
headers = {
    "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    "X-CSRF-Token": csrf,
}
reply = s.put("%s/u/%s.json" % (BASE, username), data=data, headers=headers)
json = reply.json()
if 'success' in json:
    logging.info(json['success'])
else:
    logging.error(json)
--- CUT HERE ---


Hope this helps,
--Edwin

  parent reply	other threads:[~2022-01-20 20:56 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14 18:56 [Caml-list] Type Error in OCaml Code mukesh tiwari
2022-01-15 21:18 ` Nicolás Ojeda Bär
2022-01-16  9:40   ` [Caml-list] Ask questions on the mailing lists too orbifx
2022-01-16 14:31     ` Sam Kuper
2022-01-17  9:20       ` Sébastien Hinderer
2022-01-17  9:33         ` Daniil Baturin
2022-01-17 14:30           ` Sam Kuper
2022-01-17 14:56             ` Daniil Baturin
2022-01-17 17:36               ` Sam Kuper
2022-01-17 21:06                 ` Gabriel Scherer
2022-01-18  1:51                   ` Sam Kuper
2022-01-19 15:46                     ` Sébastien Hinderer
2022-01-18  9:48                   ` orbifx
2022-01-18 15:55                     ` Simon Cruanes
2022-01-19 16:31                       ` Sébastien Hinderer
2022-01-19 17:51                         ` Sam Kuper
2022-01-19 18:09                           ` Sam Kuper
2022-01-19 19:09                             ` Sébastien Hinderer
2022-01-19 20:53                               ` Sam Kuper
2022-01-19 18:42                           ` Simon Cruanes
2022-01-19 19:03                           ` Sébastien Hinderer
2022-01-19 20:50                             ` Sam Kuper
2022-01-20 20:56                         ` Edwin Török [this message]
2022-03-11  8:46                           ` Sébastien Hinderer
2022-03-11  9:37                             ` Vasilis Goumas
2022-03-11  9:42                               ` Gabriel Scherer
2022-01-19 15:33                   ` Sébastien Hinderer
2022-01-19 21:43                     ` Gabriel Scherer
2022-01-19 22:01                       ` Sam Kuper
2022-01-19 22:38                         ` Sébastien Hinderer
     [not found]                 ` <50AF4FEF-5CD6-40E7-9FA3-78814CBEE230@etorok.eu>
2022-01-17 22:47                   ` Sam Kuper
2022-01-17  9:53         ` Alan Schmitt
2022-01-17 13:52           ` Sam Kuper
2022-01-19 15:18             ` Sébastien Hinderer
2022-01-19 15:54           ` Sébastien Hinderer
2022-01-20  9:12             ` Alan Schmitt
     [not found]             ` <87pmom7sz7.fsf@m4x.org>
2022-01-20 14:15               ` Sébastien Hinderer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03d64a08de39bf9d3eedb6515d567fb54d34a092.camel@etorok.net \
    --to=edwin+ml@etorok.net \
    --cc=Sebastien.Hinderer@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).