6 Debbugs::User -- User settings
10 use Debbugs::User qw(is_valid_user read_usertags write_usertags);
12 Debbugs::User::is_valid_user($userid);
14 $u = Debbugs::User::open($userid);
15 $u = Debbugs::User::open(user => $userid, locked => 0);
17 $u = Debbugs::User::open(user => $userid, locked => 1);
26 read_usertags(\%ut, $userid);
27 write_usertags(\%ut, $userid);
33 =item :all -- all functions that can be exported
44 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
45 use base qw(Exporter);
48 ($VERSION) = q$Revision: 1.3 $ =~ /^Revision:\s+([^\s+])/;
49 $DEBUG = 0 unless defined $DEBUG;
52 @EXPORT_OK = qw(is_valid_user open);
53 $EXPORT_TAGS{all} = [@EXPORT_OK];
56 my $gSpoolPath = "/org/bugs.debian.org/spool";
58 # Obsolete compatability functions
64 my $user = get_user($u);
65 for my $t (keys %{$user->{"tags"}}) {
66 $ut->{$t} = [] unless defined $ut->{$t};
67 push @{$ut->{$t}}, @{$user->{"tags"}->{$t}};
75 my $user = get_user($u, 1); # locked
76 $user->{"tags"} = { %{$ut} };
80 #######################################################################
85 my $l = length($e) % 7;
86 return "$gSpoolPath/user/$l/" . join("",
87 map { m/^[0-9a-zA-Z_+.-]$/ ? $_ : sprintf("%%%02X", ord($_)) }
99 if ($field && m/^ (.*)$/) {
100 $res[-1] .= "\n" . $1;
101 } elsif (m/^([^:]+):(\s+(.*))?$/) {
114 while ($s =~ m/^([^,]*,\s*)(.*)$/ || $s =~ m/^([^,]+)()$/) {
117 unless ($sofar == 0 or $sofar + length($k) <= $n) {
122 $sofar += length($k);
129 return ($u =~ /^[a-zA-Z0-9._+-]+[@][a-z0-9-.]{4,}$/);
132 #######################################################################
140 "visible_cats" => [],
141 "unknown_stanzas" => []
145 my $need_lock = shift || 0;
146 my $p = filefromemail($u);
149 $user->{"filename"} = $p;
150 open($uf, "< $p") or bless $user, "Debbugs::User";
153 $user->{"locked"} = $uf;
157 my @stanza = read_stanza($uf);
158 last if ($#stanza == -1);
159 if ($stanza[0] eq "Tag") {
162 $ut->{$t} = [] unless defined $ut->{$t};
163 push @{$ut->{$t}}, split /\s*,\s*/, $tag{Bugs};
164 } elsif ($stanza[0] eq "Category") {
166 my %stanza = @stanza;
167 my $catname = $stanza{"Category"};
169 while (++$i && defined $stanza{"Cat${i}"}) {
170 if (defined $stanza{"Cat${i}Options"}) {
172 my %c = ("nam" => $stanza{"Cat${i}"});
173 $c{"def"} = $stanza{"Cat${i}Default"}
174 if defined $stanza{"Cat${i}Default"};
175 $c{"ord"} = [ split /,/, $stanza{"Cat${i}Order"} ]
176 if defined $stanza{"Cat${i}Order"};
178 for my $l (split /\n/, $stanza{"Cat${i}Options"}) {
179 if ($l =~ m/^\s*(\S+)\s+-\s+(.*\S)\s*$/) {
182 } elsif ($l =~ m/^\s*(\S+)\s*$/) {
191 push @cat, $stanza{"Cat${i}"};
194 $user->{"categories"}->{$catname} = [@cat];
195 push @{$user->{"visible_cats"}}, $catname
196 unless ($stanza{"Hidden"} || "no") eq "yes";
198 push @{$user->{"unknown_stanzas"}}, [@stanza];
201 close($uf) unless $need_lock;
203 bless $user, "Debbugs::User";
210 my $ut = $user->{"tags"};
211 my $p = $user->{"filename"};
213 if ($p =~ m/^(.+)$/) { $p = $1; } else { return; }
214 open $uf, "> $p" or return;
216 for my $us (@{$user->{"unknown_stanzas"}}) {
219 my $k = shift @us; my $v = shift @us;
221 print $uf "$k: $v\n";
226 for my $t (keys %{$ut}) {
227 next if @{$ut->{$t}} == 0;
228 print $uf "Tag: $t\n";
229 print $uf fmt("Bugs: " . join(", ", @{$ut->{$t}}), 77) . "\n";
233 my $uc = $user->{"categories"};
234 my %vis = map { $_, 1 } @{$user->{"visible_cats"}};
235 for my $c (keys %{$uc}) {
236 next if @{$uc->{$c}} == 0;
238 print $uf "Category: $c\n";
239 print $uf "Hidden: yes\n" unless defined $vis{$c};
241 for my $cat (@{$uc->{$c}}) {
243 if (ref($cat) eq "HASH") {
244 printf $uf "Cat%d: %s\n", $i, $cat->{"nam"};
245 printf $uf "Cat%dOptions:\n", $i;
246 for my $j (0..$#{$cat->{"pri"}}) {
247 if (defined $cat->{"ttl"}->[$j]) {
248 printf $uf " %s - %s\n",
249 $cat->{"pri"}->[$j], $cat->{"ttl"}->[$j];
251 printf $uf " %s\n", $cat->{"pri"}->[$j];
254 printf $uf "Cat%dDefault: %s\n", $i, $cat->{"def"}
255 if defined $cat->{"def"};
256 printf $uf "Cat%dOrder: %s\n", $i, join(", ", @{$cat->{"ord"}})
257 if defined $cat->{"ord"};
259 printf $uf "Cat%d: %s\n", $i, $cat;
266 delete $user->{"locked"};